From ab46c2afbaf88c0534334065842a0a1563b3b3ea Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 13 May 2021 22:16:20 +0300 Subject: [PATCH 01/70] added subscribe support --- dist/jssip.js | 830 ++++++++++++++++++++++--------------------- dist/jssip.min.js | 2 +- lib/RequestSender.js | 36 +- lib/UA.js | 29 +- 4 files changed, 480 insertions(+), 417 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 063170734..ef5bed700 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -9,7 +9,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -498,14 +498,6 @@ var C = { }; // RFC 3261 12.1. module.exports = /*#__PURE__*/function () { - _createClass(Dialog, null, [{ - key: "C", - // Expose C object. - get: function get() { - return C; - } - }]); - function Dialog(owner, message, type) { var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; @@ -569,6 +561,37 @@ module.exports = /*#__PURE__*/function () { } _createClass(Dialog, [{ + key: "id", + get: function get() { + return this._id; + } + }, { + key: "local_seqnum", + get: function get() { + return this._local_seqnum; + }, + set: function set(num) { + this._local_seqnum = num; + } + }, { + key: "owner", + get: function get() { + return this._owner; + } + }, { + key: "uac_pending_reply", + get: function get() { + return this._uac_pending_reply; + }, + set: function set(pending) { + this._uac_pending_reply = pending; + } + }, { + key: "uas_pending_reply", + get: function get() { + return this._uas_pending_reply; + } + }, { key: "update", value: function update(message, type) { this._state = C.STATUS_CONFIRMED; @@ -713,36 +736,11 @@ module.exports = /*#__PURE__*/function () { return true; } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "local_seqnum", - get: function get() { - return this._local_seqnum; - }, - set: function set(num) { - this._local_seqnum = num; - } - }, { - key: "owner", - get: function get() { - return this._owner; - } - }, { - key: "uac_pending_reply", - get: function get() { - return this._uac_pending_reply; - }, - set: function set(pending) { - this._uac_pending_reply = pending; - } - }, { - key: "uas_pending_reply", - get: function get() { - return this._uas_pending_reply; + }], [{ + key: "C", + get: // Expose C object. + function get() { + return C; } }]); @@ -797,6 +795,11 @@ module.exports = /*#__PURE__*/function () { } _createClass(DialogRequestSender, [{ + key: "request", + get: function get() { + return this._request; + } + }, { key: "send", value: function send() { var _this = this; @@ -862,11 +865,6 @@ module.exports = /*#__PURE__*/function () { this._eventHandlers.onErrorResponse(response); } } - }, { - key: "request", - get: function get() { - return this._request; - } }]); return DialogRequestSender; @@ -1100,7 +1098,7 @@ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } @@ -16168,7 +16166,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -16211,6 +16209,21 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Message, [{ + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { key: "send", value: function send(target, body) { var _this2 = this; @@ -16434,21 +16447,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { response: response }); } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } }]); return Message; @@ -16467,24 +16465,6 @@ var URI = require('./URI'); var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { - _createClass(NameAddrHeader, null, [{ - key: "parse", - - /** - * Parse the given string and returns a NameAddrHeader instance or undefined if - * it is an invalid NameAddrHeader. - */ - value: function parse(name_addr_header) { - name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); - - if (name_addr_header !== -1) { - return name_addr_header; - } else { - return undefined; - } - } - }]); - function NameAddrHeader(uri, display_name, parameters) { _classCallCheck(this, NameAddrHeader); @@ -16506,6 +16486,19 @@ module.exports = /*#__PURE__*/function () { } _createClass(NameAddrHeader, [{ + key: "uri", + get: function get() { + return this._uri; + } + }, { + key: "display_name", + get: function get() { + return this._display_name; + }, + set: function set(value) { + this._display_name = value === 0 ? '0' : value; + } + }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -16570,18 +16563,21 @@ module.exports = /*#__PURE__*/function () { return body; } - }, { - key: "uri", - get: function get() { - return this._uri; - } - }, { - key: "display_name", - get: function get() { - return this._display_name; - }, - set: function set(value) { - this._display_name = value === 0 ? '0' : value; + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a NameAddrHeader instance or undefined if + * it is an invalid NameAddrHeader. + */ + function parse(name_addr_header) { + name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); + + if (name_addr_header !== -1) { + return name_addr_header; + } else { + return undefined; + } } }]); @@ -16590,7 +16586,7 @@ module.exports = /*#__PURE__*/function () { },{"./Grammar":7,"./URI":25}],11:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -16924,7 +16920,7 @@ function parseHeader(message, data, headerStart, headerEnd) { function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -16946,7 +16942,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -17010,17 +17006,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(RTCSession); - _createClass(RTCSession, null, [{ - key: "C", - - /** - * Expose C object. - */ - get: function get() { - return C; - } - }]); - function RTCSession(ua) { var _this; @@ -17100,6 +17085,70 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _createClass(RTCSession, [{ + key: "C", + get: function get() { + return C; + } // Expose session failed/ended causes as a property of the RTCSession instance. + + }, { + key: "causes", + get: function get() { + return JsSIP_C.causes; + } + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "connection", + get: function get() { + return this._connection; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "start_time", + get: function get() { + return this._start_time; + } + }, { + key: "end_time", + get: function get() { + return this._end_time; + } + }, { + key: "data", + get: function get() { + return this._data; + }, + set: function set(_data) { + this._data = _data; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { key: "isInProgress", value: function isInProgress() { switch (this._status) { @@ -20135,69 +20184,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { video: video }); } - }, { + }], [{ key: "C", - get: function get() { + get: + /** + * Expose C object. + */ + function get() { return C; - } // Expose session failed/ended causes as a property of the RTCSession instance. - - }, { - key: "causes", - get: function get() { - return JsSIP_C.causes; - } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "connection", - get: function get() { - return this._connection; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "start_time", - get: function get() { - return this._start_time; - } - }, { - key: "end_time", - get: function get() { - return this._end_time; - } - }, { - key: "data", - get: function get() { - return this._data; - }, - set: function set(_data) { - this._data = _data; - } - }, { - key: "status", - get: function get() { - return this._status; } }]); @@ -20224,7 +20218,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -20269,6 +20263,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(DTMF, [{ + key: "tone", + get: function get() { + return this._tone; + } + }, { + key: "duration", + get: function get() { + return this._duration; + } + }, { key: "send", value: function send(tone) { var _this2 = this; @@ -20386,16 +20390,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } } - }, { - key: "tone", - get: function get() { - return this._tone; - } - }, { - key: "duration", - get: function get() { - return this._duration; - } }]); return DTMF; @@ -20427,7 +20421,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -20462,6 +20456,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Info, [{ + key: "contentType", + get: function get() { + return this._contentType; + } + }, { + key: "body", + get: function get() { + return this._body; + } + }, { key: "send", value: function send(contentType, body) { var _this2 = this; @@ -20532,16 +20536,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request: request }); } - }, { - key: "contentType", - get: function get() { - return this._contentType; - } - }, { - key: "body", - get: function get() { - return this._body; - } }]); return Info; @@ -20632,7 +20626,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -20663,6 +20657,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(ReferSubscriber, [{ + key: "id", + get: function get() { + return this._id; + } + }, { key: "sendRefer", value: function sendRefer(target) { var _this2 = this; @@ -20784,11 +20783,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { cause: cause }); } - }, { - key: "id", - get: function get() { - return this._id; - } }]); return ReferSubscriber; @@ -20849,6 +20843,11 @@ module.exports = /*#__PURE__*/function () { } _createClass(Registrator, [{ + key: "registered", + get: function get() { + return this._registered; + } + }, { key: "setExtraHeaders", value: function setExtraHeaders(extraHeaders) { if (!Array.isArray(extraHeaders)) { @@ -21144,11 +21143,6 @@ module.exports = /*#__PURE__*/function () { cause: cause || null }); } - }, { - key: "registered", - get: function get() { - return this._registered; - } }]); return Registrator; @@ -21179,7 +21173,10 @@ var EventHandlers = { }; module.exports = /*#__PURE__*/function () { + // Igor's extension: alternative credential function RequestSender(ua, request, eventHandlers) { + var config2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + _classCallCheck(this, RequestSender); this._ua = ua; @@ -21188,7 +21185,8 @@ module.exports = /*#__PURE__*/function () { this._request = request; this._auth = null; this._challenged = false; - this._staled = false; // Define the undefined handlers. + this._staled = false; + this._config2 = config2; // Define the undefined handlers. for (var handler in EventHandlers) { if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { @@ -21261,7 +21259,7 @@ module.exports = /*#__PURE__*/function () { * Authenticate once. _challenged_ flag used to avoid infinite authentications. */ - if ((status_code === 401 || status_code === 407) && (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { + if ((status_code === 401 || status_code === 407) && (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. if (response.status_code === 401) { challenge = response.parseHeader('www-authenticate'); @@ -21282,11 +21280,12 @@ module.exports = /*#__PURE__*/function () { if (!this._challenged || !this._staled && challenge.stale === true) { if (!this._auth) { + var cnf = this._config2 ? this._config2 : this._ua.configuration; this._auth = new DigestAuthentication({ - username: this._ua.configuration.authorization_user, - password: this._ua.configuration.password, - realm: this._ua.configuration.realm, - ha1: this._ua.configuration.ha1 + username: cnf.authorization_user, + password: cnf.password, + realm: cnf.realm, + ha1: cnf.ha1 }); } // Verify that the challenge is really valid. @@ -21297,11 +21296,16 @@ module.exports = /*#__PURE__*/function () { return; } - this._challenged = true; // Update ha1 and realm in the UA. + this._challenged = true; // Update ha1 and realm in the UA or in alternative config. - this._ua.set('realm', this._auth.get('realm')); + if (!this._config2) { + this._ua.set('realm', this._auth.get('realm')); - this._ua.set('ha1', this._auth.get('ha1')); + this._ua.set('ha1', this._auth.get('ha1')); + } else { + this._config2.realm = this._auth.get('realm'); + this._config2.ha1 = this._auth.get('ha1'); + } if (challenge.stale) { this._staled = true; @@ -21343,11 +21347,11 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -22300,7 +22304,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -22366,6 +22370,11 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } _createClass(NonInviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22447,11 +22456,6 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return NonInviteClientTransaction; @@ -22486,6 +22490,11 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } _createClass(InviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22641,11 +22650,6 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return InviteClientTransaction; @@ -22675,6 +22679,11 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { } _createClass(AckClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "send", value: function send() { if (!this.transport.send(this.request)) { @@ -22687,11 +22696,6 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { debugact("transport error occurred for transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } - }, { - key: "C", - get: function get() { - return C; - } }]); return AckClientTransaction; @@ -22721,6 +22725,11 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } _createClass(NonInviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22807,11 +22816,6 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return NonInviteServerTransaction; @@ -22843,6 +22847,11 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } _createClass(InviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22987,11 +22996,6 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return InviteServerTransaction; @@ -23209,6 +23213,21 @@ module.exports = /*#__PURE__*/function () { _createClass(Transport, [{ + key: "via_transport", + get: function get() { + return this.socket.via_transport; + } + }, { + key: "url", + get: function get() { + return this.socket.url; + } + }, { + key: "sip_uri", + get: function get() { + return this.socket.sip_uri; + } + }, { key: "connect", value: function connect() { debug('connect()'); @@ -23421,21 +23440,6 @@ module.exports = /*#__PURE__*/function () { message: data }); } - }, { - key: "via_transport", - get: function get() { - return this.socket.via_transport; - } - }, { - key: "url", - get: function get() { - return this.socket.url; - } - }, { - key: "sip_uri", - get: function get() { - return this.socket.sip_uri; - } }]); return Transport; @@ -23461,7 +23465,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -23489,6 +23493,8 @@ var Parser = require('./Parser'); var SIPMessage = require('./SIPMessage'); +var RequestSender = require('./RequestSender'); + var sanityCheck = require('./sanityCheck'); var config = require('./Config'); @@ -23521,14 +23527,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(UA); - _createClass(UA, null, [{ - key: "C", - // Expose C object. - get: function get() { - return C; - } - }]); - function UA(configuration) { var _this; @@ -23578,8 +23576,30 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(UA, [{ - key: "start", - // ================= + key: "C", + get: function get() { + return C; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "configuration", + get: function get() { + return this._configuration; + } + }, { + key: "transport", + get: function get() { + return this._transport; + } // ================= // High Level API // ================= @@ -23587,6 +23607,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * Connect to the server if status = STATUS_INIT. * Resume UA after being closed. */ + + }, { + key: "start", value: function start() { debug('start()'); @@ -23703,6 +23726,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { message.send(target, body, options); return message; } + /* arbitrary client transaction */ + + }, { + key: "sendRequest", + value: function sendRequest(method, target, params, headers, body, handlers, credential) { + debug('sendRequest()'); + var request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); + var requestSender = new RequestSender(this, request, handlers, credential); + requestSender.send(); + } /** * Terminate ongoing sessions. */ @@ -24033,13 +24066,19 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var message = new Message(this); message.init_incoming(request); - } else if (method === JsSIP_C.INVITE) { - // Initial INVITE. - if (!request.to_tag && this.listeners('newRTCSession').length === 0) { - request.reply(405); - return; + } // incoming subscribe + else if (method === JsSIP_C.SUBSCRIBE) { + if (this.listeners('newSubscribe').length === 0) { + request.reply(405); + return; + } + } else if (method === JsSIP_C.INVITE) { + // Initial INVITE. + if (!request.to_tag && this.listeners('newRTCSession').length === 0) { + request.reply(405); + return; + } } - } var dialog; var session; // Initial Request. @@ -24107,6 +24146,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(200); break; + case JsSIP_C.SUBSCRIBE: + // Igor's extension: incoming SUBSCRIBE + this.emit('newSubscribe', { + event: request.event, + request: request + }); + break; + default: request.reply(405); break; @@ -24330,31 +24377,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - }, { + }], [{ key: "C", - get: function get() { + get: // Expose C object. + function get() { return C; } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "configuration", - get: function get() { - return this._configuration; - } - }, { - key: "transport", - get: function get() { - return this._transport; - } }]); return UA; @@ -24463,10 +24491,10 @@ function onTransportData(data) { } } } -},{"./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(require,module,exports){ +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./RequestSender":18,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":30,"events":29}],25:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -24495,24 +24523,6 @@ var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { - _createClass(URI, null, [{ - key: "parse", - - /** - * Parse the given string and returns a JsSIP.URI instance or undefined if - * it is an invalid URI. - */ - value: function parse(uri) { - uri = Grammar.parse(uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } else { - return undefined; - } - } - }]); - function URI(scheme, user, host, port) { var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; @@ -24546,6 +24556,38 @@ module.exports = /*#__PURE__*/function () { } _createClass(URI, [{ + key: "scheme", + get: function get() { + return this._scheme; + }, + set: function set(value) { + this._scheme = value.toLowerCase(); + } + }, { + key: "user", + get: function get() { + return this._user; + }, + set: function set(value) { + this._user = value; + } + }, { + key: "host", + get: function get() { + return this._host; + }, + set: function set(value) { + this._host = value.toLowerCase(); + } + }, { + key: "port", + get: function get() { + return this._port; + }, + set: function set(value) { + this._port = value === 0 ? value : parseInt(value, 10) || null; + } + }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -24689,37 +24731,21 @@ module.exports = /*#__PURE__*/function () { return aor; } - }, { - key: "scheme", - get: function get() { - return this._scheme; - }, - set: function set(value) { - this._scheme = value.toLowerCase(); - } - }, { - key: "user", - get: function get() { - return this._user; - }, - set: function set(value) { - this._user = value; - } - }, { - key: "host", - get: function get() { - return this._host; - }, - set: function set(value) { - this._host = value.toLowerCase(); - } - }, { - key: "port", - get: function get() { - return this._port; - }, - set: function set(value) { - this._port = value === 0 ? value : parseInt(value, 10) || null; + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a JsSIP.URI instance or undefined if + * it is an invalid URI. + */ + function parse(uri) { + uri = Grammar.parse(uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } else { + return undefined; + } } }]); @@ -24730,7 +24756,7 @@ module.exports = /*#__PURE__*/function () { function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -25299,6 +25325,24 @@ module.exports = /*#__PURE__*/function () { } _createClass(WebSocketInterface, [{ + key: "via_transport", + get: function get() { + return this._via_transport; + }, + set: function set(value) { + this._via_transport = value.toUpperCase(); + } + }, { + key: "sip_uri", + get: function get() { + return this._sip_uri; + } + }, { + key: "url", + get: function get() { + return this._url; + } + }, { key: "connect", value: function connect() { debug('connect()'); @@ -25408,24 +25452,6 @@ module.exports = /*#__PURE__*/function () { value: function _onError(e) { debugerror("WebSocket ".concat(this._url, " error: "), e); } - }, { - key: "via_transport", - get: function get() { - return this._via_transport; - }, - set: function set(value) { - this._via_transport = value.toUpperCase(); - } - }, { - key: "sip_uri", - get: function get() { - return this._sip_uri; - } - }, { - key: "url", - get: function get() { - return this._url; - } }]); return WebSocketInterface; @@ -25433,7 +25459,7 @@ module.exports = /*#__PURE__*/function () { },{"./Grammar":7,"debug":30}],28:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -26208,19 +26234,28 @@ function functionBindPolyfill(context) { } },{}],30:[function(require,module,exports){ -(function (process){ +(function (process){(function (){ /* eslint-env browser */ /** * This is the web browser implementation of `debug()`. */ -exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.storage = localstorage(); +exports.destroy = (() => { + let warned = false; + + return () => { + if (!warned) { + warned = true; + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + }; +})(); /** * Colors. @@ -26381,18 +26416,14 @@ function formatArgs(args) { } /** - * Invokes `console.log()` when available. - * No-op when `console.log` is not a "function". + * Invokes `console.debug()` when available. + * No-op when `console.debug` is not a "function". + * If `console.debug` is not available, falls back + * to `console.log`. * * @api public */ -function log(...args) { - // This hackery is required for IE8/9, where - // the `console.log` function doesn't have 'apply' - return typeof console === 'object' && - console.log && - console.log(...args); -} +exports.log = console.debug || console.log || (() => {}); /** * Save `namespaces`. @@ -26474,7 +26505,7 @@ formatters.j = function (v) { } }; -}).call(this,require('_process')) +}).call(this)}).call(this,require('_process')) },{"./common":31,"_process":33}],31:[function(require,module,exports){ /** @@ -26490,16 +26521,12 @@ function setup(env) { createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = require('ms'); + createDebug.destroy = destroy; Object.keys(env).forEach(key => { createDebug[key] = env[key]; }); - /** - * Active `debug` instances. - */ - createDebug.instances = []; - /** * The currently active debug mode names, and names to skip. */ @@ -26541,6 +26568,7 @@ function setup(env) { */ function createDebug(namespace) { let prevTime; + let enableOverride = null; function debug(...args) { // Disabled? @@ -26570,7 +26598,7 @@ function setup(env) { args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { // If we encounter an escaped % then don't increase the array index if (match === '%%') { - return match; + return '%'; } index++; const formatter = createDebug.formatters[format]; @@ -26593,33 +26621,28 @@ function setup(env) { } debug.namespace = namespace; - debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); - debug.color = selectColor(namespace); - debug.destroy = destroy; + debug.color = createDebug.selectColor(namespace); debug.extend = extend; - // Debug.formatArgs = formatArgs; - // debug.rawLog = rawLog; + debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. + + Object.defineProperty(debug, 'enabled', { + enumerable: true, + configurable: false, + get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, + set: v => { + enableOverride = v; + } + }); - // env-specific initialization logic for debug instances + // Env-specific initialization logic for debug instances if (typeof createDebug.init === 'function') { createDebug.init(debug); } - createDebug.instances.push(debug); - return debug; } - function destroy() { - const index = createDebug.instances.indexOf(this); - if (index !== -1) { - createDebug.instances.splice(index, 1); - return true; - } - return false; - } - function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); newDebug.log = this.log; @@ -26657,11 +26680,6 @@ function setup(env) { createDebug.names.push(new RegExp('^' + namespaces + '$')); } } - - for (i = 0; i < createDebug.instances.length; i++) { - const instance = createDebug.instances[i]; - instance.enabled = createDebug.enabled(instance.namespace); - } } /** @@ -26736,6 +26754,14 @@ function setup(env) { return val; } + /** + * XXX DO NOT USE. This is a temporary stub function. + * XXX It WILL be removed in the next major release. + */ + function destroy() { + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + createDebug.enable(createDebug.load()); return createDebug; @@ -27189,7 +27215,7 @@ var grammar = module.exports = { push: 'rtcpFbTrrInt', reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, names: ['payload', 'value'], - format: 'rtcp-fb:%d trr-int %d' + format: 'rtcp-fb:%s trr-int %d' }, { // a=rtcp-fb:98 nack rpsi diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 59d4909e2..46ae09bba 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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=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);n0)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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":38}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&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.cseqthis._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=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;n2&&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:N,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:k,token_nodot:D,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:U,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:z,qdtext:J,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:Ne,headers:ke,header:De,hname:Ue,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:ze,scheme:Je,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=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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;tl&&(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 N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){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 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&&(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 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&&(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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 z(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 J(){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=ke())?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=k())))),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=k())),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=k())?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=Ne())&&null===(e=C())&&(e=E()),e}function Ne(){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 ke(){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=De())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?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=De())?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 De(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=Ue())?(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 Ue(){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=Je())?(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=ze();null!==t;)e.push(t),t=ze();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=ze();null!==t;)e.push(t),t=ze();return e}function ze(){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 Je(){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=k()),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=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),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=k())?(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=k())&&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=k())))),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=k())),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=Nt())&&(e=kt()),e}function Nt(){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=Dt()))))),e}function kt(){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=Dt())),e}function Dt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){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=k())?e=[e,t]:(e=null,i=r),e}function xt(){var e;return null===(e=Dt())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(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=D())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?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=D())?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=k())?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=k()))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=k())&&null!==(t=M())?(null===(n=k())&&(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=Jt())&&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=z())&&(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=zt())){if(l=[],f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?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=zt())?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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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=z())&&(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=z())?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=k())),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=k())),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=k()))),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=k()))))))),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=k())?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=k())&&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=k()),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=k())))),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=N())&&(t=A());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=A());return e}function Nn(){var e,t,r,s,l,u,c,h,f,d,_,p;return d=i,_=i,null!==(e=Dn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(f=Un())?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 kn(){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 Dn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function xn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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=k())?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=k())?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=Gn2&&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"),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=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);n1&&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")):t.fromUserName&&(p.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(p.from_display_name=t.fromDisplayName),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;e.body&&"application/sdp"!==s?e.reply(415):(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)?(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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,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 N=b.value;o.removeTrack(N)}}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?rC.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=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: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._localMediaStream&&this._localMediaStreamLocallyGenerated&&(R("close() | closing local MediaStream"),m.closeMediaStream(this._localMediaStream)),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._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),nv.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(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:d.causes.RTP_TIMEOUT,status_code:408,reason_phrase:d.causes.RTP_TIMEOUT})}),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()})})})}},{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;n1&&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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&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;n1&&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"')}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=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")),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;r1&&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=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){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=u.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("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}}])&&r(t.prototype,n),l&&r(t,l),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;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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":case"authorization_jwt":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);n4&&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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&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=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);n1)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(e0&&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;t1&&(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=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=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{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{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=[];++f1)for(var n=1;n1&&(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=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.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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=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=n.call(e)},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);n0)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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":38}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),a("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,a("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){a("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=u.cloneArray(n.extraHeaders),s=u.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=u.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),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=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)}}])&&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;n2&&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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:N,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:k,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:x,STAR:D,SLASH:P,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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:z,qdtext:J,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:Ne,headers:ke,header:Ue,hname:xe,hvalue:De,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:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=D()))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;tl&&(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 N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){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 x(){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 D(){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 B(){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 W(){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 V(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 z(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 J(){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=ke())?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=k())))),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=k())),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=k())?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=Ne())&&null===(e=C())&&(e=E()),e}function Ne(){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 ke(){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=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=De())?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 xe(){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 De(){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=Je())?(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=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){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 Ve(){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=ze();null!==t;)e.push(t),t=ze();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=ze();null!==t;)e.push(t),t=ze();return e}function ze(){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 Je(){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=Be();null!==t;)e.push(t),t=Be();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=k()),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=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),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=k())?(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=k())&&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=k())))),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=k())),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=Dt())){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=Nt())&&(e=kt()),e}function Nt(){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 kt(){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=k())&&(e=xt()),e}function xt(){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=k())?e=[e,t]:(e=null,i=r),e}function Dt(){var e;return null===(e=Ut())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(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=k())?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=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(u=Wt())?l=[l,u]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(u=Wt())?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=k()))if(null!==(t=A()))if(null!==(n=Bt())){for(r=[],u=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=j())&&null!==(o=Bt())?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 Bt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=Y()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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=z())&&(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=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?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=zt())?u=[u,c]:(u=null,i=f)}null!==l&&null!==(u=V())?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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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=z())&&(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=z())?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=k())),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=W())){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=V())?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=k())),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=k()))),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=k()))))))),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=k())?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=k())&&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=k()),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=k())))),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=B())&&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=N())&&(t=A());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=A());return e}function Nn(){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=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(f=xn())?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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Dn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=k())?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=k())?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),Bn=Gn2&&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})}}])&&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"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":25}],11:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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=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=n.call(e)},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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;b("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=p.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!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new A("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new A("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,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;b("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||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===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};b('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(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===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};b("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(b("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(b("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(b("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(f.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]:{};b("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(b('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new T(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(b("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};b("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};b("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(b("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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(b("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;b("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;b("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 b("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(b("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};b('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){b("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){b("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||(b("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(b("_isReadyToReOffer() | session not established yet"),!1):(b("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(b("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(b("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(b("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),b('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(b("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 b('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};b('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(b(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(b(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;b("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 b("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;b("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return b("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;b("_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!==I.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};b('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===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(b("receiveRefer()"),!e.refer_to)return b("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return b("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);b('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new a(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(b("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;b("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new a(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){b("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,b('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(b("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void b(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){b("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};b('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};b('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};b('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};b('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),R('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]:{};b("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.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};b('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),R('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)};b('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.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(f.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){b("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){b("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!==I.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){b("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){b("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!==I.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 h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(b("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){b("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){b("session connecting"),b('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){b("session progress"),b('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){b("session accepted"),this._start_time=new Date,b('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){b("session confirmed"),this._is_confirmed=!0,b('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){b("session ended"),this._end_time=new Date,this._close(),b('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){b("session failed"),b('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),b('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){b("session onhold"),this._setLocalMediaStatus(),b('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){b("session onunhold"),this._setLocalMediaStatus(),b('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;b("session onmute"),this._setLocalMediaStatus(),b('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;b("session onunmute"),this._setLocalMediaStatus(),b('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),a}()},{"./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;n1&&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")}}])&&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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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})}}])&&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=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&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;n1&&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})}}])&&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"')}var t,n,a;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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})}}])&&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;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,u)Object.prototype.hasOwnProperty.call(u,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=u[o]));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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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")),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;r1&&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=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)}}}]),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:"C",get:function(){return C}},{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()}}]),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:"C",get:function(){return C}},{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:}}}]),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:"C",get:function(){return C}},{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())}}}]),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){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=u.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),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;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./RequestSender":18,"./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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var u in this._parameters={},this._headers={},this._scheme=t||o.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 l)Object.prototype.hasOwnProperty.call(l,a)&&this.setHeader(a,l[a])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=u.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 u=i.value;e.push("".concat(s,"=").concat(u))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&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=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=n.call(e)},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);n1)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(e0&&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;t1&&(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=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=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){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":31,_process:33}],31:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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=[];++f1)for(var n=1;n1&&(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=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.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/RequestSender.js b/lib/RequestSender.js index d33f9f61b..cc1becb7c 100644 --- a/lib/RequestSender.js +++ b/lib/RequestSender.js @@ -13,7 +13,8 @@ const EventHandlers = { module.exports = class RequestSender { - constructor(ua, request, eventHandlers) + // Igor's extension: alternative credential + constructor(ua, request, eventHandlers, config2=null) { this._ua = ua; this._eventHandlers = eventHandlers; @@ -22,7 +23,8 @@ module.exports = class RequestSender this._auth = null; this._challenged = false; this._staled = false; - + this._config2 = config2; + // Define the undefined handlers. for (const handler in EventHandlers) { @@ -92,7 +94,7 @@ module.exports = class RequestSender * Authenticate once. _challenged_ flag used to avoid infinite authentications. */ if ((status_code === 401 || status_code === 407) && - (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) + (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. @@ -120,12 +122,13 @@ module.exports = class RequestSender { if (!this._auth) { - this._auth = new DigestAuthentication({ - username : this._ua.configuration.authorization_user, - password : this._ua.configuration.password, - realm : this._ua.configuration.realm, - ha1 : this._ua.configuration.ha1 - }); + let cnf = this._config2 ? this._config2 : this._ua.configuration; + this._auth = new DigestAuthentication({ + username : cnf.authorization_user, + password : cnf.password, + realm : cnf.realm, + ha1 : cnf.ha1 + }); } // Verify that the challenge is really valid. @@ -137,10 +140,17 @@ module.exports = class RequestSender } this._challenged = true; - // Update ha1 and realm in the UA. - this._ua.set('realm', this._auth.get('realm')); - this._ua.set('ha1', this._auth.get('ha1')); - + // Update ha1 and realm in the UA or in alternative config. + if( !this._config2 ) + { + this._ua.set('realm', this._auth.get('realm')); + this._ua.set('ha1', this._auth.get('ha1')); + } + else + { + this._config2.realm = this._auth.get('realm'); + this._config2.ha1 = this._auth.get('ha1'); + } if (challenge.stale) { this._staled = true; diff --git a/lib/UA.js b/lib/UA.js index 878eec645..52cb36fc9 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -10,6 +10,7 @@ const Exceptions = require('./Exceptions'); const URI = require('./URI'); const Parser = require('./Parser'); const SIPMessage = require('./SIPMessage'); +const RequestSender = require('./RequestSender'); const sanityCheck = require('./sanityCheck'); const config = require('./Config'); const debug = require('debug')('JsSIP:UA'); @@ -256,7 +257,17 @@ module.exports = class UA extends EventEmitter return message; } - + + + /* arbitrary client transaction */ + sendRequest(method, target, params, headers, body, handlers, credential) + { + debug('sendRequest()'); + const request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); + const requestSender = new RequestSender(this, request, handlers, credential); + requestSender.send(); + } + /** * Terminate ongoing sessions. */ @@ -595,6 +606,15 @@ module.exports = class UA extends EventEmitter const message = new Message(this); message.init_incoming(request); + } + // incoming subscribe + else if (method === JsSIP_C.SUBSCRIBE) + { + if (this.listeners('newSubscribe').length === 0) + { + request.reply(405); + return; + } } else if (method === JsSIP_C.INVITE) { @@ -682,6 +702,13 @@ module.exports = class UA extends EventEmitter }); request.reply(200); break; + case JsSIP_C.SUBSCRIBE: + // Igor's extension: incoming SUBSCRIBE + this.emit('newSubscribe', { + event : request.event, + request + }); + break; default: request.reply(405); break; From 6469fc395e15728e6f05270d005227c5cc97f3a9 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 13 May 2021 22:16:20 +0300 Subject: [PATCH 02/70] alternative authentication --- dist/jssip.js | 830 ++++++++++++++++++++++--------------------- dist/jssip.min.js | 2 +- lib/RequestSender.js | 35 +- lib/UA.js | 29 +- 4 files changed, 479 insertions(+), 417 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 063170734..ef5bed700 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -9,7 +9,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -498,14 +498,6 @@ var C = { }; // RFC 3261 12.1. module.exports = /*#__PURE__*/function () { - _createClass(Dialog, null, [{ - key: "C", - // Expose C object. - get: function get() { - return C; - } - }]); - function Dialog(owner, message, type) { var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; @@ -569,6 +561,37 @@ module.exports = /*#__PURE__*/function () { } _createClass(Dialog, [{ + key: "id", + get: function get() { + return this._id; + } + }, { + key: "local_seqnum", + get: function get() { + return this._local_seqnum; + }, + set: function set(num) { + this._local_seqnum = num; + } + }, { + key: "owner", + get: function get() { + return this._owner; + } + }, { + key: "uac_pending_reply", + get: function get() { + return this._uac_pending_reply; + }, + set: function set(pending) { + this._uac_pending_reply = pending; + } + }, { + key: "uas_pending_reply", + get: function get() { + return this._uas_pending_reply; + } + }, { key: "update", value: function update(message, type) { this._state = C.STATUS_CONFIRMED; @@ -713,36 +736,11 @@ module.exports = /*#__PURE__*/function () { return true; } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "local_seqnum", - get: function get() { - return this._local_seqnum; - }, - set: function set(num) { - this._local_seqnum = num; - } - }, { - key: "owner", - get: function get() { - return this._owner; - } - }, { - key: "uac_pending_reply", - get: function get() { - return this._uac_pending_reply; - }, - set: function set(pending) { - this._uac_pending_reply = pending; - } - }, { - key: "uas_pending_reply", - get: function get() { - return this._uas_pending_reply; + }], [{ + key: "C", + get: // Expose C object. + function get() { + return C; } }]); @@ -797,6 +795,11 @@ module.exports = /*#__PURE__*/function () { } _createClass(DialogRequestSender, [{ + key: "request", + get: function get() { + return this._request; + } + }, { key: "send", value: function send() { var _this = this; @@ -862,11 +865,6 @@ module.exports = /*#__PURE__*/function () { this._eventHandlers.onErrorResponse(response); } } - }, { - key: "request", - get: function get() { - return this._request; - } }]); return DialogRequestSender; @@ -1100,7 +1098,7 @@ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } @@ -16168,7 +16166,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -16211,6 +16209,21 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Message, [{ + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { key: "send", value: function send(target, body) { var _this2 = this; @@ -16434,21 +16447,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { response: response }); } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } }]); return Message; @@ -16467,24 +16465,6 @@ var URI = require('./URI'); var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { - _createClass(NameAddrHeader, null, [{ - key: "parse", - - /** - * Parse the given string and returns a NameAddrHeader instance or undefined if - * it is an invalid NameAddrHeader. - */ - value: function parse(name_addr_header) { - name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); - - if (name_addr_header !== -1) { - return name_addr_header; - } else { - return undefined; - } - } - }]); - function NameAddrHeader(uri, display_name, parameters) { _classCallCheck(this, NameAddrHeader); @@ -16506,6 +16486,19 @@ module.exports = /*#__PURE__*/function () { } _createClass(NameAddrHeader, [{ + key: "uri", + get: function get() { + return this._uri; + } + }, { + key: "display_name", + get: function get() { + return this._display_name; + }, + set: function set(value) { + this._display_name = value === 0 ? '0' : value; + } + }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -16570,18 +16563,21 @@ module.exports = /*#__PURE__*/function () { return body; } - }, { - key: "uri", - get: function get() { - return this._uri; - } - }, { - key: "display_name", - get: function get() { - return this._display_name; - }, - set: function set(value) { - this._display_name = value === 0 ? '0' : value; + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a NameAddrHeader instance or undefined if + * it is an invalid NameAddrHeader. + */ + function parse(name_addr_header) { + name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); + + if (name_addr_header !== -1) { + return name_addr_header; + } else { + return undefined; + } } }]); @@ -16590,7 +16586,7 @@ module.exports = /*#__PURE__*/function () { },{"./Grammar":7,"./URI":25}],11:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -16924,7 +16920,7 @@ function parseHeader(message, data, headerStart, headerEnd) { function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -16946,7 +16942,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -17010,17 +17006,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(RTCSession); - _createClass(RTCSession, null, [{ - key: "C", - - /** - * Expose C object. - */ - get: function get() { - return C; - } - }]); - function RTCSession(ua) { var _this; @@ -17100,6 +17085,70 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _createClass(RTCSession, [{ + key: "C", + get: function get() { + return C; + } // Expose session failed/ended causes as a property of the RTCSession instance. + + }, { + key: "causes", + get: function get() { + return JsSIP_C.causes; + } + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "connection", + get: function get() { + return this._connection; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "start_time", + get: function get() { + return this._start_time; + } + }, { + key: "end_time", + get: function get() { + return this._end_time; + } + }, { + key: "data", + get: function get() { + return this._data; + }, + set: function set(_data) { + this._data = _data; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { key: "isInProgress", value: function isInProgress() { switch (this._status) { @@ -20135,69 +20184,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { video: video }); } - }, { + }], [{ key: "C", - get: function get() { + get: + /** + * Expose C object. + */ + function get() { return C; - } // Expose session failed/ended causes as a property of the RTCSession instance. - - }, { - key: "causes", - get: function get() { - return JsSIP_C.causes; - } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "connection", - get: function get() { - return this._connection; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "start_time", - get: function get() { - return this._start_time; - } - }, { - key: "end_time", - get: function get() { - return this._end_time; - } - }, { - key: "data", - get: function get() { - return this._data; - }, - set: function set(_data) { - this._data = _data; - } - }, { - key: "status", - get: function get() { - return this._status; } }]); @@ -20224,7 +20218,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -20269,6 +20263,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(DTMF, [{ + key: "tone", + get: function get() { + return this._tone; + } + }, { + key: "duration", + get: function get() { + return this._duration; + } + }, { key: "send", value: function send(tone) { var _this2 = this; @@ -20386,16 +20390,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } } - }, { - key: "tone", - get: function get() { - return this._tone; - } - }, { - key: "duration", - get: function get() { - return this._duration; - } }]); return DTMF; @@ -20427,7 +20421,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -20462,6 +20456,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Info, [{ + key: "contentType", + get: function get() { + return this._contentType; + } + }, { + key: "body", + get: function get() { + return this._body; + } + }, { key: "send", value: function send(contentType, body) { var _this2 = this; @@ -20532,16 +20536,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request: request }); } - }, { - key: "contentType", - get: function get() { - return this._contentType; - } - }, { - key: "body", - get: function get() { - return this._body; - } }]); return Info; @@ -20632,7 +20626,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -20663,6 +20657,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(ReferSubscriber, [{ + key: "id", + get: function get() { + return this._id; + } + }, { key: "sendRefer", value: function sendRefer(target) { var _this2 = this; @@ -20784,11 +20783,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { cause: cause }); } - }, { - key: "id", - get: function get() { - return this._id; - } }]); return ReferSubscriber; @@ -20849,6 +20843,11 @@ module.exports = /*#__PURE__*/function () { } _createClass(Registrator, [{ + key: "registered", + get: function get() { + return this._registered; + } + }, { key: "setExtraHeaders", value: function setExtraHeaders(extraHeaders) { if (!Array.isArray(extraHeaders)) { @@ -21144,11 +21143,6 @@ module.exports = /*#__PURE__*/function () { cause: cause || null }); } - }, { - key: "registered", - get: function get() { - return this._registered; - } }]); return Registrator; @@ -21179,7 +21173,10 @@ var EventHandlers = { }; module.exports = /*#__PURE__*/function () { + // Igor's extension: alternative credential function RequestSender(ua, request, eventHandlers) { + var config2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + _classCallCheck(this, RequestSender); this._ua = ua; @@ -21188,7 +21185,8 @@ module.exports = /*#__PURE__*/function () { this._request = request; this._auth = null; this._challenged = false; - this._staled = false; // Define the undefined handlers. + this._staled = false; + this._config2 = config2; // Define the undefined handlers. for (var handler in EventHandlers) { if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { @@ -21261,7 +21259,7 @@ module.exports = /*#__PURE__*/function () { * Authenticate once. _challenged_ flag used to avoid infinite authentications. */ - if ((status_code === 401 || status_code === 407) && (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { + if ((status_code === 401 || status_code === 407) && (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. if (response.status_code === 401) { challenge = response.parseHeader('www-authenticate'); @@ -21282,11 +21280,12 @@ module.exports = /*#__PURE__*/function () { if (!this._challenged || !this._staled && challenge.stale === true) { if (!this._auth) { + var cnf = this._config2 ? this._config2 : this._ua.configuration; this._auth = new DigestAuthentication({ - username: this._ua.configuration.authorization_user, - password: this._ua.configuration.password, - realm: this._ua.configuration.realm, - ha1: this._ua.configuration.ha1 + username: cnf.authorization_user, + password: cnf.password, + realm: cnf.realm, + ha1: cnf.ha1 }); } // Verify that the challenge is really valid. @@ -21297,11 +21296,16 @@ module.exports = /*#__PURE__*/function () { return; } - this._challenged = true; // Update ha1 and realm in the UA. + this._challenged = true; // Update ha1 and realm in the UA or in alternative config. - this._ua.set('realm', this._auth.get('realm')); + if (!this._config2) { + this._ua.set('realm', this._auth.get('realm')); - this._ua.set('ha1', this._auth.get('ha1')); + this._ua.set('ha1', this._auth.get('ha1')); + } else { + this._config2.realm = this._auth.get('realm'); + this._config2.ha1 = this._auth.get('ha1'); + } if (challenge.stale) { this._staled = true; @@ -21343,11 +21347,11 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -22300,7 +22304,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -22366,6 +22370,11 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } _createClass(NonInviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22447,11 +22456,6 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return NonInviteClientTransaction; @@ -22486,6 +22490,11 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } _createClass(InviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22641,11 +22650,6 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return InviteClientTransaction; @@ -22675,6 +22679,11 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { } _createClass(AckClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "send", value: function send() { if (!this.transport.send(this.request)) { @@ -22687,11 +22696,6 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { debugact("transport error occurred for transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } - }, { - key: "C", - get: function get() { - return C; - } }]); return AckClientTransaction; @@ -22721,6 +22725,11 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } _createClass(NonInviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22807,11 +22816,6 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return NonInviteServerTransaction; @@ -22843,6 +22847,11 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } _createClass(InviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22987,11 +22996,6 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return InviteServerTransaction; @@ -23209,6 +23213,21 @@ module.exports = /*#__PURE__*/function () { _createClass(Transport, [{ + key: "via_transport", + get: function get() { + return this.socket.via_transport; + } + }, { + key: "url", + get: function get() { + return this.socket.url; + } + }, { + key: "sip_uri", + get: function get() { + return this.socket.sip_uri; + } + }, { key: "connect", value: function connect() { debug('connect()'); @@ -23421,21 +23440,6 @@ module.exports = /*#__PURE__*/function () { message: data }); } - }, { - key: "via_transport", - get: function get() { - return this.socket.via_transport; - } - }, { - key: "url", - get: function get() { - return this.socket.url; - } - }, { - key: "sip_uri", - get: function get() { - return this.socket.sip_uri; - } }]); return Transport; @@ -23461,7 +23465,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -23489,6 +23493,8 @@ var Parser = require('./Parser'); var SIPMessage = require('./SIPMessage'); +var RequestSender = require('./RequestSender'); + var sanityCheck = require('./sanityCheck'); var config = require('./Config'); @@ -23521,14 +23527,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(UA); - _createClass(UA, null, [{ - key: "C", - // Expose C object. - get: function get() { - return C; - } - }]); - function UA(configuration) { var _this; @@ -23578,8 +23576,30 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(UA, [{ - key: "start", - // ================= + key: "C", + get: function get() { + return C; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "configuration", + get: function get() { + return this._configuration; + } + }, { + key: "transport", + get: function get() { + return this._transport; + } // ================= // High Level API // ================= @@ -23587,6 +23607,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * Connect to the server if status = STATUS_INIT. * Resume UA after being closed. */ + + }, { + key: "start", value: function start() { debug('start()'); @@ -23703,6 +23726,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { message.send(target, body, options); return message; } + /* arbitrary client transaction */ + + }, { + key: "sendRequest", + value: function sendRequest(method, target, params, headers, body, handlers, credential) { + debug('sendRequest()'); + var request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); + var requestSender = new RequestSender(this, request, handlers, credential); + requestSender.send(); + } /** * Terminate ongoing sessions. */ @@ -24033,13 +24066,19 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var message = new Message(this); message.init_incoming(request); - } else if (method === JsSIP_C.INVITE) { - // Initial INVITE. - if (!request.to_tag && this.listeners('newRTCSession').length === 0) { - request.reply(405); - return; + } // incoming subscribe + else if (method === JsSIP_C.SUBSCRIBE) { + if (this.listeners('newSubscribe').length === 0) { + request.reply(405); + return; + } + } else if (method === JsSIP_C.INVITE) { + // Initial INVITE. + if (!request.to_tag && this.listeners('newRTCSession').length === 0) { + request.reply(405); + return; + } } - } var dialog; var session; // Initial Request. @@ -24107,6 +24146,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(200); break; + case JsSIP_C.SUBSCRIBE: + // Igor's extension: incoming SUBSCRIBE + this.emit('newSubscribe', { + event: request.event, + request: request + }); + break; + default: request.reply(405); break; @@ -24330,31 +24377,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - }, { + }], [{ key: "C", - get: function get() { + get: // Expose C object. + function get() { return C; } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "configuration", - get: function get() { - return this._configuration; - } - }, { - key: "transport", - get: function get() { - return this._transport; - } }]); return UA; @@ -24463,10 +24491,10 @@ function onTransportData(data) { } } } -},{"./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(require,module,exports){ +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./RequestSender":18,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":30,"events":29}],25:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -24495,24 +24523,6 @@ var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { - _createClass(URI, null, [{ - key: "parse", - - /** - * Parse the given string and returns a JsSIP.URI instance or undefined if - * it is an invalid URI. - */ - value: function parse(uri) { - uri = Grammar.parse(uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } else { - return undefined; - } - } - }]); - function URI(scheme, user, host, port) { var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; @@ -24546,6 +24556,38 @@ module.exports = /*#__PURE__*/function () { } _createClass(URI, [{ + key: "scheme", + get: function get() { + return this._scheme; + }, + set: function set(value) { + this._scheme = value.toLowerCase(); + } + }, { + key: "user", + get: function get() { + return this._user; + }, + set: function set(value) { + this._user = value; + } + }, { + key: "host", + get: function get() { + return this._host; + }, + set: function set(value) { + this._host = value.toLowerCase(); + } + }, { + key: "port", + get: function get() { + return this._port; + }, + set: function set(value) { + this._port = value === 0 ? value : parseInt(value, 10) || null; + } + }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -24689,37 +24731,21 @@ module.exports = /*#__PURE__*/function () { return aor; } - }, { - key: "scheme", - get: function get() { - return this._scheme; - }, - set: function set(value) { - this._scheme = value.toLowerCase(); - } - }, { - key: "user", - get: function get() { - return this._user; - }, - set: function set(value) { - this._user = value; - } - }, { - key: "host", - get: function get() { - return this._host; - }, - set: function set(value) { - this._host = value.toLowerCase(); - } - }, { - key: "port", - get: function get() { - return this._port; - }, - set: function set(value) { - this._port = value === 0 ? value : parseInt(value, 10) || null; + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a JsSIP.URI instance or undefined if + * it is an invalid URI. + */ + function parse(uri) { + uri = Grammar.parse(uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } else { + return undefined; + } } }]); @@ -24730,7 +24756,7 @@ module.exports = /*#__PURE__*/function () { function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -25299,6 +25325,24 @@ module.exports = /*#__PURE__*/function () { } _createClass(WebSocketInterface, [{ + key: "via_transport", + get: function get() { + return this._via_transport; + }, + set: function set(value) { + this._via_transport = value.toUpperCase(); + } + }, { + key: "sip_uri", + get: function get() { + return this._sip_uri; + } + }, { + key: "url", + get: function get() { + return this._url; + } + }, { key: "connect", value: function connect() { debug('connect()'); @@ -25408,24 +25452,6 @@ module.exports = /*#__PURE__*/function () { value: function _onError(e) { debugerror("WebSocket ".concat(this._url, " error: "), e); } - }, { - key: "via_transport", - get: function get() { - return this._via_transport; - }, - set: function set(value) { - this._via_transport = value.toUpperCase(); - } - }, { - key: "sip_uri", - get: function get() { - return this._sip_uri; - } - }, { - key: "url", - get: function get() { - return this._url; - } }]); return WebSocketInterface; @@ -25433,7 +25459,7 @@ module.exports = /*#__PURE__*/function () { },{"./Grammar":7,"debug":30}],28:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -26208,19 +26234,28 @@ function functionBindPolyfill(context) { } },{}],30:[function(require,module,exports){ -(function (process){ +(function (process){(function (){ /* eslint-env browser */ /** * This is the web browser implementation of `debug()`. */ -exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.storage = localstorage(); +exports.destroy = (() => { + let warned = false; + + return () => { + if (!warned) { + warned = true; + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + }; +})(); /** * Colors. @@ -26381,18 +26416,14 @@ function formatArgs(args) { } /** - * Invokes `console.log()` when available. - * No-op when `console.log` is not a "function". + * Invokes `console.debug()` when available. + * No-op when `console.debug` is not a "function". + * If `console.debug` is not available, falls back + * to `console.log`. * * @api public */ -function log(...args) { - // This hackery is required for IE8/9, where - // the `console.log` function doesn't have 'apply' - return typeof console === 'object' && - console.log && - console.log(...args); -} +exports.log = console.debug || console.log || (() => {}); /** * Save `namespaces`. @@ -26474,7 +26505,7 @@ formatters.j = function (v) { } }; -}).call(this,require('_process')) +}).call(this)}).call(this,require('_process')) },{"./common":31,"_process":33}],31:[function(require,module,exports){ /** @@ -26490,16 +26521,12 @@ function setup(env) { createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = require('ms'); + createDebug.destroy = destroy; Object.keys(env).forEach(key => { createDebug[key] = env[key]; }); - /** - * Active `debug` instances. - */ - createDebug.instances = []; - /** * The currently active debug mode names, and names to skip. */ @@ -26541,6 +26568,7 @@ function setup(env) { */ function createDebug(namespace) { let prevTime; + let enableOverride = null; function debug(...args) { // Disabled? @@ -26570,7 +26598,7 @@ function setup(env) { args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { // If we encounter an escaped % then don't increase the array index if (match === '%%') { - return match; + return '%'; } index++; const formatter = createDebug.formatters[format]; @@ -26593,33 +26621,28 @@ function setup(env) { } debug.namespace = namespace; - debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); - debug.color = selectColor(namespace); - debug.destroy = destroy; + debug.color = createDebug.selectColor(namespace); debug.extend = extend; - // Debug.formatArgs = formatArgs; - // debug.rawLog = rawLog; + debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. + + Object.defineProperty(debug, 'enabled', { + enumerable: true, + configurable: false, + get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, + set: v => { + enableOverride = v; + } + }); - // env-specific initialization logic for debug instances + // Env-specific initialization logic for debug instances if (typeof createDebug.init === 'function') { createDebug.init(debug); } - createDebug.instances.push(debug); - return debug; } - function destroy() { - const index = createDebug.instances.indexOf(this); - if (index !== -1) { - createDebug.instances.splice(index, 1); - return true; - } - return false; - } - function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); newDebug.log = this.log; @@ -26657,11 +26680,6 @@ function setup(env) { createDebug.names.push(new RegExp('^' + namespaces + '$')); } } - - for (i = 0; i < createDebug.instances.length; i++) { - const instance = createDebug.instances[i]; - instance.enabled = createDebug.enabled(instance.namespace); - } } /** @@ -26736,6 +26754,14 @@ function setup(env) { return val; } + /** + * XXX DO NOT USE. This is a temporary stub function. + * XXX It WILL be removed in the next major release. + */ + function destroy() { + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + createDebug.enable(createDebug.load()); return createDebug; @@ -27189,7 +27215,7 @@ var grammar = module.exports = { push: 'rtcpFbTrrInt', reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, names: ['payload', 'value'], - format: 'rtcp-fb:%d trr-int %d' + format: 'rtcp-fb:%s trr-int %d' }, { // a=rtcp-fb:98 nack rpsi diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 59d4909e2..46ae09bba 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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=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);n0)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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":38}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&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.cseqthis._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=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;n2&&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:N,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:k,token_nodot:D,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:U,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:z,qdtext:J,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:Ne,headers:ke,header:De,hname:Ue,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:ze,scheme:Je,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=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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;tl&&(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 N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){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 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&&(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 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&&(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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 z(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 J(){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=ke())?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=k())))),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=k())),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=k())?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=Ne())&&null===(e=C())&&(e=E()),e}function Ne(){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 ke(){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=De())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?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=De())?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 De(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=Ue())?(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 Ue(){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=Je())?(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=ze();null!==t;)e.push(t),t=ze();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=ze();null!==t;)e.push(t),t=ze();return e}function ze(){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 Je(){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=k()),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=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),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=k())?(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=k())&&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=k())))),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=k())),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=Nt())&&(e=kt()),e}function Nt(){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=Dt()))))),e}function kt(){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=Dt())),e}function Dt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){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=k())?e=[e,t]:(e=null,i=r),e}function xt(){var e;return null===(e=Dt())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(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=D())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?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=D())?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=k())?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=k()))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=k())&&null!==(t=M())?(null===(n=k())&&(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=Jt())&&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=z())&&(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=zt())){if(l=[],f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?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=zt())?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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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=z())&&(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=z())?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=k())),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=k())),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=k()))),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=k()))))))),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=k())?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=k())&&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=k()),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=k())))),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=N())&&(t=A());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=A());return e}function Nn(){var e,t,r,s,l,u,c,h,f,d,_,p;return d=i,_=i,null!==(e=Dn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(f=Un())?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 kn(){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 Dn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function xn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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=k())?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=k())?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=Gn2&&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"),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=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);n1&&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")):t.fromUserName&&(p.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(p.from_display_name=t.fromDisplayName),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;e.body&&"application/sdp"!==s?e.reply(415):(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)?(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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,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 N=b.value;o.removeTrack(N)}}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?rC.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=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: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._localMediaStream&&this._localMediaStreamLocallyGenerated&&(R("close() | closing local MediaStream"),m.closeMediaStream(this._localMediaStream)),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._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),nv.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(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:d.causes.RTP_TIMEOUT,status_code:408,reason_phrase:d.causes.RTP_TIMEOUT})}),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()})})})}},{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;n1&&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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&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;n1&&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"')}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=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")),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;r1&&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=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){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=u.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("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}}])&&r(t.prototype,n),l&&r(t,l),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;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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":case"authorization_jwt":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);n4&&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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&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=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);n1)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(e0&&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;t1&&(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=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=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{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{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=[];++f1)for(var n=1;n1&&(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=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.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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=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=n.call(e)},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);n0)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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":38}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),a("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,a("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){a("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=u.cloneArray(n.extraHeaders),s=u.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=u.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),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=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)}}])&&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;n2&&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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:N,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:k,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:x,STAR:D,SLASH:P,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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:z,qdtext:J,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:Ne,headers:ke,header:Ue,hname:xe,hvalue:De,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:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=D()))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;tl&&(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 N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){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 x(){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 D(){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 B(){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 W(){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 V(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 z(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 J(){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=ke())?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=k())))),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=k())),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=k())?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=Ne())&&null===(e=C())&&(e=E()),e}function Ne(){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 ke(){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=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=De())?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 xe(){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 De(){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=Je())?(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=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){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 Ve(){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=ze();null!==t;)e.push(t),t=ze();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=ze();null!==t;)e.push(t),t=ze();return e}function ze(){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 Je(){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=Be();null!==t;)e.push(t),t=Be();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=k()),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=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),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=k())?(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=k())&&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=k())))),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=k())),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=Dt())){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=Nt())&&(e=kt()),e}function Nt(){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 kt(){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=k())&&(e=xt()),e}function xt(){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=k())?e=[e,t]:(e=null,i=r),e}function Dt(){var e;return null===(e=Ut())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(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=k())?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=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(u=Wt())?l=[l,u]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(u=Wt())?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=k()))if(null!==(t=A()))if(null!==(n=Bt())){for(r=[],u=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=j())&&null!==(o=Bt())?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 Bt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=Y()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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=z())&&(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=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?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=zt())?u=[u,c]:(u=null,i=f)}null!==l&&null!==(u=V())?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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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=z())&&(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=z())?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=k())),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=W())){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=V())?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=k())),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=k()))),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=k()))))))),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=k())?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=k())&&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=k()),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=k())))),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=B())&&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=N())&&(t=A());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=A());return e}function Nn(){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=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(f=xn())?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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Dn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=k())?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=k())?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),Bn=Gn2&&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})}}])&&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"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":25}],11:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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=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=n.call(e)},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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;b("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=p.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!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new A("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new A("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,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;b("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||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===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};b('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(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===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};b("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(b("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(b("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(b("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(f.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]:{};b("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(b('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new T(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(b("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};b("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};b("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(b("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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(b("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;b("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;b("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 b("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(b("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};b('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){b("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){b("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||(b("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(b("_isReadyToReOffer() | session not established yet"),!1):(b("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(b("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(b("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(b("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),b('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(b("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 b('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};b('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(b(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(b(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;b("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 b("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;b("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return b("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;b("_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!==I.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};b('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===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(b("receiveRefer()"),!e.refer_to)return b("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return b("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);b('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new a(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(b("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;b("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new a(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){b("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,b('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(b("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void b(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){b("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};b('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};b('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};b('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};b('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),R('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]:{};b("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.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};b('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),R('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)};b('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.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(f.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){b("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){b("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!==I.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){b("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){b("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!==I.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 h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(b("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){b("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){b("session connecting"),b('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){b("session progress"),b('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){b("session accepted"),this._start_time=new Date,b('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){b("session confirmed"),this._is_confirmed=!0,b('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){b("session ended"),this._end_time=new Date,this._close(),b('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){b("session failed"),b('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),b('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){b("session onhold"),this._setLocalMediaStatus(),b('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){b("session onunhold"),this._setLocalMediaStatus(),b('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;b("session onmute"),this._setLocalMediaStatus(),b('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;b("session onunmute"),this._setLocalMediaStatus(),b('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),a}()},{"./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;n1&&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")}}])&&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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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})}}])&&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=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&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;n1&&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})}}])&&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"')}var t,n,a;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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})}}])&&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;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,u)Object.prototype.hasOwnProperty.call(u,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=u[o]));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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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")),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;r1&&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=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)}}}]),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:"C",get:function(){return C}},{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()}}]),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:"C",get:function(){return C}},{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:}}}]),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:"C",get:function(){return C}},{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())}}}]),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){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=u.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),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;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./RequestSender":18,"./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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var u in this._parameters={},this._headers={},this._scheme=t||o.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 l)Object.prototype.hasOwnProperty.call(l,a)&&this.setHeader(a,l[a])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=u.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 u=i.value;e.push("".concat(s,"=").concat(u))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&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=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=n.call(e)},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);n1)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(e0&&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;t1&&(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=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=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){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":31,_process:33}],31:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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=[];++f1)for(var n=1;n1&&(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=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.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/RequestSender.js b/lib/RequestSender.js index d33f9f61b..5d0a1d8f7 100644 --- a/lib/RequestSender.js +++ b/lib/RequestSender.js @@ -13,7 +13,7 @@ const EventHandlers = { module.exports = class RequestSender { - constructor(ua, request, eventHandlers) + constructor(ua, request, eventHandlers, config2=null) { this._ua = ua; this._eventHandlers = eventHandlers; @@ -22,7 +22,8 @@ module.exports = class RequestSender this._auth = null; this._challenged = false; this._staled = false; - + this._config2 = config2; + // Define the undefined handlers. for (const handler in EventHandlers) { @@ -92,7 +93,7 @@ module.exports = class RequestSender * Authenticate once. _challenged_ flag used to avoid infinite authentications. */ if ((status_code === 401 || status_code === 407) && - (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) + (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. @@ -120,12 +121,13 @@ module.exports = class RequestSender { if (!this._auth) { - this._auth = new DigestAuthentication({ - username : this._ua.configuration.authorization_user, - password : this._ua.configuration.password, - realm : this._ua.configuration.realm, - ha1 : this._ua.configuration.ha1 - }); + let cnf = this._config2 ? this._config2 : this._ua.configuration; + this._auth = new DigestAuthentication({ + username : cnf.authorization_user, + password : cnf.password, + realm : cnf.realm, + ha1 : cnf.ha1 + }); } // Verify that the challenge is really valid. @@ -137,10 +139,17 @@ module.exports = class RequestSender } this._challenged = true; - // Update ha1 and realm in the UA. - this._ua.set('realm', this._auth.get('realm')); - this._ua.set('ha1', this._auth.get('ha1')); - + // Update ha1 and realm in the UA or in alternative config. + if( !this._config2 ) + { + this._ua.set('realm', this._auth.get('realm')); + this._ua.set('ha1', this._auth.get('ha1')); + } + else + { + this._config2.realm = this._auth.get('realm'); + this._config2.ha1 = this._auth.get('ha1'); + } if (challenge.stale) { this._staled = true; diff --git a/lib/UA.js b/lib/UA.js index 878eec645..52cb36fc9 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -10,6 +10,7 @@ const Exceptions = require('./Exceptions'); const URI = require('./URI'); const Parser = require('./Parser'); const SIPMessage = require('./SIPMessage'); +const RequestSender = require('./RequestSender'); const sanityCheck = require('./sanityCheck'); const config = require('./Config'); const debug = require('debug')('JsSIP:UA'); @@ -256,7 +257,17 @@ module.exports = class UA extends EventEmitter return message; } - + + + /* arbitrary client transaction */ + sendRequest(method, target, params, headers, body, handlers, credential) + { + debug('sendRequest()'); + const request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); + const requestSender = new RequestSender(this, request, handlers, credential); + requestSender.send(); + } + /** * Terminate ongoing sessions. */ @@ -595,6 +606,15 @@ module.exports = class UA extends EventEmitter const message = new Message(this); message.init_incoming(request); + } + // incoming subscribe + else if (method === JsSIP_C.SUBSCRIBE) + { + if (this.listeners('newSubscribe').length === 0) + { + request.reply(405); + return; + } } else if (method === JsSIP_C.INVITE) { @@ -682,6 +702,13 @@ module.exports = class UA extends EventEmitter }); request.reply(200); break; + case JsSIP_C.SUBSCRIBE: + // Igor's extension: incoming SUBSCRIBE + this.emit('newSubscribe', { + event : request.event, + request + }); + break; default: request.reply(405); break; From 66367136253cbc1733a28b139d44f0dda9d87449 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 20 May 2021 17:35:24 +0300 Subject: [PATCH 03/70] added subscriber/notifier to JsSIP --- .vscode/settings.json | 2 + dist/jssip.js | 27937 ---------------------------------------- dist/jssip.min.js | 2 +- lib/Constants.js | 2 +- lib/Notifier.js | 224 + lib/RequestSender.js | 28 +- lib/Subscriber.js | 260 + lib/UA.js | 34 +- 8 files changed, 533 insertions(+), 27956 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 dist/jssip.js create mode 100644 lib/Notifier.js create mode 100644 lib/Subscriber.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..e02aef276 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/dist/jssip.js b/dist/jssip.js deleted file mode 100644 index ef5bed700..000000000 --- a/dist/jssip.js +++ /dev/null @@ -1,27937 +0,0 @@ -/* - * JsSIP v3.7.5 - * the Javascript SIP library - * Copyright: 2012-2021 José Luis Millán (https://github.com/jmillan) - * Homepage: https://jssip.net - * License: MIT - */ - -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var Utils = require('./Utils'); - -var JsSIP_C = require('./Constants'); - -var Grammar = require('./Grammar'); - -var URI = require('./URI'); - -var Socket = require('./Socket'); - -var Exceptions = require('./Exceptions'); // Default settings. - - -exports.settings = { - // SIP authentication. - authorization_user: null, - password: null, - realm: null, - ha1: null, - authorization_jwt: null, - // SIP account. - display_name: null, - uri: null, - contact_uri: null, - // SIP instance id (GRUU). - instance_id: null, - // Preloaded SIP Route header field. - use_preloaded_route: false, - // Session parameters. - session_timers: true, - session_timers_refresh_method: JsSIP_C.UPDATE, - session_timers_force_refresher: false, - no_answer_timeout: 60, - // Registration parameters. - register: true, - register_expires: 600, - registrar_server: null, - // Connection options. - sockets: null, - connection_recovery_max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL, - connection_recovery_min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL, - - /* - * Host address. - * Value to be set in Via sent_by and host part of Contact FQDN. - */ - via_host: "".concat(Utils.createRandomToken(12), ".invalid") -}; // Configuration checks. - -var checks = { - mandatory: { - sockets: function sockets(_sockets2) { - /* Allow defining sockets parameter as: - * Socket: socket - * Array of Socket: [socket1, socket2] - * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}] - * Array of Objects and Socket: [{socket: socket1}, socket2] - */ - var _sockets = []; - - if (Socket.isSocket(_sockets2)) { - _sockets.push({ - socket: _sockets2 - }); - } else if (Array.isArray(_sockets2) && _sockets2.length) { - var _iterator = _createForOfIteratorHelper(_sockets2), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var socket = _step.value; - - if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) { - _sockets.push(socket); - } else if (Socket.isSocket(socket)) { - _sockets.push({ - socket: socket - }); - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } else { - return; - } - - return _sockets; - }, - uri: function uri(_uri) { - if (!/^sip:/i.test(_uri)) { - _uri = "".concat(JsSIP_C.SIP, ":").concat(_uri); - } - - var parsed = URI.parse(_uri); - - if (!parsed) { - return; - } else if (!parsed.user) { - return; - } else { - return parsed; - } - } - }, - optional: { - authorization_user: function authorization_user(_authorization_user) { - if (Grammar.parse("\"".concat(_authorization_user, "\""), 'quoted_string') === -1) { - return; - } else { - return _authorization_user; - } - }, - authorization_jwt: function authorization_jwt(_authorization_jwt) { - if (typeof _authorization_jwt === 'string') { - return _authorization_jwt; - } - }, - user_agent: function user_agent(_user_agent) { - if (typeof _user_agent === 'string') { - return _user_agent; - } - }, - connection_recovery_max_interval: function connection_recovery_max_interval(_connection_recovery_max_interval) { - if (Utils.isDecimal(_connection_recovery_max_interval)) { - var value = Number(_connection_recovery_max_interval); - - if (value > 0) { - return value; - } - } - }, - connection_recovery_min_interval: function connection_recovery_min_interval(_connection_recovery_min_interval) { - if (Utils.isDecimal(_connection_recovery_min_interval)) { - var value = Number(_connection_recovery_min_interval); - - if (value > 0) { - return value; - } - } - }, - contact_uri: function contact_uri(_contact_uri) { - if (typeof _contact_uri === 'string') { - var uri = Grammar.parse(_contact_uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } - } - }, - display_name: function display_name(_display_name) { - return _display_name; - }, - instance_id: function instance_id(_instance_id) { - if (/^uuid:/i.test(_instance_id)) { - _instance_id = _instance_id.substr(5); - } - - if (Grammar.parse(_instance_id, 'uuid') === -1) { - return; - } else { - return _instance_id; - } - }, - no_answer_timeout: function no_answer_timeout(_no_answer_timeout) { - if (Utils.isDecimal(_no_answer_timeout)) { - var value = Number(_no_answer_timeout); - - if (value > 0) { - return value; - } - } - }, - session_timers: function session_timers(_session_timers) { - if (typeof _session_timers === 'boolean') { - return _session_timers; - } - }, - session_timers_refresh_method: function session_timers_refresh_method(method) { - if (typeof method === 'string') { - method = method.toUpperCase(); - - if (method === JsSIP_C.INVITE || method === JsSIP_C.UPDATE) { - return method; - } - } - }, - session_timers_force_refresher: function session_timers_force_refresher(_session_timers_force_refresher) { - if (typeof _session_timers_force_refresher === 'boolean') { - return _session_timers_force_refresher; - } - }, - password: function password(_password) { - return String(_password); - }, - realm: function realm(_realm) { - return String(_realm); - }, - ha1: function ha1(_ha) { - return String(_ha); - }, - register: function register(_register) { - if (typeof _register === 'boolean') { - return _register; - } - }, - register_expires: function register_expires(_register_expires) { - if (Utils.isDecimal(_register_expires)) { - var value = Number(_register_expires); - - if (value > 0) { - return value; - } - } - }, - registrar_server: function registrar_server(_registrar_server) { - if (!/^sip:/i.test(_registrar_server)) { - _registrar_server = "".concat(JsSIP_C.SIP, ":").concat(_registrar_server); - } - - var parsed = URI.parse(_registrar_server); - - if (!parsed) { - return; - } else if (parsed.user) { - return; - } else { - return parsed; - } - }, - use_preloaded_route: function use_preloaded_route(_use_preloaded_route) { - if (typeof _use_preloaded_route === 'boolean') { - return _use_preloaded_route; - } - } - } -}; - -exports.load = function (dst, src) { - // Check Mandatory parameters. - for (var parameter in checks.mandatory) { - if (!src.hasOwnProperty(parameter)) { - throw new Exceptions.ConfigurationError(parameter); - } else { - var value = src[parameter]; - var checked_value = checks.mandatory[parameter](value); - - if (checked_value !== undefined) { - dst[parameter] = checked_value; - } else { - throw new Exceptions.ConfigurationError(parameter, value); - } - } - } // Check Optional parameters. - - - for (var _parameter in checks.optional) { - if (src.hasOwnProperty(_parameter)) { - var _value = src[_parameter]; - /* If the parameter value is null, empty string, undefined, empty array - * or it's a number with NaN value, then apply its default value. - */ - - if (Utils.isEmpty(_value)) { - continue; - } - - var _checked_value = checks.optional[_parameter](_value); - - if (_checked_value !== undefined) { - dst[_parameter] = _checked_value; - } else { - throw new Exceptions.ConfigurationError(_parameter, _value); - } - } - } -}; -},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":20,"./URI":25,"./Utils":26}],2:[function(require,module,exports){ -"use strict"; - -var pkg = require('../package.json'); - -module.exports = { - USER_AGENT: "".concat(pkg.title, " ").concat(pkg.version), - // SIP scheme. - SIP: 'sip', - SIPS: 'sips', - // End and Failure causes. - causes: { - // Generic error causes. - CONNECTION_ERROR: 'Connection Error', - REQUEST_TIMEOUT: 'Request Timeout', - SIP_FAILURE_CODE: 'SIP Failure Code', - INTERNAL_ERROR: 'Internal Error', - // SIP error causes. - BUSY: 'Busy', - REJECTED: 'Rejected', - REDIRECTED: 'Redirected', - UNAVAILABLE: 'Unavailable', - NOT_FOUND: 'Not Found', - ADDRESS_INCOMPLETE: 'Address Incomplete', - INCOMPATIBLE_SDP: 'Incompatible SDP', - MISSING_SDP: 'Missing SDP', - AUTHENTICATION_ERROR: 'Authentication Error', - // Session error causes. - BYE: 'Terminated', - WEBRTC_ERROR: 'WebRTC Error', - CANCELED: 'Canceled', - NO_ANSWER: 'No Answer', - EXPIRES: 'Expires', - NO_ACK: 'No ACK', - DIALOG_ERROR: 'Dialog Error', - USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access', - BAD_MEDIA_DESCRIPTION: 'Bad Media Description', - RTP_TIMEOUT: 'RTP Timeout' - }, - SIP_ERROR_CAUSES: { - REDIRECTED: [300, 301, 302, 305, 380], - BUSY: [486, 600], - REJECTED: [403, 603], - NOT_FOUND: [404, 604], - UNAVAILABLE: [480, 410, 408, 430], - ADDRESS_INCOMPLETE: [484, 424], - INCOMPATIBLE_SDP: [488, 606], - AUTHENTICATION_ERROR: [401, 407] - }, - // SIP Methods. - 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 methods. - DTMF_TRANSPORT: { - INFO: 'INFO', - RFC2833: 'RFC2833' - }, - - /* SIP Response Reasons - * DOC: https://www.iana.org/assignments/sip-parameters - * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7 - */ - REASON_PHRASE: { - 100: 'Trying', - 180: 'Ringing', - 181: 'Call Is Being Forwarded', - 182: 'Queued', - 183: 'Session Progress', - 199: 'Early Dialog Terminated', - // draft-ietf-sipcore-199 - 200: 'OK', - 202: 'Accepted', - // RFC 3265 - 204: 'No Notification', - // RFC 5839 - 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', - // RFC 3903 - 413: 'Request Entity Too Large', - 414: 'Request-URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Unsupported URI Scheme', - 417: 'Unknown Resource-Priority', - // RFC 4412 - 420: 'Bad Extension', - 421: 'Extension Required', - 422: 'Session Interval Too Small', - // RFC 4028 - 423: 'Interval Too Brief', - 424: 'Bad Location Information', - // RFC 6442 - 428: 'Use Identity Header', - // RFC 4474 - 429: 'Provide Referrer Identity', - // RFC 3892 - 430: 'Flow Failed', - // RFC 5626 - 433: 'Anonymity Disallowed', - // RFC 5079 - 436: 'Bad Identity-Info', - // RFC 4474 - 437: 'Unsupported Certificate', - // RFC 4744 - 438: 'Invalid Identity Header', - // RFC 4744 - 439: 'First Hop Lacks Outbound Support', - // RFC 5626 - 440: 'Max-Breadth Exceeded', - // RFC 5393 - 469: 'Bad Info Package', - // draft-ietf-sipcore-info-events - 470: 'Consent Needed', - // RFC 5360 - 478: 'Unresolvable Destination', - // Custom code copied from Kamailio. - 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', - // RFC 3265 - 491: 'Request Pending', - 493: 'Undecipherable', - 494: 'Security Agreement Required', - // RFC 3329 - 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', - // RFC 3312 - 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(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var SIPMessage = require('./SIPMessage'); - -var JsSIP_C = require('./Constants'); - -var Transactions = require('./Transactions'); - -var Dialog_RequestSender = require('./Dialog/RequestSender'); - -var Utils = require('./Utils'); - -var debug = require('debug')('JsSIP:Dialog'); - -var C = { - // Dialog states. - STATUS_EARLY: 1, - STATUS_CONFIRMED: 2 -}; // RFC 3261 12.1. - -module.exports = /*#__PURE__*/function () { - function Dialog(owner, message, type) { - var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; - - _classCallCheck(this, Dialog); - - this._owner = owner; - this._ua = owner._ua; - this._uac_pending_reply = false; - this._uas_pending_reply = false; - - if (!message.hasHeader('contact')) { - return { - error: 'unable to create a Dialog without Contact header field' - }; - } - - if (message instanceof SIPMessage.IncomingResponse) { - state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED; - } - - var contact = message.parseHeader('contact'); // RFC 3261 12.1.1. - - if (type === 'UAS') { - this._id = { - call_id: message.call_id, - local_tag: message.to_tag, - remote_tag: message.from_tag, - toString: function toString() { - return this.call_id + this.local_tag + this.remote_tag; - } - }; - this._state = state; - this._remote_seqnum = message.cseq; - this._local_uri = message.parseHeader('to').uri; - this._remote_uri = message.parseHeader('from').uri; - this._remote_target = contact.uri; - this._route_set = message.getHeaders('record-route'); - this._ack_seqnum = this._remote_seqnum; - } // RFC 3261 12.1.2. - else if (type === 'UAC') { - this._id = { - call_id: message.call_id, - local_tag: message.from_tag, - remote_tag: message.to_tag, - toString: function toString() { - return this.call_id + this.local_tag + this.remote_tag; - } - }; - this._state = state; - this._local_seqnum = message.cseq; - this._local_uri = message.parseHeader('from').uri; - this._remote_uri = message.parseHeader('to').uri; - this._remote_target = contact.uri; - this._route_set = message.getHeaders('record-route').reverse(); - this._ack_seqnum = null; - } - - this._ua.newDialog(this); - - debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); - } - - _createClass(Dialog, [{ - key: "id", - get: function get() { - return this._id; - } - }, { - key: "local_seqnum", - get: function get() { - return this._local_seqnum; - }, - set: function set(num) { - this._local_seqnum = num; - } - }, { - key: "owner", - get: function get() { - return this._owner; - } - }, { - key: "uac_pending_reply", - get: function get() { - return this._uac_pending_reply; - }, - set: function set(pending) { - this._uac_pending_reply = pending; - } - }, { - key: "uas_pending_reply", - get: function get() { - return this._uas_pending_reply; - } - }, { - key: "update", - value: function update(message, type) { - this._state = C.STATUS_CONFIRMED; - debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); - - if (type === 'UAC') { - // RFC 3261 13.2.2.4. - this._route_set = message.getHeaders('record-route').reverse(); - } - } - }, { - key: "terminate", - value: function terminate() { - debug("dialog ".concat(this._id.toString(), " deleted")); - - this._ua.destroyDialog(this); - } - }, { - key: "sendRequest", - value: function sendRequest(method) { - var _this = this; - - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var body = options.body || null; - - var request = this._createRequest(method, extraHeaders, body); // Increase the local CSeq on authentication. - - - eventHandlers.onAuthenticated = function () { - _this._local_seqnum += 1; - }; - - var request_sender = new Dialog_RequestSender(this, request, eventHandlers); - request_sender.send(); // Return the instance of OutgoingRequest. - - return request; - } - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - // Check in-dialog request. - if (!this._checkInDialogRequest(request)) { - return; - } // ACK received. Cleanup this._ack_seqnum. - - - if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) { - this._ack_seqnum = null; - } // INVITE received. Set this._ack_seqnum. - else if (request.method === JsSIP_C.INVITE) { - this._ack_seqnum = request.cseq; - } - - this._owner.receiveRequest(request); - } // RFC 3261 12.2.1.1. - - }, { - key: "_createRequest", - value: function _createRequest(method, extraHeaders, body) { - extraHeaders = Utils.cloneArray(extraHeaders); - - if (!this._local_seqnum) { - this._local_seqnum = Math.floor(Math.random() * 10000); - } - - var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1; - var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, { - 'cseq': cseq, - '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 - }, extraHeaders, body); - return request; - } // RFC 3261 12.2.2. - - }, { - key: "_checkInDialogRequest", - value: function _checkInDialogRequest(request) { - var _this2 = this; - - if (!this._remote_seqnum) { - this._remote_seqnum = request.cseq; - } else if (request.cseq < this._remote_seqnum) { - if (request.method === JsSIP_C.ACK) { - // We are not expecting any ACK with lower seqnum than the current one. - // Or this is not the ACK we are waiting for. - if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) { - return false; - } - } else { - request.reply(500); - return false; - } - } else if (request.cseq > this._remote_seqnum) { - this._remote_seqnum = request.cseq; - } // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-. - - - if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) { - if (this._uac_pending_reply === true) { - request.reply(491); - } else if (this._uas_pending_reply === true) { - var retryAfter = (Math.random() * 10 | 0) + 1; - request.reply(500, null, ["Retry-After:".concat(retryAfter)]); - return false; - } else { - this._uas_pending_reply = true; - - var stateChanged = function stateChanged() { - if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED || request.server_transaction.state === Transactions.C.STATUS_COMPLETED || request.server_transaction.state === Transactions.C.STATUS_TERMINATED) { - request.server_transaction.removeListener('stateChanged', stateChanged); - _this2._uas_pending_reply = false; - } - }; - - request.server_transaction.on('stateChanged', stateChanged); - } // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted. - - - if (request.hasHeader('contact')) { - request.server_transaction.on('stateChanged', function () { - if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED) { - _this2._remote_target = request.parseHeader('contact').uri; - } - }); - } - } else if (request.method === JsSIP_C.NOTIFY) { - // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted. - if (request.hasHeader('contact')) { - request.server_transaction.on('stateChanged', function () { - if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) { - _this2._remote_target = request.parseHeader('contact').uri; - } - }); - } - } - - return true; - } - }], [{ - key: "C", - get: // Expose C object. - function get() { - return C; - } - }]); - - return Dialog; -}(); -},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":19,"./Transactions":22,"./Utils":26,"debug":30}],4:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var JsSIP_C = require('../Constants'); - -var Transactions = require('../Transactions'); - -var RTCSession = require('../RTCSession'); - -var RequestSender = require('../RequestSender'); // Default event handlers. - - -var EventHandlers = { - onRequestTimeout: function onRequestTimeout() {}, - onTransportError: function onTransportError() {}, - onSuccessResponse: function onSuccessResponse() {}, - onErrorResponse: function onErrorResponse() {}, - onAuthenticated: function onAuthenticated() {}, - onDialogError: function onDialogError() {} -}; - -module.exports = /*#__PURE__*/function () { - function DialogRequestSender(dialog, request, eventHandlers) { - _classCallCheck(this, DialogRequestSender); - - this._dialog = dialog; - this._ua = dialog._ua; - this._request = request; - this._eventHandlers = eventHandlers; // RFC3261 14.1 Modifying an Existing Session. UAC Behavior. - - this._reattempt = false; - this._reattemptTimer = null; // Define the undefined handlers. - - for (var handler in EventHandlers) { - if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { - if (!this._eventHandlers[handler]) { - this._eventHandlers[handler] = EventHandlers[handler]; - } - } - } - } - - _createClass(DialogRequestSender, [{ - key: "request", - get: function get() { - return this._request; - } - }, { - key: "send", - value: function send() { - var _this = this; - - var request_sender = new RequestSender(this._ua, this._request, { - onRequestTimeout: function onRequestTimeout() { - _this._eventHandlers.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this._eventHandlers.onTransportError(); - }, - onAuthenticated: function onAuthenticated(request) { - _this._eventHandlers.onAuthenticated(request); - }, - onReceiveResponse: function onReceiveResponse(response) { - _this._receiveResponse(response); - } - }); - request_sender.send(); // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-. - - if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) { - this._dialog.uac_pending_reply = true; - - var stateChanged = function stateChanged() { - if (request_sender.clientTransaction.state === Transactions.C.STATUS_ACCEPTED || request_sender.clientTransaction.state === Transactions.C.STATUS_COMPLETED || request_sender.clientTransaction.state === Transactions.C.STATUS_TERMINATED) { - request_sender.clientTransaction.removeListener('stateChanged', stateChanged); - _this._dialog.uac_pending_reply = false; - } - }; - - request_sender.clientTransaction.on('stateChanged', stateChanged); - } - } - }, { - key: "_receiveResponse", - value: function _receiveResponse(response) { - var _this2 = this; - - // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog. - if (response.status_code === 408 || response.status_code === 481) { - this._eventHandlers.onDialogError(response); - } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) { - if (this._reattempt) { - if (response.status_code >= 200 && response.status_code < 300) { - this._eventHandlers.onSuccessResponse(response); - } else if (response.status_code >= 300) { - this._eventHandlers.onErrorResponse(response); - } - } else { - this._request.cseq = this._dialog.local_seqnum += 1; - this._reattemptTimer = setTimeout(function () { - // TODO: look at dialog state instead. - if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) { - _this2._reattempt = true; - - _this2._request_sender.send(); - } - }, 1000); - } - } else if (response.status_code >= 200 && response.status_code < 300) { - this._eventHandlers.onSuccessResponse(response); - } else if (response.status_code >= 300) { - this._eventHandlers.onErrorResponse(response); - } - } - }]); - - return DialogRequestSender; -}(); -},{"../Constants":2,"../RTCSession":12,"../RequestSender":18,"../Transactions":22}],5:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Utils = require('./Utils'); - -var debug = require('debug')('JsSIP:DigestAuthentication'); - -var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); - -debugerror.log = console.warn.bind(console); - -module.exports = /*#__PURE__*/function () { - function DigestAuthentication(credentials) { - _classCallCheck(this, DigestAuthentication); - - this._credentials = credentials; - 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; - } - - _createClass(DigestAuthentication, [{ - key: "get", - value: function get(parameter) { - switch (parameter) { - case 'realm': - return this._realm; - - case 'ha1': - return this._ha1; - - default: - debugerror('get() | cannot get "%s" parameter', parameter); - return undefined; - } - } - /** - * Performs Digest authentication given a SIP request and the challenge - * received in a response to that request. - * Returns true if auth was successfully generated, false otherwise. - */ - - }, { - key: "authenticate", - value: function authenticate(_ref, challenge) - /* test interface */ - { - var method = _ref.method, - ruri = _ref.ruri, - body = _ref.body; - var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - this._algorithm = challenge.algorithm; - this._realm = challenge.realm; - this._nonce = challenge.nonce; - this._opaque = challenge.opaque; - this._stale = challenge.stale; - - if (this._algorithm) { - if (this._algorithm !== 'MD5') { - debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); - return false; - } - } else { - this._algorithm = 'MD5'; - } - - if (!this._nonce) { - debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); - return false; - } - - if (!this._realm) { - debugerror('authenticate() | challenge without Digest realm, authentication aborted'); - return false; - } // If no plain SIP password is provided. - - - if (!this._credentials.password) { - // If ha1 is not provided we cannot authenticate. - if (!this._credentials.ha1) { - debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); - return false; - } // If the realm does not match the stored realm we cannot authenticate. - - - if (this._credentials.realm !== this._realm) { - debugerror('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); - return false; - } - } // 'qop' can contain a list of values (Array). Let's choose just one. - - - if (challenge.qop) { - if (challenge.qop.indexOf('auth-int') > -1) { - this._qop = 'auth-int'; - } else if (challenge.qop.indexOf('auth') > -1) { - this._qop = 'auth'; - } else { - // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. - debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); - return false; - } - } else { - this._qop = null; - } // Fill other attributes. - - - this._method = method; - this._uri = ruri; - this._cnonce = cnonce || Utils.createRandomToken(12); - this._nc += 1; - var hex = Number(this._nc).toString(16); - this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex; // Nc-value = 8LHEX. Max value = 'FFFFFFFF'. - - if (this._nc === 4294967296) { - this._nc = 1; - this._ncHex = '00000001'; - } // Calculate the Digest "response" value. - // If we have plain SIP password then regenerate ha1. - - - if (this._credentials.password) { - // HA1 = MD5(A1) = MD5(username:realm:password). - this._ha1 = Utils.calculateMD5("".concat(this._credentials.username, ":").concat(this._realm, ":").concat(this._credentials.password)); - } // Otherwise reuse the stored ha1. - else { - this._ha1 = this._credentials.ha1; - } - - var a2; - var ha2; - - if (this._qop === 'auth') { - // HA2 = MD5(A2) = MD5(method:digestURI). - a2 = "".concat(this._method, ":").concat(this._uri); - ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). - - this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2)); - } else if (this._qop === 'auth-int') { - // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)). - a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : '')); - ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). - - this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2)); - } else if (this._qop === null) { - // HA2 = MD5(A2) = MD5(method:digestURI). - a2 = "".concat(this._method, ":").concat(this._uri); - ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). - - this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2)); - } - - debug('authenticate() | response generated'); - return true; - } - /** - * Return the Proxy-Authorization or WWW-Authorization header value. - */ - - }, { - key: "toString", - value: function toString() { - var auth_params = []; - - if (!this._response) { - throw new Error('response field does not exist, cannot generate Authorization header'); - } - - auth_params.push("algorithm=".concat(this._algorithm)); - auth_params.push("username=\"".concat(this._credentials.username, "\"")); - auth_params.push("realm=\"".concat(this._realm, "\"")); - auth_params.push("nonce=\"".concat(this._nonce, "\"")); - auth_params.push("uri=\"".concat(this._uri, "\"")); - auth_params.push("response=\"".concat(this._response, "\"")); - - if (this._opaque) { - auth_params.push("opaque=\"".concat(this._opaque, "\"")); - } - - if (this._qop) { - auth_params.push("qop=".concat(this._qop)); - auth_params.push("cnonce=\"".concat(this._cnonce, "\"")); - auth_params.push("nc=".concat(this._ncHex)); - } - - return "Digest ".concat(auth_params.join(', ')); - } - }]); - - return DigestAuthentication; -}(); -},{"./Utils":26,"debug":30}],6:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } - -function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var ConfigurationError = /*#__PURE__*/function (_Error) { - _inherits(ConfigurationError, _Error); - - var _super = _createSuper(ConfigurationError); - - function ConfigurationError(parameter, value) { - var _this; - - _classCallCheck(this, ConfigurationError); - - _this = _super.call(this); - _this.code = 1; - _this.name = 'CONFIGURATION_ERROR'; - _this.parameter = parameter; - _this.value = value; - _this.message = !_this.value ? "Missing parameter: ".concat(_this.parameter) : "Invalid value ".concat(JSON.stringify(_this.value), " for parameter \"").concat(_this.parameter, "\""); - return _this; - } - - return ConfigurationError; -}( /*#__PURE__*/_wrapNativeSuper(Error)); - -var InvalidStateError = /*#__PURE__*/function (_Error2) { - _inherits(InvalidStateError, _Error2); - - var _super2 = _createSuper(InvalidStateError); - - function InvalidStateError(status) { - var _this2; - - _classCallCheck(this, InvalidStateError); - - _this2 = _super2.call(this); - _this2.code = 2; - _this2.name = 'INVALID_STATE_ERROR'; - _this2.status = status; - _this2.message = "Invalid status: ".concat(status); - return _this2; - } - - return InvalidStateError; -}( /*#__PURE__*/_wrapNativeSuper(Error)); - -var NotSupportedError = /*#__PURE__*/function (_Error3) { - _inherits(NotSupportedError, _Error3); - - var _super3 = _createSuper(NotSupportedError); - - function NotSupportedError(message) { - var _this3; - - _classCallCheck(this, NotSupportedError); - - _this3 = _super3.call(this); - _this3.code = 3; - _this3.name = 'NOT_SUPPORTED_ERROR'; - _this3.message = message; - return _this3; - } - - return NotSupportedError; -}( /*#__PURE__*/_wrapNativeSuper(Error)); - -var NotReadyError = /*#__PURE__*/function (_Error4) { - _inherits(NotReadyError, _Error4); - - var _super4 = _createSuper(NotReadyError); - - function NotReadyError(message) { - var _this4; - - _classCallCheck(this, NotReadyError); - - _this4 = _super4.call(this); - _this4.code = 4; - _this4.name = 'NOT_READY_ERROR'; - _this4.message = message; - return _this4; - } - - return NotReadyError; -}( /*#__PURE__*/_wrapNativeSuper(Error)); - -module.exports = { - ConfigurationError: ConfigurationError, - InvalidStateError: InvalidStateError, - NotSupportedError: NotSupportedError, - NotReadyError: NotReadyError -}; -},{}],7:[function(require,module,exports){ -"use strict"; - -module.exports = function () { - /* - * Generated by PEG.js 0.7.0. - * - * http://pegjs.majda.cz/ - */ - function quote(s) { - /* - * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a - * string literal except for the closing quote character, backslash, - * carriage return, line separator, paragraph separator, and line feed. - * Any character may appear in the form of an escape sequence. - * - * For portability, we also escape escape all control and non-ASCII - * characters. Note that "\0" and "\v" escape sequences are not used - * because JSHint does not like the first and IE the second. - */ - return '"' + s.replace(/\\/g, '\\\\') // backslash - .replace(/"/g, '\\"') // closing quote character - .replace(/\x08/g, '\\b') // backspace - .replace(/\t/g, '\\t') // horizontal tab - .replace(/\n/g, '\\n') // line feed - .replace(/\f/g, '\\f') // form feed - .replace(/\r/g, '\\r') // carriage return - .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"'; - } - - var result = { - /* - * Parses the input with a generated parser. If the parsing is successfull, - * returns a value explicitly or implicitly specified by the grammar from - * which the parser was generated (see |PEG.buildParser|). If the parsing is - * unsuccessful, throws |PEG.parser.SyntaxError| describing the error. - */ - parse: function parse(input, startRule) { - var parseFunctions = { - "CRLF": parse_CRLF, - "DIGIT": parse_DIGIT, - "ALPHA": parse_ALPHA, - "HEXDIG": parse_HEXDIG, - "WSP": parse_WSP, - "OCTET": parse_OCTET, - "DQUOTE": parse_DQUOTE, - "SP": parse_SP, - "HTAB": parse_HTAB, - "alphanum": parse_alphanum, - "reserved": parse_reserved, - "unreserved": parse_unreserved, - "mark": parse_mark, - "escaped": parse_escaped, - "LWS": parse_LWS, - "SWS": parse_SWS, - "HCOLON": parse_HCOLON, - "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM, - "TEXT_UTF8char": parse_TEXT_UTF8char, - "UTF8_NONASCII": parse_UTF8_NONASCII, - "UTF8_CONT": parse_UTF8_CONT, - "LHEX": parse_LHEX, - "token": parse_token, - "token_nodot": parse_token_nodot, - "separators": parse_separators, - "word": parse_word, - "STAR": parse_STAR, - "SLASH": parse_SLASH, - "EQUAL": parse_EQUAL, - "LPAREN": parse_LPAREN, - "RPAREN": parse_RPAREN, - "RAQUOT": parse_RAQUOT, - "LAQUOT": parse_LAQUOT, - "COMMA": parse_COMMA, - "SEMI": parse_SEMI, - "COLON": parse_COLON, - "LDQUOT": parse_LDQUOT, - "RDQUOT": parse_RDQUOT, - "comment": parse_comment, - "ctext": parse_ctext, - "quoted_string": parse_quoted_string, - "quoted_string_clean": parse_quoted_string_clean, - "qdtext": parse_qdtext, - "quoted_pair": parse_quoted_pair, - "SIP_URI_noparams": parse_SIP_URI_noparams, - "SIP_URI": parse_SIP_URI, - "uri_scheme": parse_uri_scheme, - "uri_scheme_sips": parse_uri_scheme_sips, - "uri_scheme_sip": parse_uri_scheme_sip, - "userinfo": parse_userinfo, - "user": parse_user, - "user_unreserved": parse_user_unreserved, - "password": parse_password, - "hostport": parse_hostport, - "host": parse_host, - "hostname": parse_hostname, - "domainlabel": parse_domainlabel, - "toplabel": parse_toplabel, - "IPv6reference": parse_IPv6reference, - "IPv6address": parse_IPv6address, - "h16": parse_h16, - "ls32": parse_ls32, - "IPv4address": parse_IPv4address, - "dec_octet": parse_dec_octet, - "port": parse_port, - "uri_parameters": parse_uri_parameters, - "uri_parameter": parse_uri_parameter, - "transport_param": parse_transport_param, - "user_param": parse_user_param, - "method_param": parse_method_param, - "ttl_param": parse_ttl_param, - "maddr_param": parse_maddr_param, - "lr_param": parse_lr_param, - "other_param": parse_other_param, - "pname": parse_pname, - "pvalue": parse_pvalue, - "paramchar": parse_paramchar, - "param_unreserved": parse_param_unreserved, - "headers": parse_headers, - "header": parse_header, - "hname": parse_hname, - "hvalue": parse_hvalue, - "hnv_unreserved": parse_hnv_unreserved, - "Request_Response": parse_Request_Response, - "Request_Line": parse_Request_Line, - "Request_URI": parse_Request_URI, - "absoluteURI": parse_absoluteURI, - "hier_part": parse_hier_part, - "net_path": parse_net_path, - "abs_path": parse_abs_path, - "opaque_part": parse_opaque_part, - "uric": parse_uric, - "uric_no_slash": parse_uric_no_slash, - "path_segments": parse_path_segments, - "segment": parse_segment, - "param": parse_param, - "pchar": parse_pchar, - "scheme": parse_scheme, - "authority": parse_authority, - "srvr": parse_srvr, - "reg_name": parse_reg_name, - "query": parse_query, - "SIP_Version": parse_SIP_Version, - "INVITEm": parse_INVITEm, - "ACKm": parse_ACKm, - "OPTIONSm": parse_OPTIONSm, - "BYEm": parse_BYEm, - "CANCELm": parse_CANCELm, - "REGISTERm": parse_REGISTERm, - "SUBSCRIBEm": parse_SUBSCRIBEm, - "NOTIFYm": parse_NOTIFYm, - "REFERm": parse_REFERm, - "Method": parse_Method, - "Status_Line": parse_Status_Line, - "Status_Code": parse_Status_Code, - "extension_code": parse_extension_code, - "Reason_Phrase": parse_Reason_Phrase, - "Allow_Events": parse_Allow_Events, - "Call_ID": parse_Call_ID, - "Contact": parse_Contact, - "contact_param": parse_contact_param, - "name_addr": parse_name_addr, - "display_name": parse_display_name, - "contact_params": parse_contact_params, - "c_p_q": parse_c_p_q, - "c_p_expires": parse_c_p_expires, - "delta_seconds": parse_delta_seconds, - "qvalue": parse_qvalue, - "generic_param": parse_generic_param, - "gen_value": parse_gen_value, - "Content_Disposition": parse_Content_Disposition, - "disp_type": parse_disp_type, - "disp_param": parse_disp_param, - "handling_param": parse_handling_param, - "Content_Encoding": parse_Content_Encoding, - "Content_Length": parse_Content_Length, - "Content_Type": parse_Content_Type, - "media_type": parse_media_type, - "m_type": parse_m_type, - "discrete_type": parse_discrete_type, - "composite_type": parse_composite_type, - "extension_token": parse_extension_token, - "x_token": parse_x_token, - "m_subtype": parse_m_subtype, - "m_parameter": parse_m_parameter, - "m_value": parse_m_value, - "CSeq": parse_CSeq, - "CSeq_value": parse_CSeq_value, - "Expires": parse_Expires, - "Event": parse_Event, - "event_type": parse_event_type, - "From": parse_From, - "from_param": parse_from_param, - "tag_param": parse_tag_param, - "Max_Forwards": parse_Max_Forwards, - "Min_Expires": parse_Min_Expires, - "Name_Addr_Header": parse_Name_Addr_Header, - "Proxy_Authenticate": parse_Proxy_Authenticate, - "challenge": parse_challenge, - "other_challenge": parse_other_challenge, - "auth_param": parse_auth_param, - "digest_cln": parse_digest_cln, - "realm": parse_realm, - "realm_value": parse_realm_value, - "domain": parse_domain, - "URI": parse_URI, - "nonce": parse_nonce, - "nonce_value": parse_nonce_value, - "opaque": parse_opaque, - "stale": parse_stale, - "algorithm": parse_algorithm, - "qop_options": parse_qop_options, - "qop_value": parse_qop_value, - "Proxy_Require": parse_Proxy_Require, - "Record_Route": parse_Record_Route, - "rec_route": parse_rec_route, - "Reason": parse_Reason, - "reason_param": parse_reason_param, - "reason_cause": parse_reason_cause, - "Require": parse_Require, - "Route": parse_Route, - "route_param": parse_route_param, - "Subscription_State": parse_Subscription_State, - "substate_value": parse_substate_value, - "subexp_params": parse_subexp_params, - "event_reason_value": parse_event_reason_value, - "Subject": parse_Subject, - "Supported": parse_Supported, - "To": parse_To, - "to_param": parse_to_param, - "Via": parse_Via, - "via_param": parse_via_param, - "via_params": parse_via_params, - "via_ttl": parse_via_ttl, - "via_maddr": parse_via_maddr, - "via_received": parse_via_received, - "via_branch": parse_via_branch, - "response_port": parse_response_port, - "rport": parse_rport, - "sent_protocol": parse_sent_protocol, - "protocol_name": parse_protocol_name, - "transport": parse_transport, - "sent_by": parse_sent_by, - "via_host": parse_via_host, - "via_port": parse_via_port, - "ttl": parse_ttl, - "WWW_Authenticate": parse_WWW_Authenticate, - "Session_Expires": parse_Session_Expires, - "s_e_expires": parse_s_e_expires, - "s_e_params": parse_s_e_params, - "s_e_refresher": parse_s_e_refresher, - "extension_header": parse_extension_header, - "header_value": parse_header_value, - "message_body": parse_message_body, - "uuid_URI": parse_uuid_URI, - "uuid": parse_uuid, - "hex4": parse_hex4, - "hex8": parse_hex8, - "hex12": parse_hex12, - "Refer_To": parse_Refer_To, - "Replaces": parse_Replaces, - "call_id": parse_call_id, - "replaces_param": parse_replaces_param, - "to_tag": parse_to_tag, - "from_tag": parse_from_tag, - "early_flag": parse_early_flag - }; - - if (startRule !== undefined) { - if (parseFunctions[startRule] === undefined) { - throw new Error("Invalid rule name: " + quote(startRule) + "."); - } - } else { - startRule = "CRLF"; - } - - var pos = 0; - var reportFailures = 0; - var rightmostFailuresPos = 0; - var rightmostFailuresExpected = []; - - function padLeft(input, padding, length) { - var result = input; - var padLength = length - input.length; - - for (var i = 0; i < padLength; i++) { - result = padding + result; - } - - return result; - } - - function escape(ch) { - var charCode = ch.charCodeAt(0); - var escapeChar; - var length; - - if (charCode <= 0xFF) { - escapeChar = 'x'; - length = 2; - } else { - escapeChar = 'u'; - length = 4; - } - - return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); - } - - function matchFailed(failure) { - if (pos < rightmostFailuresPos) { - return; - } - - if (pos > rightmostFailuresPos) { - rightmostFailuresPos = pos; - rightmostFailuresExpected = []; - } - - rightmostFailuresExpected.push(failure); - } - - function parse_CRLF() { - var result0; - - if (input.substr(pos, 2) === "\r\n") { - result0 = "\r\n"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"\\r\\n\""); - } - } - - return result0; - } - - function parse_DIGIT() { - var result0; - - if (/^[0-9]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[0-9]"); - } - } - - return result0; - } - - function parse_ALPHA() { - var result0; - - if (/^[a-zA-Z]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[a-zA-Z]"); - } - } - - return result0; - } - - function parse_HEXDIG() { - var result0; - - if (/^[0-9a-fA-F]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[0-9a-fA-F]"); - } - } - - return result0; - } - - function parse_WSP() { - var result0; - result0 = parse_SP(); - - if (result0 === null) { - result0 = parse_HTAB(); - } - - return result0; - } - - function parse_OCTET() { - var result0; - - if (/^[\0-\xFF]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\0-\\xFF]"); - } - } - - return result0; - } - - function parse_DQUOTE() { - var result0; - - if (/^["]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\"]"); - } - } - - return result0; - } - - function parse_SP() { - var result0; - - if (input.charCodeAt(pos) === 32) { - result0 = " "; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\" \""); - } - } - - return result0; - } - - function parse_HTAB() { - var result0; - - if (input.charCodeAt(pos) === 9) { - result0 = "\t"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"\\t\""); - } - } - - return result0; - } - - function parse_alphanum() { - var result0; - - if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[a-zA-Z0-9]"); - } - } - - return result0; - } - - function parse_reserved() { - var result0; - - if (input.charCodeAt(pos) === 59) { - result0 = ";"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 64) { - result0 = "@"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_unreserved() { - var result0; - result0 = parse_alphanum(); - - if (result0 === null) { - result0 = parse_mark(); - } - - return result0; - } - - function parse_mark() { - var result0; - - if (input.charCodeAt(pos) === 45) { - result0 = "-"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 95) { - result0 = "_"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 46) { - result0 = "."; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 33) { - result0 = "!"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 126) { - result0 = "~"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 42) { - result0 = "*"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 39) { - result0 = "'"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 40) { - result0 = "("; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 41) { - result0 = ")"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_escaped() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.charCodeAt(pos) === 37) { - result0 = "%"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result0 !== null) { - result1 = parse_HEXDIG(); - - if (result1 !== null) { - result2 = parse_HEXDIG(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, escaped) { - return escaped.join(''); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_LWS() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - pos2 = pos; - result0 = []; - result1 = parse_WSP(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_WSP(); - } - - if (result0 !== null) { - result1 = parse_CRLF(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos2; - } - } else { - result0 = null; - pos = pos2; - } - - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result2 = parse_WSP(); - - if (result2 !== null) { - result1 = []; - - while (result2 !== null) { - result1.push(result2); - result2 = parse_WSP(); - } - } else { - result1 = null; - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return " "; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_SWS() { - var result0; - result0 = parse_LWS(); - result0 = result0 !== null ? result0 : ""; - return result0; - } - - function parse_HCOLON() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = []; - result1 = parse_SP(); - - if (result1 === null) { - result1 = parse_HTAB(); - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_SP(); - - if (result1 === null) { - result1 = parse_HTAB(); - } - } - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ':'; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_TEXT_UTF8_TRIM() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result1 = parse_TEXT_UTF8char(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_TEXT_UTF8char(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = []; - result3 = parse_LWS(); - - while (result3 !== null) { - result2.push(result3); - result3 = parse_LWS(); - } - - if (result2 !== null) { - result3 = parse_TEXT_UTF8char(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = []; - result3 = parse_LWS(); - - while (result3 !== null) { - result2.push(result3); - result3 = parse_LWS(); - } - - if (result2 !== null) { - result3 = parse_TEXT_UTF8char(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_TEXT_UTF8char() { - var result0; - - if (/^[!-~]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[!-~]"); - } - } - - if (result0 === null) { - result0 = parse_UTF8_NONASCII(); - } - - return result0; - } - - function parse_UTF8_NONASCII() { - var result0; - - if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\x80-\\uFFFF]"); - } - } - - return result0; - } - - function parse_UTF8_CONT() { - var result0; - - if (/^[\x80-\xBF]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\x80-\\xBF]"); - } - } - - return result0; - } - - function parse_LHEX() { - var result0; - result0 = parse_DIGIT(); - - if (result0 === null) { - if (/^[a-f]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[a-f]"); - } - } - } - - return result0; - } - - function parse_token() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - } - } - } - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - } - } - } - } - } - } - } - } - } - } - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_token_nodot() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - } - } - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - } - } - } - } - } - } - } - } - } - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_separators() { - var result0; - - if (input.charCodeAt(pos) === 40) { - result0 = "("; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 41) { - result0 = ")"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 60) { - result0 = "<"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"<\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 62) { - result0 = ">"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\">\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 64) { - result0 = "@"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 59) { - result0 = ";"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 92) { - result0 = "\\"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"\\\\\""); - } - } - - if (result0 === null) { - result0 = parse_DQUOTE(); - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 91) { - result0 = "["; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 93) { - result0 = "]"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 123) { - result0 = "{"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"{\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 125) { - result0 = "}"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"}\""); - } - } - - if (result0 === null) { - result0 = parse_SP(); - - if (result0 === null) { - result0 = parse_HTAB(); - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_word() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 40) { - result1 = "("; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 41) { - result1 = ")"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 60) { - result1 = "<"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"<\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 62) { - result1 = ">"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\">\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 92) { - result1 = "\\"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"\\\\\""); - } - } - - if (result1 === null) { - result1 = parse_DQUOTE(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 47) { - result1 = "/"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 91) { - result1 = "["; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 93) { - result1 = "]"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 63) { - result1 = "?"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 123) { - result1 = "{"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"{\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 125) { - result1 = "}"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"}\""); - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 40) { - result1 = "("; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 41) { - result1 = ")"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 60) { - result1 = "<"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"<\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 62) { - result1 = ">"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\">\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 92) { - result1 = "\\"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"\\\\\""); - } - } - - if (result1 === null) { - result1 = parse_DQUOTE(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 47) { - result1 = "/"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 91) { - result1 = "["; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 93) { - result1 = "]"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 63) { - result1 = "?"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 123) { - result1 = "{"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"{\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 125) { - result1 = "}"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"}\""); - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_STAR() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "*"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_SLASH() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 47) { - result1 = "/"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "/"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_EQUAL() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "="; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_LPAREN() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 40) { - result1 = "("; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "("; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_RPAREN() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 41) { - result1 = ")"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ")"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_RAQUOT() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.charCodeAt(pos) === 62) { - result0 = ">"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\">\""); - } - } - - if (result0 !== null) { - result1 = parse_SWS(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ">"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_LAQUOT() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 60) { - result1 = "<"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"<\""); - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "<"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_COMMA() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ","; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_SEMI() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ";"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_COLON() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ":"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_LDQUOT() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - result1 = parse_DQUOTE(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "\""; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_RDQUOT() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DQUOTE(); - - if (result0 !== null) { - result1 = parse_SWS(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "\""; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_comment() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_LPAREN(); - - if (result0 !== null) { - result1 = []; - result2 = parse_ctext(); - - if (result2 === null) { - result2 = parse_quoted_pair(); - - if (result2 === null) { - result2 = parse_comment(); - } - } - - while (result2 !== null) { - result1.push(result2); - result2 = parse_ctext(); - - if (result2 === null) { - result2 = parse_quoted_pair(); - - if (result2 === null) { - result2 = parse_comment(); - } - } - } - - if (result1 !== null) { - result2 = parse_RPAREN(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_ctext() { - var result0; - - if (/^[!-']/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[!-']"); - } - } - - if (result0 === null) { - if (/^[*-[]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[*-[]"); - } - } - - if (result0 === null) { - if (/^[\]-~]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\]-~]"); - } - } - - if (result0 === null) { - result0 = parse_UTF8_NONASCII(); - - if (result0 === null) { - result0 = parse_LWS(); - } - } - } - } - - return result0; - } - - function parse_quoted_string() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - result1 = parse_DQUOTE(); - - if (result1 !== null) { - result2 = []; - result3 = parse_qdtext(); - - if (result3 === null) { - result3 = parse_quoted_pair(); - } - - while (result3 !== null) { - result2.push(result3); - result3 = parse_qdtext(); - - if (result3 === null) { - result3 = parse_quoted_pair(); - } - } - - if (result2 !== null) { - result3 = parse_DQUOTE(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_quoted_string_clean() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - result1 = parse_DQUOTE(); - - if (result1 !== null) { - result2 = []; - result3 = parse_qdtext(); - - if (result3 === null) { - result3 = parse_quoted_pair(); - } - - while (result3 !== null) { - result2.push(result3); - result3 = parse_qdtext(); - - if (result3 === null) { - result3 = parse_quoted_pair(); - } - } - - if (result2 !== null) { - result3 = parse_DQUOTE(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var trimmed = input.substring(pos, offset).trim(); - return trimmed.substring(1, trimmed.length - 1) // remove outer quotes - .replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g, '$1'); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_qdtext() { - var result0; - result0 = parse_LWS(); - - if (result0 === null) { - if (input.charCodeAt(pos) === 33) { - result0 = "!"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result0 === null) { - if (/^[#-[]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[#-[]"); - } - } - - if (result0 === null) { - if (/^[\]-~]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\]-~]"); - } - } - - if (result0 === null) { - result0 = parse_UTF8_NONASCII(); - } - } - } - } - - return result0; - } - - function parse_quoted_pair() { - var result0, result1; - var pos0; - pos0 = pos; - - if (input.charCodeAt(pos) === 92) { - result0 = "\\"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"\\\\\""); - } - } - - if (result0 !== null) { - if (/^[\0-\t]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[\\0-\\t]"); - } - } - - if (result1 === null) { - if (/^[\x0B-\f]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[\\x0B-\\f]"); - } - } - - if (result1 === null) { - if (/^[\x0E-]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[\\x0E-]"); - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_SIP_URI_noparams() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_uri_scheme(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_userinfo(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_hostport(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - try { - data.uri = new URI(data.scheme, data.user, data.host, data.port); - delete data.scheme; - delete data.user; - delete data.host; - delete data.host_type; - delete data.port; - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_SIP_URI() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_uri_scheme(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_userinfo(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_hostport(); - - if (result3 !== null) { - result4 = parse_uri_parameters(); - - if (result4 !== null) { - result5 = parse_headers(); - result5 = result5 !== null ? result5 : ""; - - if (result5 !== null) { - result0 = [result0, result1, result2, result3, result4, result5]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var header; - - try { - data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers); - delete data.scheme; - delete data.user; - delete data.host; - delete data.host_type; - delete data.port; - delete data.uri_params; - - if (startRule === 'SIP_URI') { - data = data.uri; - } - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_uri_scheme() { - var result0; - result0 = parse_uri_scheme_sips(); - - if (result0 === null) { - result0 = parse_uri_scheme_sip(); - } - - return result0; - } - - function parse_uri_scheme_sips() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 4).toLowerCase() === "sips") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"sips\""); - } - } - - if (result0 !== null) { - result0 = function (offset, scheme) { - data.scheme = scheme.toLowerCase(); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_uri_scheme_sip() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 3).toLowerCase() === "sip") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"sip\""); - } - } - - if (result0 !== null) { - result0 = function (offset, scheme) { - data.scheme = scheme.toLowerCase(); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_userinfo() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_user(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_password(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - if (input.charCodeAt(pos) === 64) { - result2 = "@"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.user = decodeURIComponent(input.substring(pos - 1, offset)); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_user() { - var result0, result1; - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - result1 = parse_user_unreserved(); - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - result1 = parse_user_unreserved(); - } - } - } - } else { - result0 = null; - } - - return result0; - } - - function parse_user_unreserved() { - var result0; - - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 59) { - result0 = ";"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_password() { - var result0, result1; - var pos0; - pos0 = pos; - result0 = []; - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 38) { - result1 = "&"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 36) { - result1 = "$"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 38) { - result1 = "&"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 36) { - result1 = "$"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.password = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_hostport() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - result0 = parse_host(); - - if (result0 !== null) { - pos1 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_port(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos1; - } - } else { - result1 = null; - pos = pos1; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_host() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_hostname(); - - if (result0 === null) { - result0 = parse_IPv4address(); - - if (result0 === null) { - result0 = parse_IPv6reference(); - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.host = input.substring(pos, offset).toLowerCase(); - return data.host; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_hostname() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = []; - pos2 = pos; - result1 = parse_domainlabel(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - while (result1 !== null) { - result0.push(result1); - pos2 = pos; - result1 = parse_domainlabel(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - } - - if (result0 !== null) { - result1 = parse_toplabel(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.host_type = 'domain'; - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_domainlabel() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_alphanum(); - - if (result0 !== null) { - result1 = []; - result2 = parse_alphanum(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - } - } - - while (result2 !== null) { - result1.push(result2); - result2 = parse_alphanum(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_toplabel() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_ALPHA(); - - if (result0 !== null) { - result1 = []; - result2 = parse_alphanum(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - } - } - - while (result2 !== null) { - result1.push(result2); - result2 = parse_alphanum(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_IPv6reference() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.charCodeAt(pos) === 91) { - result0 = "["; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result0 !== null) { - result1 = parse_IPv6address(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 93) { - result2 = "]"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.host_type = 'IPv6'; - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_IPv6address() { - var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - if (input.charCodeAt(pos) === 58) { - result7 = ":"; - pos++; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result7 !== null) { - result8 = parse_h16(); - - if (result8 !== null) { - if (input.charCodeAt(pos) === 58) { - result9 = ":"; - pos++; - } else { - result9 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result9 !== null) { - result10 = parse_h16(); - - if (result10 !== null) { - if (input.charCodeAt(pos) === 58) { - result11 = ":"; - pos++; - } else { - result11 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result11 !== null) { - result12 = parse_ls32(); - - if (result12 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - if (input.charCodeAt(pos) === 58) { - result8 = ":"; - pos++; - } else { - result8 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result8 !== null) { - result9 = parse_h16(); - - if (result9 !== null) { - if (input.charCodeAt(pos) === 58) { - result10 = ":"; - pos++; - } else { - result10 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result10 !== null) { - result11 = parse_ls32(); - - if (result11 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - if (input.charCodeAt(pos) === 58) { - result8 = ":"; - pos++; - } else { - result8 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result8 !== null) { - result9 = parse_ls32(); - - if (result9 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_ls32(); - - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_ls32(); - - if (result5 !== null) { - result0 = [result0, result1, result2, result3, result4, result5]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_ls32(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_ls32(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - if (input.substr(pos, 2) === "::") { - result1 = "::"; - pos += 2; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - if (input.charCodeAt(pos) === 58) { - result7 = ":"; - pos++; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result7 !== null) { - result8 = parse_h16(); - - if (result8 !== null) { - if (input.charCodeAt(pos) === 58) { - result9 = ":"; - pos++; - } else { - result9 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result9 !== null) { - result10 = parse_ls32(); - - if (result10 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - if (input.substr(pos, 2) === "::") { - result2 = "::"; - pos += 2; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - if (input.charCodeAt(pos) === 58) { - result8 = ":"; - pos++; - } else { - result8 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result8 !== null) { - result9 = parse_ls32(); - - if (result9 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - if (input.substr(pos, 2) === "::") { - result3 = "::"; - pos += 2; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - if (input.charCodeAt(pos) === 58) { - result7 = ":"; - pos++; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result7 !== null) { - result8 = parse_ls32(); - - if (result8 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } - - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - if (input.substr(pos, 2) === "::") { - result4 = "::"; - pos += 2; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_ls32(); - - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } - - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos2; - } - } else { - result4 = null; - pos = pos2; - } - - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - if (input.substr(pos, 2) === "::") { - result5 = "::"; - pos += 2; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result5 !== null) { - result6 = parse_ls32(); - - if (result6 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } - - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos2; - } - } else { - result4 = null; - pos = pos2; - } - - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - - result5 = result5 !== null ? result5 : ""; - - if (result5 !== null) { - if (input.substr(pos, 2) === "::") { - result6 = "::"; - pos += 2; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } - - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos2; - } - } else { - result4 = null; - pos = pos2; - } - - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - - result5 = result5 !== null ? result5 : ""; - - if (result5 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - result6 = [result6, result7]; - } else { - result6 = null; - pos = pos2; - } - } else { - result6 = null; - pos = pos2; - } - - result6 = result6 !== null ? result6 : ""; - - if (result6 !== null) { - if (input.substr(pos, 2) === "::") { - result7 = "::"; - pos += 2; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.host_type = 'IPv6'; - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_h16() { - var result0, result1, result2, result3; - var pos0; - pos0 = pos; - result0 = parse_HEXDIG(); - - if (result0 !== null) { - result1 = parse_HEXDIG(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_HEXDIG(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_HEXDIG(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_ls32() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - result0 = parse_IPv4address(); - } - - return result0; - } - - function parse_IPv4address() { - var result0, result1, result2, result3, result4, result5, result6; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_dec_octet(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 !== null) { - result2 = parse_dec_octet(); - - if (result2 !== null) { - if (input.charCodeAt(pos) === 46) { - result3 = "."; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result3 !== null) { - result4 = parse_dec_octet(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 46) { - result5 = "."; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result5 !== null) { - result6 = parse_dec_octet(); - - if (result6 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.host_type = 'IPv4'; - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_dec_octet() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 2) === "25") { - result0 = "25"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"25\""); - } - } - - if (result0 !== null) { - if (/^[0-5]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[0-5]"); - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - - if (input.charCodeAt(pos) === 50) { - result0 = "2"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"2\""); - } - } - - if (result0 !== null) { - if (/^[0-4]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[0-4]"); - } - } - - if (result1 !== null) { - result2 = parse_DIGIT(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - - if (input.charCodeAt(pos) === 49) { - result0 = "1"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"1\""); - } - } - - if (result0 !== null) { - result1 = parse_DIGIT(); - - if (result1 !== null) { - result2 = parse_DIGIT(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - - if (/^[1-9]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[1-9]"); - } - } - - if (result0 !== null) { - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - result0 = parse_DIGIT(); - } - } - } - } - - return result0; - } - - function parse_port() { - var result0, result1, result2, result3, result4; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DIGIT(); - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_DIGIT(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_DIGIT(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result4 = parse_DIGIT(); - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, port) { - port = parseInt(port.join('')); - data.port = port; - return port; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_uri_parameters() { - var result0, result1, result2; - var pos0; - result0 = []; - pos0 = pos; - - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 !== null) { - result2 = parse_uri_parameter(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos0; - } - } else { - result1 = null; - pos = pos0; - } - - while (result1 !== null) { - result0.push(result1); - pos0 = pos; - - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 !== null) { - result2 = parse_uri_parameter(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos0; - } - } else { - result1 = null; - pos = pos0; - } - } - - return result0; - } - - function parse_uri_parameter() { - var result0; - result0 = parse_transport_param(); - - if (result0 === null) { - result0 = parse_user_param(); - - if (result0 === null) { - result0 = parse_method_param(); - - if (result0 === null) { - result0 = parse_ttl_param(); - - if (result0 === null) { - result0 = parse_maddr_param(); - - if (result0 === null) { - result0 = parse_lr_param(); - - if (result0 === null) { - result0 = parse_other_param(); - } - } - } - } - } - } - - return result0; - } - - function parse_transport_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 10).toLowerCase() === "transport=") { - result0 = input.substr(pos, 10); - pos += 10; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"transport=\""); - } - } - - if (result0 !== null) { - if (input.substr(pos, 3).toLowerCase() === "udp") { - result1 = input.substr(pos, 3); - pos += 3; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"udp\""); - } - } - - if (result1 === null) { - if (input.substr(pos, 3).toLowerCase() === "tcp") { - result1 = input.substr(pos, 3); - pos += 3; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"tcp\""); - } - } - - if (result1 === null) { - if (input.substr(pos, 4).toLowerCase() === "sctp") { - result1 = input.substr(pos, 4); - pos += 4; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"sctp\""); - } - } - - if (result1 === null) { - if (input.substr(pos, 3).toLowerCase() === "tls") { - result1 = input.substr(pos, 3); - pos += 3; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"tls\""); - } - } - - if (result1 === null) { - result1 = parse_token(); - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, transport) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['transport'] = transport.toLowerCase(); - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_user_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 5).toLowerCase() === "user=") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"user=\""); - } - } - - if (result0 !== null) { - if (input.substr(pos, 5).toLowerCase() === "phone") { - result1 = input.substr(pos, 5); - pos += 5; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"phone\""); - } - } - - if (result1 === null) { - if (input.substr(pos, 2).toLowerCase() === "ip") { - result1 = input.substr(pos, 2); - pos += 2; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"ip\""); - } - } - - if (result1 === null) { - result1 = parse_token(); - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, user) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['user'] = user.toLowerCase(); - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_method_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 7).toLowerCase() === "method=") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"method=\""); - } - } - - if (result0 !== null) { - result1 = parse_Method(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, method) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['method'] = method; - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_ttl_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 4).toLowerCase() === "ttl=") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"ttl=\""); - } - } - - if (result0 !== null) { - result1 = parse_ttl(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, ttl) { - if (!data.params) data.params = {}; - data.params['ttl'] = ttl; - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_maddr_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6).toLowerCase() === "maddr=") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"maddr=\""); - } - } - - if (result0 !== null) { - result1 = parse_host(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, maddr) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['maddr'] = maddr; - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_lr_param() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 2).toLowerCase() === "lr") { - result0 = input.substr(pos, 2); - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"lr\""); - } - } - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['lr'] = undefined; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_other_param() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_pname(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 !== null) { - result2 = parse_pvalue(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, param, value) { - if (!data.uri_params) data.uri_params = {}; - - if (typeof value === 'undefined') { - value = undefined; - } else { - value = value[1]; - } - - data.uri_params[param.toLowerCase()] = value; - }(pos0, result0[0], result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_pname() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_paramchar(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_paramchar(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, pname) { - return pname.join(''); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_pvalue() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_paramchar(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_paramchar(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, pvalue) { - return pvalue.join(''); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_paramchar() { - var result0; - result0 = parse_param_unreserved(); - - if (result0 === null) { - result0 = parse_unreserved(); - - if (result0 === null) { - result0 = parse_escaped(); - } - } - - return result0; - } - - function parse_param_unreserved() { - var result0; - - if (input.charCodeAt(pos) === 91) { - result0 = "["; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 93) { - result0 = "]"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_headers() { - var result0, result1, result2, result3, result4; - var pos0, pos1; - pos0 = pos; - - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 !== null) { - result1 = parse_header(); - - if (result1 !== null) { - result2 = []; - pos1 = pos; - - if (input.charCodeAt(pos) === 38) { - result3 = "&"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result3 !== null) { - result4 = parse_header(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos1; - } - } else { - result3 = null; - pos = pos1; - } - - while (result3 !== null) { - result2.push(result3); - pos1 = pos; - - if (input.charCodeAt(pos) === 38) { - result3 = "&"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result3 !== null) { - result4 = parse_header(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos1; - } - } else { - result3 = null; - pos = pos1; - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_header() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_hname(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 !== null) { - result2 = parse_hvalue(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, hname, hvalue) { - hname = hname.join('').toLowerCase(); - hvalue = hvalue.join(''); - if (!data.uri_headers) data.uri_headers = {}; - - if (!data.uri_headers[hname]) { - data.uri_headers[hname] = [hvalue]; - } else { - data.uri_headers[hname].push(hvalue); - } - }(pos0, result0[0], result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_hname() { - var result0, result1; - result1 = parse_hnv_unreserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_hnv_unreserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - } - } - } - } else { - result0 = null; - } - - return result0; - } - - function parse_hvalue() { - var result0, result1; - result0 = []; - result1 = parse_hnv_unreserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - } - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_hnv_unreserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - } - } - } - - return result0; - } - - function parse_hnv_unreserved() { - var result0; - - if (input.charCodeAt(pos) === 91) { - result0 = "["; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 93) { - result0 = "]"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_Request_Response() { - var result0; - result0 = parse_Status_Line(); - - if (result0 === null) { - result0 = parse_Request_Line(); - } - - return result0; - } - - function parse_Request_Line() { - var result0, result1, result2, result3, result4; - var pos0; - pos0 = pos; - result0 = parse_Method(); - - if (result0 !== null) { - result1 = parse_SP(); - - if (result1 !== null) { - result2 = parse_Request_URI(); - - if (result2 !== null) { - result3 = parse_SP(); - - if (result3 !== null) { - result4 = parse_SIP_Version(); - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Request_URI() { - var result0; - result0 = parse_SIP_URI(); - - if (result0 === null) { - result0 = parse_absoluteURI(); - } - - return result0; - } - - function parse_absoluteURI() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_scheme(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_hier_part(); - - if (result2 === null) { - result2 = parse_opaque_part(); - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_hier_part() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - result0 = parse_net_path(); - - if (result0 === null) { - result0 = parse_abs_path(); - } - - if (result0 !== null) { - pos1 = pos; - - if (input.charCodeAt(pos) === 63) { - result1 = "?"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result1 !== null) { - result2 = parse_query(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos1; - } - } else { - result1 = null; - pos = pos1; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_net_path() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 2) === "//") { - result0 = "//"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"//\""); - } - } - - if (result0 !== null) { - result1 = parse_authority(); - - if (result1 !== null) { - result2 = parse_abs_path(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_abs_path() { - var result0, result1; - var pos0; - pos0 = pos; - - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 !== null) { - result1 = parse_path_segments(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_opaque_part() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_uric_no_slash(); - - if (result0 !== null) { - result1 = []; - result2 = parse_uric(); - - while (result2 !== null) { - result1.push(result2); - result2 = parse_uric(); - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_uric() { - var result0; - result0 = parse_reserved(); - - if (result0 === null) { - result0 = parse_unreserved(); - - if (result0 === null) { - result0 = parse_escaped(); - } - } - - return result0; - } - - function parse_uric_no_slash() { - var result0; - result0 = parse_unreserved(); - - if (result0 === null) { - result0 = parse_escaped(); - - if (result0 === null) { - if (input.charCodeAt(pos) === 59) { - result0 = ";"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 64) { - result0 = "@"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_path_segments() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_segment(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - - if (input.charCodeAt(pos) === 47) { - result2 = "/"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result2 !== null) { - result3 = parse_segment(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - - if (input.charCodeAt(pos) === 47) { - result2 = "/"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result2 !== null) { - result3 = parse_segment(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_segment() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = []; - result1 = parse_pchar(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_pchar(); - } - - if (result0 !== null) { - result1 = []; - pos1 = pos; - - if (input.charCodeAt(pos) === 59) { - result2 = ";"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result2 !== null) { - result3 = parse_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - - if (input.charCodeAt(pos) === 59) { - result2 = ";"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result2 !== null) { - result3 = parse_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_param() { - var result0, result1; - result0 = []; - result1 = parse_pchar(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_pchar(); - } - - return result0; - } - - function parse_pchar() { - var result0; - result0 = parse_unreserved(); - - if (result0 === null) { - result0 = parse_escaped(); - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 64) { - result0 = "@"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_scheme() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_ALPHA(); - - if (result0 !== null) { - result1 = []; - result2 = parse_ALPHA(); - - if (result2 === null) { - result2 = parse_DIGIT(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 43) { - result2 = "+"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - } - } - } - } - - while (result2 !== null) { - result1.push(result2); - result2 = parse_ALPHA(); - - if (result2 === null) { - result2 = parse_DIGIT(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 43) { - result2 = "+"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.scheme = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_authority() { - var result0; - result0 = parse_srvr(); - - if (result0 === null) { - result0 = parse_reg_name(); - } - - return result0; - } - - function parse_srvr() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_userinfo(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_hostport(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - result0 = result0 !== null ? result0 : ""; - return result0; - } - - function parse_reg_name() { - var result0, result1; - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 36) { - result1 = "$"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 38) { - result1 = "&"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - } - } - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 36) { - result1 = "$"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 38) { - result1 = "&"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - } - } - } - } - } - } - } - } - } - } - } else { - result0 = null; - } - - return result0; - } - - function parse_query() { - var result0, result1; - result0 = []; - result1 = parse_uric(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_uric(); - } - - return result0; - } - - function parse_SIP_Version() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 3).toLowerCase() === "sip") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SIP\""); - } - } - - if (result0 !== null) { - if (input.charCodeAt(pos) === 47) { - result1 = "/"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result1 !== null) { - result3 = parse_DIGIT(); - - if (result3 !== null) { - result2 = []; - - while (result3 !== null) { - result2.push(result3); - result3 = parse_DIGIT(); - } - } else { - result2 = null; - } - - if (result2 !== null) { - if (input.charCodeAt(pos) === 46) { - result3 = "."; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result3 !== null) { - result5 = parse_DIGIT(); - - if (result5 !== null) { - result4 = []; - - while (result5 !== null) { - result4.push(result5); - result5 = parse_DIGIT(); - } - } else { - result4 = null; - } - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.sip_version = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_INVITEm() { - var result0; - - if (input.substr(pos, 6) === "INVITE") { - result0 = "INVITE"; - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"INVITE\""); - } - } - - return result0; - } - - function parse_ACKm() { - var result0; - - if (input.substr(pos, 3) === "ACK") { - result0 = "ACK"; - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"ACK\""); - } - } - - return result0; - } - - function parse_OPTIONSm() { - var result0; - - if (input.substr(pos, 7) === "OPTIONS") { - result0 = "OPTIONS"; - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"OPTIONS\""); - } - } - - return result0; - } - - function parse_BYEm() { - var result0; - - if (input.substr(pos, 3) === "BYE") { - result0 = "BYE"; - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"BYE\""); - } - } - - return result0; - } - - function parse_CANCELm() { - var result0; - - if (input.substr(pos, 6) === "CANCEL") { - result0 = "CANCEL"; - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"CANCEL\""); - } - } - - return result0; - } - - function parse_REGISTERm() { - var result0; - - if (input.substr(pos, 8) === "REGISTER") { - result0 = "REGISTER"; - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"REGISTER\""); - } - } - - return result0; - } - - function parse_SUBSCRIBEm() { - var result0; - - if (input.substr(pos, 9) === "SUBSCRIBE") { - result0 = "SUBSCRIBE"; - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SUBSCRIBE\""); - } - } - - return result0; - } - - function parse_NOTIFYm() { - var result0; - - if (input.substr(pos, 6) === "NOTIFY") { - result0 = "NOTIFY"; - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"NOTIFY\""); - } - } - - return result0; - } - - function parse_REFERm() { - var result0; - - if (input.substr(pos, 5) === "REFER") { - result0 = "REFER"; - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"REFER\""); - } - } - - return result0; - } - - function parse_Method() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_INVITEm(); - - if (result0 === null) { - result0 = parse_ACKm(); - - if (result0 === null) { - result0 = parse_OPTIONSm(); - - if (result0 === null) { - result0 = parse_BYEm(); - - if (result0 === null) { - result0 = parse_CANCELm(); - - if (result0 === null) { - result0 = parse_REGISTERm(); - - if (result0 === null) { - result0 = parse_SUBSCRIBEm(); - - if (result0 === null) { - result0 = parse_NOTIFYm(); - - if (result0 === null) { - result0 = parse_REFERm(); - - if (result0 === null) { - result0 = parse_token(); - } - } - } - } - } - } - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.method = input.substring(pos, offset); - return data.method; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Status_Line() { - var result0, result1, result2, result3, result4; - var pos0; - pos0 = pos; - result0 = parse_SIP_Version(); - - if (result0 !== null) { - result1 = parse_SP(); - - if (result1 !== null) { - result2 = parse_Status_Code(); - - if (result2 !== null) { - result3 = parse_SP(); - - if (result3 !== null) { - result4 = parse_Reason_Phrase(); - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Status_Code() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_extension_code(); - - if (result0 !== null) { - result0 = function (offset, status_code) { - data.status_code = parseInt(status_code.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_extension_code() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_DIGIT(); - - if (result0 !== null) { - result1 = parse_DIGIT(); - - if (result1 !== null) { - result2 = parse_DIGIT(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Reason_Phrase() { - var result0, result1; - var pos0; - pos0 = pos; - result0 = []; - result1 = parse_reserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - result1 = parse_UTF8_NONASCII(); - - if (result1 === null) { - result1 = parse_UTF8_CONT(); - - if (result1 === null) { - result1 = parse_SP(); - - if (result1 === null) { - result1 = parse_HTAB(); - } - } - } - } - } - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_reserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - result1 = parse_UTF8_NONASCII(); - - if (result1 === null) { - result1 = parse_UTF8_CONT(); - - if (result1 === null) { - result1 = parse_SP(); - - if (result1 === null) { - result1 = parse_HTAB(); - } - } - } - } - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.reason_phrase = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Allow_Events() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_event_type(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_event_type(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_event_type(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Call_ID() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_word(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 !== null) { - result2 = parse_word(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Contact() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - result0 = parse_STAR(); - - if (result0 === null) { - pos1 = pos; - result0 = parse_contact_param(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_contact_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_contact_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } - - if (result0 !== null) { - result0 = function (offset) { - var idx, length; - length = data.multi_header.length; - - for (idx = 0; idx < length; idx++) { - if (data.multi_header[idx].parsed === null) { - data = null; - break; - } - } - - if (data !== null) { - data = data.multi_header; - } else { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_contact_param() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_SIP_URI_noparams(); - - if (result0 === null) { - result0 = parse_name_addr(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_contact_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_contact_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var header; - if (!data.multi_header) data.multi_header = []; - - try { - header = new NameAddrHeader(data.uri, data.display_name, data.params); - delete data.uri; - delete data.display_name; - delete data.params; - } catch (e) { - header = null; - } - - data.multi_header.push({ - 'possition': pos, - 'offset': offset, - 'parsed': header - }); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_name_addr() { - var result0, result1, result2, result3; - var pos0; - pos0 = pos; - result0 = parse_display_name(); - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_LAQUOT(); - - if (result1 !== null) { - result2 = parse_SIP_URI(); - - if (result2 !== null) { - result3 = parse_RAQUOT(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_display_name() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_LWS(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_LWS(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - result0 = parse_quoted_string_clean(); - } - - if (result0 !== null) { - result0 = function (offset, display_name) { - if (typeof display_name === 'string') { - // quoted_string_clean - data.display_name = display_name; - } else { - // token ( LWS token )* - data.display_name = display_name[1].reduce(function (acc, cur) { - return acc + cur[0] + cur[1]; - }, display_name[0]); - } - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_contact_params() { - var result0; - result0 = parse_c_p_q(); - - if (result0 === null) { - result0 = parse_c_p_expires(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - } - - return result0; - } - - function parse_c_p_q() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 1).toLowerCase() === "q") { - result0 = input.substr(pos, 1); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"q\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_qvalue(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, q) { - if (!data.params) data.params = {}; - data.params['q'] = q; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_c_p_expires() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 7).toLowerCase() === "expires") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"expires\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_delta_seconds(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, expires) { - if (!data.params) data.params = {}; - data.params['expires'] = expires; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_delta_seconds() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_DIGIT(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, delta_seconds) { - return parseInt(delta_seconds.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_qvalue() { - var result0, result1, result2, result3, result4; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - - if (input.charCodeAt(pos) === 48) { - result0 = "0"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"0\""); - } - } - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_DIGIT(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result4 = parse_DIGIT(); - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - result1 = [result1, result2, result3, result4]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return parseFloat(input.substring(pos, offset)); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_generic_param() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_token(); - - if (result0 !== null) { - pos2 = pos; - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_gen_value(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, param, value) { - if (!data.params) data.params = {}; - - if (typeof value === 'undefined') { - value = undefined; - } else { - value = value[1]; - } - - data.params[param.toLowerCase()] = value; - }(pos0, result0[0], result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_gen_value() { - var result0; - result0 = parse_token(); - - if (result0 === null) { - result0 = parse_host(); - - if (result0 === null) { - result0 = parse_quoted_string(); - } - } - - return result0; - } - - function parse_Content_Disposition() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_disp_type(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_disp_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_disp_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_disp_type() { - var result0; - - if (input.substr(pos, 6).toLowerCase() === "render") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"render\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 7).toLowerCase() === "session") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"session\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 4).toLowerCase() === "icon") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"icon\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 5).toLowerCase() === "alert") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"alert\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - } - } - - return result0; - } - - function parse_disp_param() { - var result0; - result0 = parse_handling_param(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_handling_param() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 8).toLowerCase() === "handling") { - result0 = input.substr(pos, 8); - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"handling\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - if (input.substr(pos, 8).toLowerCase() === "optional") { - result2 = input.substr(pos, 8); - pos += 8; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"optional\""); - } - } - - if (result2 === null) { - if (input.substr(pos, 8).toLowerCase() === "required") { - result2 = input.substr(pos, 8); - pos += 8; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"required\""); - } - } - - if (result2 === null) { - result2 = parse_token(); - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Content_Encoding() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Content_Length() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_DIGIT(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, length) { - data = parseInt(length.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Content_Type() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_media_type(); - - if (result0 !== null) { - result0 = function (offset) { - data = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_media_type() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - result0 = parse_m_type(); - - if (result0 !== null) { - result1 = parse_SLASH(); - - if (result1 !== null) { - result2 = parse_m_subtype(); - - if (result2 !== null) { - result3 = []; - pos1 = pos; - result4 = parse_SEMI(); - - if (result4 !== null) { - result5 = parse_m_parameter(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - - while (result4 !== null) { - result3.push(result4); - pos1 = pos; - result4 = parse_SEMI(); - - if (result4 !== null) { - result5 = parse_m_parameter(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - } - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_m_type() { - var result0; - result0 = parse_discrete_type(); - - if (result0 === null) { - result0 = parse_composite_type(); - } - - return result0; - } - - function parse_discrete_type() { - var result0; - - if (input.substr(pos, 4).toLowerCase() === "text") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"text\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 5).toLowerCase() === "image") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"image\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 5).toLowerCase() === "audio") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"audio\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 5).toLowerCase() === "video") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"video\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 11).toLowerCase() === "application") { - result0 = input.substr(pos, 11); - pos += 11; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"application\""); - } - } - - if (result0 === null) { - result0 = parse_extension_token(); - } - } - } - } - } - - return result0; - } - - function parse_composite_type() { - var result0; - - if (input.substr(pos, 7).toLowerCase() === "message") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"message\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 9).toLowerCase() === "multipart") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"multipart\""); - } - } - - if (result0 === null) { - result0 = parse_extension_token(); - } - } - - return result0; - } - - function parse_extension_token() { - var result0; - result0 = parse_token(); - - if (result0 === null) { - result0 = parse_x_token(); - } - - return result0; - } - - function parse_x_token() { - var result0, result1; - var pos0; - pos0 = pos; - - if (input.substr(pos, 2).toLowerCase() === "x-") { - result0 = input.substr(pos, 2); - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"x-\""); - } - } - - if (result0 !== null) { - result1 = parse_token(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_m_subtype() { - var result0; - result0 = parse_extension_token(); - - if (result0 === null) { - result0 = parse_token(); - } - - return result0; - } - - function parse_m_parameter() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_m_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_m_value() { - var result0; - result0 = parse_token(); - - if (result0 === null) { - result0 = parse_quoted_string(); - } - - return result0; - } - - function parse_CSeq() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_CSeq_value(); - - if (result0 !== null) { - result1 = parse_LWS(); - - if (result1 !== null) { - result2 = parse_Method(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_CSeq_value() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_DIGIT(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, cseq_value) { - data.value = parseInt(cseq_value.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Expires() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_delta_seconds(); - - if (result0 !== null) { - result0 = function (offset, expires) { - data = expires; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Event() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_event_type(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, event_type) { - data.event = event_type.join('').toLowerCase(); - }(pos0, result0[0]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_event_type() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token_nodot(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result2 !== null) { - result3 = parse_token_nodot(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result2 !== null) { - result3 = parse_token_nodot(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_From() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_SIP_URI_noparams(); - - if (result0 === null) { - result0 = parse_name_addr(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_from_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_from_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var tag = data.tag; - - try { - data = new NameAddrHeader(data.uri, data.display_name, data.params); - - if (tag) { - data.setParam('tag', tag); - } - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_from_param() { - var result0; - result0 = parse_tag_param(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_tag_param() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 3).toLowerCase() === "tag") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"tag\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, tag) { - data.tag = tag; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Max_Forwards() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_DIGIT(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, forwards) { - data = parseInt(forwards.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Min_Expires() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_delta_seconds(); - - if (result0 !== null) { - result0 = function (offset, min_expires) { - data = min_expires; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Name_Addr_Header() { - var result0, result1, result2, result3, result4, result5, result6; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = []; - result1 = parse_display_name(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_display_name(); - } - - if (result0 !== null) { - result1 = parse_LAQUOT(); - - if (result1 !== null) { - result2 = parse_SIP_URI(); - - if (result2 !== null) { - result3 = parse_RAQUOT(); - - if (result3 !== null) { - result4 = []; - pos2 = pos; - result5 = parse_SEMI(); - - if (result5 !== null) { - result6 = parse_generic_param(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - - while (result5 !== null) { - result4.push(result5); - pos2 = pos; - result5 = parse_SEMI(); - - if (result5 !== null) { - result6 = parse_generic_param(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - } - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - try { - data = new NameAddrHeader(data.uri, data.display_name, data.params); - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Proxy_Authenticate() { - var result0; - result0 = parse_challenge(); - return result0; - } - - function parse_challenge() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - - if (input.substr(pos, 6).toLowerCase() === "digest") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"Digest\""); - } - } - - if (result0 !== null) { - result1 = parse_LWS(); - - if (result1 !== null) { - result2 = parse_digest_cln(); - - if (result2 !== null) { - result3 = []; - pos1 = pos; - result4 = parse_COMMA(); - - if (result4 !== null) { - result5 = parse_digest_cln(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - - while (result4 !== null) { - result3.push(result4); - pos1 = pos; - result4 = parse_COMMA(); - - if (result4 !== null) { - result5 = parse_digest_cln(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - } - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - result0 = parse_other_challenge(); - } - - return result0; - } - - function parse_other_challenge() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = parse_LWS(); - - if (result1 !== null) { - result2 = parse_auth_param(); - - if (result2 !== null) { - result3 = []; - pos1 = pos; - result4 = parse_COMMA(); - - if (result4 !== null) { - result5 = parse_auth_param(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - - while (result4 !== null) { - result3.push(result4); - pos1 = pos; - result4 = parse_COMMA(); - - if (result4 !== null) { - result5 = parse_auth_param(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - } - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_auth_param() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 === null) { - result2 = parse_quoted_string(); - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_digest_cln() { - var result0; - result0 = parse_realm(); - - if (result0 === null) { - result0 = parse_domain(); - - if (result0 === null) { - result0 = parse_nonce(); - - if (result0 === null) { - result0 = parse_opaque(); - - if (result0 === null) { - result0 = parse_stale(); - - if (result0 === null) { - result0 = parse_algorithm(); - - if (result0 === null) { - result0 = parse_qop_options(); - - if (result0 === null) { - result0 = parse_auth_param(); - } - } - } - } - } - } - } - - return result0; - } - - function parse_realm() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 5).toLowerCase() === "realm") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"realm\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_realm_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_realm_value() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_quoted_string_clean(); - - if (result0 !== null) { - result0 = function (offset, realm) { - data.realm = realm; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_domain() { - var result0, result1, result2, result3, result4, result5, result6; - var pos0, pos1; - pos0 = pos; - - if (input.substr(pos, 6).toLowerCase() === "domain") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"domain\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_LDQUOT(); - - if (result2 !== null) { - result3 = parse_URI(); - - if (result3 !== null) { - result4 = []; - pos1 = pos; - result6 = parse_SP(); - - if (result6 !== null) { - result5 = []; - - while (result6 !== null) { - result5.push(result6); - result6 = parse_SP(); - } - } else { - result5 = null; - } - - if (result5 !== null) { - result6 = parse_URI(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos1; - } - } else { - result5 = null; - pos = pos1; - } - - while (result5 !== null) { - result4.push(result5); - pos1 = pos; - result6 = parse_SP(); - - if (result6 !== null) { - result5 = []; - - while (result6 !== null) { - result5.push(result6); - result6 = parse_SP(); - } - } else { - result5 = null; - } - - if (result5 !== null) { - result6 = parse_URI(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos1; - } - } else { - result5 = null; - pos = pos1; - } - } - - if (result4 !== null) { - result5 = parse_RDQUOT(); - - if (result5 !== null) { - result0 = [result0, result1, result2, result3, result4, result5]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_URI() { - var result0; - result0 = parse_absoluteURI(); - - if (result0 === null) { - result0 = parse_abs_path(); - } - - return result0; - } - - function parse_nonce() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 5).toLowerCase() === "nonce") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"nonce\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_nonce_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_nonce_value() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_quoted_string_clean(); - - if (result0 !== null) { - result0 = function (offset, nonce) { - data.nonce = nonce; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_opaque() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6).toLowerCase() === "opaque") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"opaque\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_quoted_string_clean(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, opaque) { - data.opaque = opaque; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_stale() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - - if (input.substr(pos, 5).toLowerCase() === "stale") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"stale\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - pos1 = pos; - - if (input.substr(pos, 4).toLowerCase() === "true") { - result2 = input.substr(pos, 4); - pos += 4; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"true\""); - } - } - - if (result2 !== null) { - result2 = function (offset) { - data.stale = true; - }(pos1); - } - - if (result2 === null) { - pos = pos1; - } - - if (result2 === null) { - pos1 = pos; - - if (input.substr(pos, 5).toLowerCase() === "false") { - result2 = input.substr(pos, 5); - pos += 5; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"false\""); - } - } - - if (result2 !== null) { - result2 = function (offset) { - data.stale = false; - }(pos1); - } - - if (result2 === null) { - pos = pos1; - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_algorithm() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 9).toLowerCase() === "algorithm") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"algorithm\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - if (input.substr(pos, 3).toLowerCase() === "md5") { - result2 = input.substr(pos, 3); - pos += 3; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"MD5\""); - } - } - - if (result2 === null) { - if (input.substr(pos, 8).toLowerCase() === "md5-sess") { - result2 = input.substr(pos, 8); - pos += 8; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"MD5-sess\""); - } - } - - if (result2 === null) { - result2 = parse_token(); - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, algorithm) { - data.algorithm = algorithm.toUpperCase(); - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_qop_options() { - var result0, result1, result2, result3, result4, result5, result6; - var pos0, pos1, pos2; - pos0 = pos; - - if (input.substr(pos, 3).toLowerCase() === "qop") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"qop\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_LDQUOT(); - - if (result2 !== null) { - pos1 = pos; - result3 = parse_qop_value(); - - if (result3 !== null) { - result4 = []; - pos2 = pos; - - if (input.charCodeAt(pos) === 44) { - result5 = ","; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result5 !== null) { - result6 = parse_qop_value(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - - while (result5 !== null) { - result4.push(result5); - pos2 = pos; - - if (input.charCodeAt(pos) === 44) { - result5 = ","; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result5 !== null) { - result6 = parse_qop_value(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - } - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos1; - } - } else { - result3 = null; - pos = pos1; - } - - if (result3 !== null) { - result4 = parse_RDQUOT(); - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_qop_value() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 8).toLowerCase() === "auth-int") { - result0 = input.substr(pos, 8); - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"auth-int\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 4).toLowerCase() === "auth") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"auth\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - - if (result0 !== null) { - result0 = function (offset, qop_value) { - data.qop || (data.qop = []); - data.qop.push(qop_value.toLowerCase()); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Proxy_Require() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Record_Route() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_rec_route(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_rec_route(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_rec_route(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var idx, length; - length = data.multi_header.length; - - for (idx = 0; idx < length; idx++) { - if (data.multi_header[idx].parsed === null) { - data = null; - break; - } - } - - if (data !== null) { - data = data.multi_header; - } else { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_rec_route() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_name_addr(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var header; - if (!data.multi_header) data.multi_header = []; - - try { - header = new NameAddrHeader(data.uri, data.display_name, data.params); - delete data.uri; - delete data.display_name; - delete data.params; - } catch (e) { - header = null; - } - - data.multi_header.push({ - 'possition': pos, - 'offset': offset, - 'parsed': header - }); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Reason() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 3).toLowerCase() === "sip") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SIP\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_reason_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_reason_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, protocol) { - data.protocol = protocol.toLowerCase(); - if (!data.params) data.params = {}; - - if (data.params.text && data.params.text[0] === '"') { - var text = data.params.text; - data.text = text.substring(1, text.length - 1); - delete data.params.text; - } - }(pos0, result0[0]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_reason_param() { - var result0; - result0 = parse_reason_cause(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_reason_cause() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 5).toLowerCase() === "cause") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"cause\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result3 = parse_DIGIT(); - - if (result3 !== null) { - result2 = []; - - while (result3 !== null) { - result2.push(result3); - result3 = parse_DIGIT(); - } - } else { - result2 = null; - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, cause) { - data.cause = parseInt(cause.join('')); - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Require() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Route() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_route_param(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_route_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_route_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_route_param() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_name_addr(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Subscription_State() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_substate_value(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_subexp_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_subexp_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_substate_value() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 6).toLowerCase() === "active") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"active\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 7).toLowerCase() === "pending") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"pending\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 10).toLowerCase() === "terminated") { - result0 = input.substr(pos, 10); - pos += 10; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"terminated\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.state = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_subexp_params() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6).toLowerCase() === "reason") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"reason\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_event_reason_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, reason) { - if (typeof reason !== 'undefined') data.reason = reason; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 7).toLowerCase() === "expires") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"expires\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_delta_seconds(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, expires) { - if (typeof expires !== 'undefined') data.expires = expires; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 11).toLowerCase() === "retry_after") { - result0 = input.substr(pos, 11); - pos += 11; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"retry_after\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_delta_seconds(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, retry_after) { - if (typeof retry_after !== 'undefined') data.retry_after = retry_after; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - if (result0 === null) { - result0 = parse_generic_param(); - } - } - } - - return result0; - } - - function parse_event_reason_value() { - var result0; - - if (input.substr(pos, 11).toLowerCase() === "deactivated") { - result0 = input.substr(pos, 11); - pos += 11; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"deactivated\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 9).toLowerCase() === "probation") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"probation\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 8).toLowerCase() === "rejected") { - result0 = input.substr(pos, 8); - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"rejected\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 7).toLowerCase() === "timeout") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"timeout\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 6).toLowerCase() === "giveup") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"giveup\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 10).toLowerCase() === "noresource") { - result0 = input.substr(pos, 10); - pos += 10; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"noresource\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 9).toLowerCase() === "invariant") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"invariant\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - } - } - } - } - } - - return result0; - } - - function parse_Subject() { - var result0; - result0 = parse_TEXT_UTF8_TRIM(); - result0 = result0 !== null ? result0 : ""; - return result0; - } - - function parse_Supported() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - result0 = result0 !== null ? result0 : ""; - return result0; - } - - function parse_To() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_SIP_URI_noparams(); - - if (result0 === null) { - result0 = parse_name_addr(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_to_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_to_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var tag = data.tag; - - try { - data = new NameAddrHeader(data.uri, data.display_name, data.params); - - if (tag) { - data.setParam('tag', tag); - } - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_to_param() { - var result0; - result0 = parse_tag_param(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_Via() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_via_param(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_via_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_via_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_via_param() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - result0 = parse_sent_protocol(); - - if (result0 !== null) { - result1 = parse_LWS(); - - if (result1 !== null) { - result2 = parse_sent_by(); - - if (result2 !== null) { - result3 = []; - pos1 = pos; - result4 = parse_SEMI(); - - if (result4 !== null) { - result5 = parse_via_params(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - - while (result4 !== null) { - result3.push(result4); - pos1 = pos; - result4 = parse_SEMI(); - - if (result4 !== null) { - result5 = parse_via_params(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - } - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_via_params() { - var result0; - result0 = parse_via_ttl(); - - if (result0 === null) { - result0 = parse_via_maddr(); - - if (result0 === null) { - result0 = parse_via_received(); - - if (result0 === null) { - result0 = parse_via_branch(); - - if (result0 === null) { - result0 = parse_response_port(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - } - } - } - } - - return result0; - } - - function parse_via_ttl() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 3).toLowerCase() === "ttl") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"ttl\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_ttl(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_ttl_value) { - data.ttl = via_ttl_value; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_via_maddr() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 5).toLowerCase() === "maddr") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"maddr\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_host(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_maddr) { - data.maddr = via_maddr; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_via_received() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 8).toLowerCase() === "received") { - result0 = input.substr(pos, 8); - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"received\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_IPv4address(); - - if (result2 === null) { - result2 = parse_IPv6address(); - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_received) { - data.received = via_received; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_via_branch() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6).toLowerCase() === "branch") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"branch\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_branch) { - data.branch = via_branch; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_response_port() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - - if (input.substr(pos, 5).toLowerCase() === "rport") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"rport\""); - } - } - - if (result0 !== null) { - pos1 = pos; - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_rport(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos1; - } - } else { - result1 = null; - pos = pos1; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_rport() { - var result0, result1, result2, result3, result4; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DIGIT(); - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_DIGIT(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_DIGIT(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result4 = parse_DIGIT(); - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, rport) { - data.rport = parseInt(rport.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_sent_protocol() { - var result0, result1, result2, result3, result4; - var pos0; - pos0 = pos; - result0 = parse_protocol_name(); - - if (result0 !== null) { - result1 = parse_SLASH(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result3 = parse_SLASH(); - - if (result3 !== null) { - result4 = parse_transport(); - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_protocol_name() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 3).toLowerCase() === "sip") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SIP\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - - if (result0 !== null) { - result0 = function (offset, via_protocol) { - data.protocol = via_protocol; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_transport() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 3).toLowerCase() === "udp") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"UDP\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 3).toLowerCase() === "tcp") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"TCP\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 3).toLowerCase() === "tls") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"TLS\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 4).toLowerCase() === "sctp") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SCTP\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - } - } - - if (result0 !== null) { - result0 = function (offset, via_transport) { - data.transport = via_transport; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_sent_by() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - result0 = parse_via_host(); - - if (result0 !== null) { - pos1 = pos; - result1 = parse_COLON(); - - if (result1 !== null) { - result2 = parse_via_port(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos1; - } - } else { - result1 = null; - pos = pos1; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_via_host() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_IPv4address(); - - if (result0 === null) { - result0 = parse_IPv6reference(); - - if (result0 === null) { - result0 = parse_hostname(); - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.host = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_via_port() { - var result0, result1, result2, result3, result4; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DIGIT(); - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_DIGIT(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_DIGIT(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result4 = parse_DIGIT(); - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_sent_by_port) { - data.port = parseInt(via_sent_by_port.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_ttl() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DIGIT(); - - if (result0 !== null) { - result1 = parse_DIGIT(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, ttl) { - return parseInt(ttl.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_WWW_Authenticate() { - var result0; - result0 = parse_challenge(); - return result0; - } - - function parse_Session_Expires() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_s_e_expires(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_s_e_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_s_e_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_s_e_expires() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_delta_seconds(); - - if (result0 !== null) { - result0 = function (offset, expires) { - data.expires = expires; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_s_e_params() { - var result0; - result0 = parse_s_e_refresher(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_s_e_refresher() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 9).toLowerCase() === "refresher") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"refresher\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - if (input.substr(pos, 3).toLowerCase() === "uac") { - result2 = input.substr(pos, 3); - pos += 3; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"uac\""); - } - } - - if (result2 === null) { - if (input.substr(pos, 3).toLowerCase() === "uas") { - result2 = input.substr(pos, 3); - pos += 3; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"uas\""); - } - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, s_e_refresher_value) { - data.refresher = s_e_refresher_value.toLowerCase(); - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_extension_header() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = parse_HCOLON(); - - if (result1 !== null) { - result2 = parse_header_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_header_value() { - var result0, result1; - result0 = []; - result1 = parse_TEXT_UTF8char(); - - if (result1 === null) { - result1 = parse_UTF8_CONT(); - - if (result1 === null) { - result1 = parse_LWS(); - } - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_TEXT_UTF8char(); - - if (result1 === null) { - result1 = parse_UTF8_CONT(); - - if (result1 === null) { - result1 = parse_LWS(); - } - } - } - - return result0; - } - - function parse_message_body() { - var result0, result1; - result0 = []; - result1 = parse_OCTET(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_OCTET(); - } - - return result0; - } - - function parse_uuid_URI() { - var result0, result1; - var pos0; - pos0 = pos; - - if (input.substr(pos, 5) === "uuid:") { - result0 = "uuid:"; - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"uuid:\""); - } - } - - if (result0 !== null) { - result1 = parse_uuid(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_uuid() { - var result0, result1, result2, result3, result4, result5, result6, result7, result8; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_hex8(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 !== null) { - result2 = parse_hex4(); - - if (result2 !== null) { - if (input.charCodeAt(pos) === 45) { - result3 = "-"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result3 !== null) { - result4 = parse_hex4(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 45) { - result5 = "-"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result5 !== null) { - result6 = parse_hex4(); - - if (result6 !== null) { - if (input.charCodeAt(pos) === 45) { - result7 = "-"; - pos++; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result7 !== null) { - result8 = parse_hex12(); - - if (result8 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, uuid) { - data = input.substring(pos + 5, offset); - }(pos0, result0[0]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_hex4() { - var result0, result1, result2, result3; - var pos0; - pos0 = pos; - result0 = parse_HEXDIG(); - - if (result0 !== null) { - result1 = parse_HEXDIG(); - - if (result1 !== null) { - result2 = parse_HEXDIG(); - - if (result2 !== null) { - result3 = parse_HEXDIG(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_hex8() { - var result0, result1; - var pos0; - pos0 = pos; - result0 = parse_hex4(); - - if (result0 !== null) { - result1 = parse_hex4(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_hex12() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_hex4(); - - if (result0 !== null) { - result1 = parse_hex4(); - - if (result1 !== null) { - result2 = parse_hex4(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Refer_To() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_SIP_URI_noparams(); - - if (result0 === null) { - result0 = parse_name_addr(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - try { - data = new NameAddrHeader(data.uri, data.display_name, data.params); - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Replaces() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_call_id(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_replaces_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_replaces_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_call_id() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_word(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 !== null) { - result2 = parse_word(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.call_id = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_replaces_param() { - var result0; - result0 = parse_to_tag(); - - if (result0 === null) { - result0 = parse_from_tag(); - - if (result0 === null) { - result0 = parse_early_flag(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - } - } - - return result0; - } - - function parse_to_tag() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6) === "to-tag") { - result0 = "to-tag"; - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"to-tag\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, to_tag) { - data.to_tag = to_tag; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_from_tag() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 8) === "from-tag") { - result0 = "from-tag"; - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"from-tag\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, from_tag) { - data.from_tag = from_tag; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_early_flag() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 10) === "early-only") { - result0 = "early-only"; - pos += 10; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"early-only\""); - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.early_only = true; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function cleanupExpected(expected) { - expected.sort(); - var lastExpected = null; - var cleanExpected = []; - - for (var i = 0; i < expected.length; i++) { - if (expected[i] !== lastExpected) { - cleanExpected.push(expected[i]); - lastExpected = expected[i]; - } - } - - return cleanExpected; - } - - function computeErrorPosition() { - /* - * The first idea was to use |String.split| to break the input up to the - * error position along newlines and derive the line and column from - * there. However IE's |split| implementation is so broken that it was - * enough to prevent it. - */ - var line = 1; - var column = 1; - var seenCR = false; - - for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) { - var ch = input.charAt(i); - - if (ch === "\n") { - if (!seenCR) { - line++; - } - - column = 1; - seenCR = false; - } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { - line++; - column = 1; - seenCR = true; - } else { - column++; - seenCR = false; - } - } - - return { - line: line, - column: column - }; - } - - var URI = require('./URI'); - - var NameAddrHeader = require('./NameAddrHeader'); - - var data = {}; - var result = parseFunctions[startRule](); - /* - * The parser is now in one of the following three states: - * - * 1. The parser successfully parsed the whole input. - * - * - |result !== null| - * - |pos === input.length| - * - |rightmostFailuresExpected| may or may not contain something - * - * 2. The parser successfully parsed only a part of the input. - * - * - |result !== null| - * - |pos < input.length| - * - |rightmostFailuresExpected| may or may not contain something - * - * 3. The parser did not successfully parse any part of the input. - * - * - |result === null| - * - |pos === 0| - * - |rightmostFailuresExpected| contains at least one failure - * - * All code following this comment (including called functions) must - * handle these states. - */ - - if (result === null || pos !== input.length) { - var offset = Math.max(pos, rightmostFailuresPos); - var found = offset < input.length ? input.charAt(offset) : null; - var errorPosition = computeErrorPosition(); - new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column); - return -1; - } - - return data; - }, - - /* Returns the parser source code. */ - toSource: function toSource() { - return this._source; - } - }; - /* Thrown when a parser encounters a syntax error. */ - - result.SyntaxError = function (expected, found, offset, line, column) { - function buildMessage(expected, found) { - var expectedHumanized, foundHumanized; - - switch (expected.length) { - case 0: - expectedHumanized = "end of input"; - break; - - case 1: - expectedHumanized = expected[0]; - break; - - default: - expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1]; - } - - foundHumanized = found ? quote(found) : "end of input"; - return "Expected " + expectedHumanized + " but " + foundHumanized + " found."; - } - - this.name = "SyntaxError"; - this.expected = expected; - this.found = found; - this.message = buildMessage(expected, found); - this.offset = offset; - this.line = line; - this.column = column; - }; - - result.SyntaxError.prototype = Error.prototype; - return result; -}(); -},{"./NameAddrHeader":10,"./URI":25}],8:[function(require,module,exports){ -"use strict"; - -var pkg = require('../package.json'); - -var C = require('./Constants'); - -var Exceptions = require('./Exceptions'); - -var Utils = require('./Utils'); - -var UA = require('./UA'); - -var URI = require('./URI'); - -var NameAddrHeader = require('./NameAddrHeader'); - -var Grammar = require('./Grammar'); - -var WebSocketInterface = require('./WebSocketInterface'); - -var debug = require('debug')('JsSIP'); - -debug('version %s', pkg.version); -/** - * Expose the JsSIP module. - */ - -module.exports = { - C: C, - Exceptions: Exceptions, - Utils: Utils, - UA: UA, - URI: URI, - NameAddrHeader: NameAddrHeader, - WebSocketInterface: WebSocketInterface, - Grammar: Grammar, - // Expose the debug module. - debug: require('debug'), - - get name() { - return pkg.title; - }, - - get version() { - return pkg.version; - } - -}; -},{"../package.json":38,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":24,"./URI":25,"./Utils":26,"./WebSocketInterface":27,"debug":30}],9:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('./Constants'); - -var SIPMessage = require('./SIPMessage'); - -var Utils = require('./Utils'); - -var RequestSender = require('./RequestSender'); - -var Exceptions = require('./Exceptions'); - -var debug = require('debug')('JsSIP:Message'); - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(Message, _EventEmitter); - - var _super = _createSuper(Message); - - function Message(ua) { - var _this; - - _classCallCheck(this, Message); - - _this = _super.call(this); - _this._ua = ua; - _this._request = null; - _this._closed = false; - _this._direction = null; - _this._local_identity = null; - _this._remote_identity = null; // Whether an incoming message has been replied. - - _this._is_replied = false; // Custom message empty object for high level use. - - _this._data = {}; - return _this; - } - - _createClass(Message, [{ - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "send", - value: function send(target, body) { - var _this2 = this; - - var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - var originalTarget = target; - - if (target === undefined || body === undefined) { - throw new TypeError('Not enough arguments'); - } // Check target validity. - - - target = this._ua.normalizeTarget(target); - - if (!target) { - throw new TypeError("Invalid target: ".concat(originalTarget)); - } // Get call options. - - - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var contentType = options.contentType || 'text/plain'; // Set event handlers. - - for (var event in eventHandlers) { - if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { - this.on(event, eventHandlers[event]); - } - } - - extraHeaders.push("Content-Type: ".concat(contentType)); - this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, null, extraHeaders); - - if (body) { - this._request.body = body; - } - - var request_sender = new RequestSender(this._ua, this._request, { - onRequestTimeout: function onRequestTimeout() { - _this2._onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this2._onTransportError(); - }, - onReceiveResponse: function onReceiveResponse(response) { - _this2._receiveResponse(response); - } - }); - - this._newMessage('local', this._request); - - request_sender.send(); - } - }, { - key: "init_incoming", - value: function init_incoming(request) { - this._request = request; - - this._newMessage('remote', request); // Reply with a 200 OK if the user didn't reply. - - - if (!this._is_replied) { - this._is_replied = true; - request.reply(200); - } - - this._close(); - } - /** - * Accept the incoming Message - * Only valid for incoming Messages - */ - - }, { - key: "accept", - value: function accept() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var body = options.body; - - if (this._direction !== 'incoming') { - throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message'); - } - - if (this._is_replied) { - throw new Error('incoming Message already replied'); - } - - this._is_replied = true; - - this._request.reply(200, null, extraHeaders, body); - } - /** - * Reject the incoming Message - * Only valid for incoming Messages - */ - - }, { - key: "reject", - value: function reject() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var status_code = options.status_code || 480; - var reason_phrase = options.reason_phrase; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var body = options.body; - - if (this._direction !== 'incoming') { - throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message'); - } - - if (this._is_replied) { - throw new Error('incoming Message already replied'); - } - - if (status_code < 300 || status_code >= 700) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } - - this._is_replied = true; - - this._request.reply(status_code, reason_phrase, extraHeaders, body); - } - }, { - key: "_receiveResponse", - value: function _receiveResponse(response) { - if (this._closed) { - return; - } - - switch (true) { - case /^1[0-9]{2}$/.test(response.status_code): - // Ignore provisional responses. - break; - - case /^2[0-9]{2}$/.test(response.status_code): - this._succeeded('remote', response); - - break; - - default: - { - var cause = Utils.sipErrorCause(response.status_code); - - this._failed('remote', response, cause); - - break; - } - } - } - }, { - key: "_onRequestTimeout", - value: function _onRequestTimeout() { - if (this._closed) { - return; - } - - this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT); - } - }, { - key: "_onTransportError", - value: function _onTransportError() { - if (this._closed) { - return; - } - - this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); - } - }, { - key: "_close", - value: function _close() { - this._closed = true; - - this._ua.destroyMessage(this); - } - /** - * Internal Callbacks - */ - - }, { - key: "_newMessage", - value: function _newMessage(originator, request) { - if (originator === 'remote') { - this._direction = 'incoming'; - this._local_identity = request.to; - this._remote_identity = request.from; - } else if (originator === 'local') { - this._direction = 'outgoing'; - this._local_identity = request.from; - this._remote_identity = request.to; - } - - this._ua.newMessage(this, { - originator: originator, - message: this, - request: request - }); - } - }, { - key: "_failed", - value: function _failed(originator, response, cause) { - debug('MESSAGE failed'); - - this._close(); - - debug('emit "failed"'); - this.emit('failed', { - originator: originator, - response: response || null, - cause: cause - }); - } - }, { - key: "_succeeded", - value: function _succeeded(originator, response) { - debug('MESSAGE succeeded'); - - this._close(); - - debug('emit "succeeded"'); - this.emit('succeeded', { - originator: originator, - response: response - }); - } - }]); - - return Message; -}(EventEmitter); -},{"./Constants":2,"./Exceptions":6,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30,"events":29}],10:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var URI = require('./URI'); - -var Grammar = require('./Grammar'); - -module.exports = /*#__PURE__*/function () { - function NameAddrHeader(uri, display_name, parameters) { - _classCallCheck(this, NameAddrHeader); - - // Checks. - if (!uri || !(uri instanceof URI)) { - throw new TypeError('missing or invalid "uri" parameter'); - } // Initialize parameters. - - - this._uri = uri; - this._parameters = {}; - this.display_name = display_name; - - for (var param in parameters) { - if (Object.prototype.hasOwnProperty.call(parameters, param)) { - this.setParam(param, parameters[param]); - } - } - } - - _createClass(NameAddrHeader, [{ - key: "uri", - get: function get() { - return this._uri; - } - }, { - key: "display_name", - get: function get() { - return this._display_name; - }, - set: function set(value) { - this._display_name = value === 0 ? '0' : value; - } - }, { - key: "setParam", - value: function setParam(key, value) { - if (key) { - this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString(); - } - } - }, { - key: "getParam", - value: function getParam(key) { - if (key) { - return this._parameters[key.toLowerCase()]; - } - } - }, { - key: "hasParam", - value: function hasParam(key) { - if (key) { - return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false; - } - } - }, { - key: "deleteParam", - value: function deleteParam(parameter) { - parameter = parameter.toLowerCase(); - - if (this._parameters.hasOwnProperty(parameter)) { - var value = this._parameters[parameter]; - delete this._parameters[parameter]; - return value; - } - } - }, { - key: "clearParams", - value: function clearParams() { - this._parameters = {}; - } - }, { - key: "clone", - value: function clone() { - return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters))); - } - }, { - key: "_quote", - value: function _quote(str) { - return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); - } - }, { - key: "toString", - value: function toString() { - var body = this._display_name ? "\"".concat(this._quote(this._display_name), "\" ") : ''; - body += "<".concat(this._uri.toString(), ">"); - - for (var parameter in this._parameters) { - if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) { - body += ";".concat(parameter); - - if (this._parameters[parameter] !== null) { - body += "=".concat(this._parameters[parameter]); - } - } - } - - return body; - } - }], [{ - key: "parse", - value: - /** - * Parse the given string and returns a NameAddrHeader instance or undefined if - * it is an invalid NameAddrHeader. - */ - function parse(name_addr_header) { - name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); - - if (name_addr_header !== -1) { - return name_addr_header; - } else { - return undefined; - } - } - }]); - - return NameAddrHeader; -}(); -},{"./Grammar":7,"./URI":25}],11:[function(require,module,exports){ -"use strict"; - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var Grammar = require('./Grammar'); - -var SIPMessage = require('./SIPMessage'); - -var debugerror = require('debug')('JsSIP:ERROR:Parser'); - -debugerror.log = console.warn.bind(console); -/** - * Parse SIP Message - */ - -exports.parseMessage = function (data, ua) { - var message; - var bodyStart; - var headerEnd = data.indexOf('\r\n'); - - if (headerEnd === -1) { - debugerror('parseMessage() | no CRLF found, not a SIP message'); - return; - } // Parse first line. Check if it is a Request or a Reply. - - - var firstLine = data.substring(0, headerEnd); - var parsed = Grammar.parse(firstLine, 'Request_Response'); - - if (parsed === -1) { - debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); - return; - } else if (!parsed.status_code) { - message = new SIPMessage.IncomingRequest(ua); - message.method = parsed.method; - message.ruri = parsed.uri; - } else { - message = new SIPMessage.IncomingResponse(); - message.status_code = parsed.status_code; - message.reason_phrase = parsed.reason_phrase; - } - - message.data = data; - var headerStart = headerEnd + 2; - /* Loop over every line in data. Detect the end of each header and parse - * it or simply add to the headers collection. - */ - - while (true) { - headerEnd = getHeader(data, headerStart); // The SIP message has normally finished. - - if (headerEnd === -2) { - bodyStart = headerStart + 2; - break; - } // Data.indexOf returned -1 due to a malformed message. - else if (headerEnd === -1) { - debugerror('parseMessage() | malformed message'); - return; - } - - parsed = parseHeader(message, data, headerStart, headerEnd); - - if (parsed !== true) { - debugerror('parseMessage() |', parsed.error); - return; - } - - headerStart = headerEnd + 2; - } - /* RFC3261 18.3. - * If there are additional bytes in the transport packet - * beyond the end of the body, they MUST be discarded. - */ - - - if (message.hasHeader('content-length')) { - var contentLength = message.getHeader('content-length'); - message.body = data.substr(bodyStart, contentLength); - } else { - message.body = data.substring(bodyStart); - } - - return message; -}; -/** - * Extract and parse every header of a SIP message. - */ - - -function getHeader(data, headerStart) { - // 'start' position of the header. - var start = headerStart; // 'end' position of the header. - - var end = 0; // 'partial end' position of the header. - - var partialEnd = 0; // End of message. - - if (data.substring(start, start + 2).match(/(^\r\n)/)) { - return -2; - } - - while (end === 0) { - // Partial End of Header. - partialEnd = data.indexOf('\r\n', start); // 'indexOf' returns -1 if the value to be found never occurs. - - if (partialEnd === -1) { - return partialEnd; - } - - if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) { - // Not the end of the message. Continue from the next position. - start = partialEnd + 2; - } else { - end = partialEnd; - } - } - - return end; -} - -function parseHeader(message, data, headerStart, headerEnd) { - var parsed; - var hcolonIndex = data.indexOf(':', headerStart); - var headerName = data.substring(headerStart, hcolonIndex).trim(); - var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim(); // If header-field is well-known, parse it. - - switch (headerName.toLowerCase()) { - case 'via': - case 'v': - message.addHeader('via', headerValue); - - if (message.getHeaders('via').length === 1) { - parsed = message.parseHeader('Via'); - - if (parsed) { - message.via = parsed; - message.via_branch = parsed.branch; - } - } else { - parsed = 0; - } - - break; - - case 'from': - case 'f': - message.setHeader('from', headerValue); - parsed = message.parseHeader('from'); - - if (parsed) { - message.from = parsed; - message.from_tag = parsed.getParam('tag'); - } - - break; - - case 'to': - case 't': - message.setHeader('to', headerValue); - parsed = message.parseHeader('to'); - - if (parsed) { - message.to = parsed; - message.to_tag = parsed.getParam('tag'); - } - - break; - - case 'record-route': - parsed = Grammar.parse(headerValue, 'Record_Route'); - - if (parsed === -1) { - parsed = undefined; - } else { - var _iterator = _createForOfIteratorHelper(parsed), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var header = _step.value; - message.addHeader('record-route', headerValue.substring(header.possition, header.offset)); - message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed; - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } - - break; - - case 'call-id': - case 'i': - message.setHeader('call-id', headerValue); - parsed = message.parseHeader('call-id'); - - if (parsed) { - message.call_id = headerValue; - } - - break; - - case 'contact': - case 'm': - parsed = Grammar.parse(headerValue, 'Contact'); - - if (parsed === -1) { - parsed = undefined; - } else { - var _iterator2 = _createForOfIteratorHelper(parsed), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var _header = _step2.value; - message.addHeader('contact', headerValue.substring(_header.possition, _header.offset)); - message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed; - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - } - - break; - - case 'content-length': - case 'l': - message.setHeader('content-length', headerValue); - parsed = message.parseHeader('content-length'); - break; - - case 'content-type': - case 'c': - message.setHeader('content-type', headerValue); - parsed = message.parseHeader('content-type'); - break; - - case 'cseq': - message.setHeader('cseq', headerValue); - parsed = message.parseHeader('cseq'); - - if (parsed) { - message.cseq = parsed.value; - } - - if (message instanceof SIPMessage.IncomingResponse) { - message.method = parsed.method; - } - - break; - - case 'max-forwards': - message.setHeader('max-forwards', headerValue); - parsed = message.parseHeader('max-forwards'); - break; - - case 'www-authenticate': - message.setHeader('www-authenticate', headerValue); - parsed = message.parseHeader('www-authenticate'); - break; - - case 'proxy-authenticate': - message.setHeader('proxy-authenticate', headerValue); - parsed = message.parseHeader('proxy-authenticate'); - break; - - case 'session-expires': - case 'x': - message.setHeader('session-expires', headerValue); - parsed = message.parseHeader('session-expires'); - - if (parsed) { - message.session_expires = parsed.expires; - message.session_expires_refresher = parsed.refresher; - } - - break; - - case 'refer-to': - case 'r': - message.setHeader('refer-to', headerValue); - parsed = message.parseHeader('refer-to'); - - if (parsed) { - message.refer_to = parsed; - } - - break; - - case 'replaces': - message.setHeader('replaces', headerValue); - parsed = message.parseHeader('replaces'); - - if (parsed) { - message.replaces = parsed; - } - - break; - - case 'event': - case 'o': - message.setHeader('event', headerValue); - parsed = message.parseHeader('event'); - - if (parsed) { - message.event = parsed; - } - - break; - - default: - // Do not parse this header. - message.addHeader(headerName, headerValue); - parsed = 0; - } - - if (parsed === undefined) { - return { - error: "error parsing header \"".concat(headerName, "\"") - }; - } else { - return true; - } -} -},{"./Grammar":7,"./SIPMessage":19,"debug":30}],12:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -/* globals RTCPeerConnection: false, RTCSessionDescription: false */ -var EventEmitter = require('events').EventEmitter; - -var sdp_transform = require('sdp-transform'); - -var JsSIP_C = require('./Constants'); - -var Exceptions = require('./Exceptions'); - -var Transactions = require('./Transactions'); - -var Utils = require('./Utils'); - -var Timers = require('./Timers'); - -var SIPMessage = require('./SIPMessage'); - -var Dialog = require('./Dialog'); - -var RequestSender = require('./RequestSender'); - -var RTCSession_DTMF = require('./RTCSession/DTMF'); - -var RTCSession_Info = require('./RTCSession/Info'); - -var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier'); - -var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); - -var URI = require('./URI'); - -var debug = require('debug')('JsSIP:RTCSession'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession'); - -debugerror.log = console.warn.bind(console); -var C = { - // RTCSession states. - 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 -}; -/** - * Local variables. - */ - -var holdMediaTypes = ['audio', 'video']; - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(RTCSession, _EventEmitter); - - var _super = _createSuper(RTCSession); - - function RTCSession(ua) { - var _this; - - _classCallCheck(this, RTCSession); - - debug('new'); - _this = _super.call(this); - _this._id = null; - _this._ua = ua; - _this._status = C.STATUS_NULL; - _this._dialog = null; - _this._earlyDialogs = {}; - _this._contact = null; - _this._from_tag = null; - _this._to_tag = null; // The RTCPeerConnection instance (public attribute). - - _this._connection = null; // Prevent races on serial PeerConnction operations. - - _this._connectionPromiseQueue = Promise.resolve(); // Incoming/Outgoing request being currently processed. - - _this._request = null; // Cancel state for initial outgoing request. - - _this._is_canceled = false; - _this._cancel_reason = ''; // RTCSession confirmation flag. - - _this._is_confirmed = false; // Is late SDP being negotiated. - - _this._late_sdp = false; // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()). - - _this._rtcOfferConstraints = null; - _this._rtcAnswerConstraints = null; // Local MediaStream. - - _this._localMediaStream = null; - _this._localMediaStreamLocallyGenerated = false; // Flag to indicate PeerConnection ready for new actions. - - _this._rtcReady = true; // SIP Timers. - - _this._timers = { - ackTimer: null, - expiresTimer: null, - invite2xxTimer: null, - userNoAnswerTimer: null - }; // Session info. - - _this._direction = null; - _this._local_identity = null; - _this._remote_identity = null; - _this._start_time = null; - _this._end_time = null; - _this._tones = null; // Mute/Hold state. - - _this._audioMuted = false; - _this._videoMuted = false; - _this._localHold = false; - _this._remoteHold = false; // Session Timers (RFC 4028). - - _this._sessionTimers = { - enabled: _this._ua.configuration.session_timers, - refreshMethod: _this._ua.configuration.session_timers_refresh_method, - defaultExpires: JsSIP_C.SESSION_EXPIRES, - currentExpires: null, - running: false, - refresher: false, - timer: null // A setTimeout. - - }; // Map of ReferSubscriber instances indexed by the REFER's CSeq number. - - _this._referSubscribers = {}; // Custom session empty object for high level use. - - _this._data = {}; - return _this; - } - /** - * User API - */ - // Expose RTCSession constants as a property of the RTCSession instance. - - - _createClass(RTCSession, [{ - key: "C", - get: function get() { - return C; - } // Expose session failed/ended causes as a property of the RTCSession instance. - - }, { - key: "causes", - get: function get() { - return JsSIP_C.causes; - } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "connection", - get: function get() { - return this._connection; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "start_time", - get: function get() { - return this._start_time; - } - }, { - key: "end_time", - get: function get() { - return this._end_time; - } - }, { - key: "data", - get: function get() { - return this._data; - }, - set: function set(_data) { - this._data = _data; - } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "isInProgress", - value: function isInProgress() { - switch (this._status) { - case C.STATUS_NULL: - case C.STATUS_INVITE_SENT: - case C.STATUS_1XX_RECEIVED: - case C.STATUS_INVITE_RECEIVED: - case C.STATUS_WAITING_FOR_ANSWER: - return true; - - default: - return false; - } - } - }, { - key: "isEstablished", - value: function isEstablished() { - switch (this._status) { - case C.STATUS_ANSWERED: - case C.STATUS_WAITING_FOR_ACK: - case C.STATUS_CONFIRMED: - return true; - - default: - return false; - } - } - }, { - key: "isEnded", - value: function isEnded() { - switch (this._status) { - case C.STATUS_CANCELED: - case C.STATUS_TERMINATED: - return true; - - default: - return false; - } - } - }, { - key: "isMuted", - value: function isMuted() { - return { - audio: this._audioMuted, - video: this._videoMuted - }; - } - }, { - key: "isOnHold", - value: function isOnHold() { - return { - local: this._localHold, - remote: this._remoteHold - }; - } - }, { - key: "connect", - value: function connect(target) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var initCallback = arguments.length > 2 ? arguments[2] : undefined; - debug('connect()'); - var originalTarget = target; - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var mediaConstraints = Utils.cloneObject(options.mediaConstraints, { - audio: true, - video: true - }); - var mediaStream = options.mediaStream || null; - var pcConfig = Utils.cloneObject(options.pcConfig, { - iceServers: [] - }); - var rtcConstraints = options.rtcConstraints || null; - var rtcOfferConstraints = options.rtcOfferConstraints || null; - this._rtcOfferConstraints = rtcOfferConstraints; - this._rtcAnswerConstraints = options.rtcAnswerConstraints || null; - this._data = options.data || this._data; // Check target. - - if (target === undefined) { - throw new TypeError('Not enough arguments'); - } // Check Session Status. - - - if (this._status !== C.STATUS_NULL) { - throw new Exceptions.InvalidStateError(this._status); - } // Check WebRTC support. - - - if (!window.RTCPeerConnection) { - throw new Exceptions.NotSupportedError('WebRTC not supported'); - } // Check target validity. - - - target = this._ua.normalizeTarget(target); - - if (!target) { - throw new TypeError("Invalid target: ".concat(originalTarget)); - } // Session Timers. - - - if (this._sessionTimers.enabled) { - if (Utils.isDecimal(options.sessionTimersExpires)) { - if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) { - this._sessionTimers.defaultExpires = options.sessionTimersExpires; - } else { - this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES; - } - } - } // Set event handlers. - - - for (var event in eventHandlers) { - if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { - this.on(event, eventHandlers[event]); - } - } // Session parameter initialization. - - - this._from_tag = Utils.newTag(); // Set anonymous property. - - var anonymous = options.anonymous || false; - var requestParams = { - from_tag: this._from_tag - }; - this._contact = this._ua.contact.toString({ - anonymous: anonymous, - outbound: true - }); - - if (anonymous) { - requestParams.from_display_name = 'Anonymous'; - requestParams.from_uri = new URI('sip', 'anonymous', 'anonymous.invalid'); - extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())); - extraHeaders.push('Privacy: id'); - } else if (options.fromUserName) { - requestParams.from_uri = new URI('sip', options.fromUserName, this._ua.configuration.uri.host); - extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())); - } - - if (options.fromDisplayName) { - requestParams.from_display_name = options.fromDisplayName; - } - - extraHeaders.push("Contact: ".concat(this._contact)); - extraHeaders.push('Content-Type: application/sdp'); - - if (this._sessionTimers.enabled) { - extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher ? ';refresher=uac' : '')); - } - - this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders); - this._id = this._request.call_id + this._from_tag; // Create a new RTCPeerConnection instance. - - this._createRTCConnection(pcConfig, rtcConstraints); // Set internal properties. - - - this._direction = 'outgoing'; - this._local_identity = this._request.from; - this._remote_identity = this._request.to; // User explicitly provided a newRTCSession callback for this session. - - if (initCallback) { - initCallback(this); - } - - this._newRTCSession('local', this._request); - - this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream); - } - }, { - key: "init_incoming", - value: function init_incoming(request, initCallback) { - var _this2 = this; - - debug('init_incoming()'); - var expires; - var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type. - - if (request.body && contentType !== 'application/sdp') { - request.reply(415); - return; - } // Session parameter initialization. - - - this._status = C.STATUS_INVITE_RECEIVED; - this._from_tag = request.from_tag; - this._id = request.call_id + this._from_tag; - this._request = request; - this._contact = this._ua.contact.toString(); // Get the Expires header value if exists. - - if (request.hasHeader('expires')) { - expires = request.getHeader('expires') * 1000; - } - /* Set the to_tag before - * replying a response code that will create a dialog. - */ - - - request.to_tag = Utils.newTag(); // An error on dialog creation will fire 'failed' event. - - if (!this._createDialog(request, 'UAS', true)) { - request.reply(500, 'Missing Contact header field'); - return; - } - - if (request.body) { - this._late_sdp = false; - } else { - this._late_sdp = true; - } - - this._status = C.STATUS_WAITING_FOR_ANSWER; // Set userNoAnswerTimer. - - this._timers.userNoAnswerTimer = setTimeout(function () { - request.reply(408); - - _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER); - }, this._ua.configuration.no_answer_timeout); - /* Set expiresTimer - * RFC3261 13.3.1 - */ - - if (expires) { - this._timers.expiresTimer = setTimeout(function () { - if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) { - request.reply(487); - - _this2._failed('system', null, JsSIP_C.causes.EXPIRES); - } - }, expires); - } // Set internal properties. - - - this._direction = 'incoming'; - this._local_identity = request.to; - this._remote_identity = request.from; // A init callback was specifically defined. - - if (initCallback) { - initCallback(this); - } // Fire 'newRTCSession' event. - - - this._newRTCSession('remote', request); // The user may have rejected the call in the 'newRTCSession' event. - - - if (this._status === C.STATUS_TERMINATED) { - return; - } // Reply 180. - - - request.reply(180, null, ["Contact: ".concat(this._contact)]); // Fire 'progress' event. - // TODO: Document that 'response' field in 'progress' event is null for incoming calls. - - this._progress('local', null); - } - /** - * Answer the call. - */ - - }, { - key: "answer", - value: function answer() { - var _this3 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('answer()'); - var request = this._request; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var mediaConstraints = Utils.cloneObject(options.mediaConstraints); - var mediaStream = options.mediaStream || null; - var pcConfig = Utils.cloneObject(options.pcConfig, { - iceServers: [] - }); - var rtcConstraints = options.rtcConstraints || null; - var rtcAnswerConstraints = options.rtcAnswerConstraints || null; - var rtcOfferConstraints = Utils.cloneObject(options.rtcOfferConstraints); - var tracks; - var peerHasAudioLine = false; - var peerHasVideoLine = false; - var peerOffersFullAudio = false; - var peerOffersFullVideo = false; - this._rtcAnswerConstraints = rtcAnswerConstraints; - this._rtcOfferConstraints = options.rtcOfferConstraints || null; - this._data = options.data || this._data; // Check Session Direction and Status. - - if (this._direction !== 'incoming') { - throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession'); - } // Check Session status. - - - if (this._status !== C.STATUS_WAITING_FOR_ANSWER) { - throw new Exceptions.InvalidStateError(this._status); - } // Session Timers. - - - if (this._sessionTimers.enabled) { - if (Utils.isDecimal(options.sessionTimersExpires)) { - if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) { - this._sessionTimers.defaultExpires = options.sessionTimersExpires; - } else { - this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES; - } - } - } - - this._status = C.STATUS_ANSWERED; // An error on dialog creation will fire 'failed' event. - - if (!this._createDialog(request, 'UAS')) { - request.reply(500, 'Error creating dialog'); - return; - } - - clearTimeout(this._timers.userNoAnswerTimer); - extraHeaders.unshift("Contact: ".concat(this._contact)); // Determine incoming media from incoming SDP offer (if any). - - var sdp = request.parseSDP(); // Make sure sdp.media is an array, not the case if there is only one media. - - if (!Array.isArray(sdp.media)) { - sdp.media = [sdp.media]; - } // Go through all medias in SDP to find offered capabilities to answer with. - - - var _iterator = _createForOfIteratorHelper(sdp.media), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var m = _step.value; - - if (m.type === 'audio') { - peerHasAudioLine = true; - - if (!m.direction || m.direction === 'sendrecv') { - peerOffersFullAudio = true; - } - } - - if (m.type === 'video') { - peerHasVideoLine = true; - - if (!m.direction || m.direction === 'sendrecv') { - peerOffersFullVideo = true; - } - } - } // Remove audio from mediaStream if suggested by mediaConstraints. - - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - - if (mediaStream && mediaConstraints.audio === false) { - tracks = mediaStream.getAudioTracks(); - - var _iterator2 = _createForOfIteratorHelper(tracks), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var track = _step2.value; - mediaStream.removeTrack(track); - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - } // Remove video from mediaStream if suggested by mediaConstraints. - - - if (mediaStream && mediaConstraints.video === false) { - tracks = mediaStream.getVideoTracks(); - - var _iterator3 = _createForOfIteratorHelper(tracks), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var _track = _step3.value; - mediaStream.removeTrack(_track); - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } - } // Set audio constraints based on incoming stream if not supplied. - - - if (!mediaStream && mediaConstraints.audio === undefined) { - mediaConstraints.audio = peerOffersFullAudio; - } // Set video constraints based on incoming stream if not supplied. - - - if (!mediaStream && mediaConstraints.video === undefined) { - mediaConstraints.video = peerOffersFullVideo; - } // Don't ask for audio if the incoming offer has no audio section. - - - if (!mediaStream && !peerHasAudioLine && !rtcOfferConstraints.offerToReceiveAudio) { - mediaConstraints.audio = false; - } // Don't ask for video if the incoming offer has no video section. - - - if (!mediaStream && !peerHasVideoLine && !rtcOfferConstraints.offerToReceiveVideo) { - mediaConstraints.video = false; - } // Create a new RTCPeerConnection instance. - // TODO: This may throw an error, should react. - - - this._createRTCConnection(pcConfig, rtcConstraints); - - Promise.resolve() // Handle local MediaStream. - .then(function () { - // A local MediaStream is given, use it. - if (mediaStream) { - return mediaStream; - } // Audio and/or video requested, prompt getUserMedia. - else if (mediaConstraints.audio || mediaConstraints.video) { - _this3._localMediaStreamLocallyGenerated = true; - return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) { - if (_this3._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - request.reply(480); - - _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - - debugerror('emit "getusermediafailed" [error:%o]', error); - - _this3.emit('getusermediafailed', error); - - throw new Error('getUserMedia() failed'); - }); - } - }) // Attach MediaStream to RTCPeerconnection. - .then(function (stream) { - if (_this3._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this3._localMediaStream = stream; - - if (stream) { - stream.getTracks().forEach(function (track) { - _this3._connection.addTrack(track, stream); - }); - } - }) // Set remote description. - .then(function () { - if (_this3._late_sdp) { - return; - } - - var e = { - originator: 'remote', - type: 'offer', - sdp: request.body - }; - debug('emit "sdp"'); - - _this3.emit('sdp', e); - - var offer = new RTCSessionDescription({ - type: 'offer', - sdp: e.sdp - }); - _this3._connectionPromiseQueue = _this3._connectionPromiseQueue.then(function () { - return _this3._connection.setRemoteDescription(offer); - })["catch"](function (error) { - request.reply(488); - - _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); - - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this3.emit('peerconnection:setremotedescriptionfailed', error); - - throw new Error('peerconnection.setRemoteDescription() failed'); - }); - return _this3._connectionPromiseQueue; - }) // Create local description. - .then(function () { - if (_this3._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } // TODO: Is this event already useful? - - - _this3._connecting(request); - - if (!_this3._late_sdp) { - return _this3._createLocalDescription('answer', rtcAnswerConstraints)["catch"](function () { - request.reply(500); - throw new Error('_createLocalDescription() failed'); - }); - } else { - return _this3._createLocalDescription('offer', _this3._rtcOfferConstraints)["catch"](function () { - request.reply(500); - throw new Error('_createLocalDescription() failed'); - }); - } - }) // Send reply. - .then(function (desc) { - if (_this3._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this3._handleSessionTimersInIncomingRequest(request, extraHeaders); - - request.reply(200, null, extraHeaders, desc, function () { - _this3._status = C.STATUS_WAITING_FOR_ACK; - - _this3._setInvite2xxTimer(request, desc); - - _this3._setACKTimer(); - - _this3._accepted('local'); - }, function () { - _this3._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); - }); - })["catch"](function (error) { - if (_this3._status === C.STATUS_TERMINATED) { - return; - } - - debugerror(error); - }); - } - /** - * Terminate the call. - */ - - }, { - key: "terminate", - value: function terminate() { - var _this4 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('terminate()'); - var cause = options.cause || JsSIP_C.causes.BYE; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var body = options.body; - var cancel_reason; - var status_code = options.status_code; - var reason_phrase = options.reason_phrase; // Check Session Status. - - if (this._status === C.STATUS_TERMINATED) { - throw new Exceptions.InvalidStateError(this._status); - } - - switch (this._status) { - // - UAC - - case C.STATUS_NULL: - case C.STATUS_INVITE_SENT: - case C.STATUS_1XX_RECEIVED: - debug('canceling session'); - - if (status_code && (status_code < 200 || status_code >= 700)) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } else if (status_code) { - reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; - cancel_reason = "SIP ;cause=".concat(status_code, " ;text=\"").concat(reason_phrase, "\""); - } // Check Session Status. - - - if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) { - this._is_canceled = true; - this._cancel_reason = cancel_reason; - } else if (this._status === C.STATUS_1XX_RECEIVED) { - this._request.cancel(cancel_reason); - } - - this._status = C.STATUS_CANCELED; - - this._failed('local', null, JsSIP_C.causes.CANCELED); - - break; - // - UAS - - - case C.STATUS_WAITING_FOR_ANSWER: - case C.STATUS_ANSWERED: - debug('rejecting session'); - status_code = status_code || 480; - - if (status_code < 300 || status_code >= 700) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } - - this._request.reply(status_code, reason_phrase, extraHeaders, body); - - this._failed('local', null, JsSIP_C.causes.REJECTED); - - break; - - case C.STATUS_WAITING_FOR_ACK: - case C.STATUS_CONFIRMED: - debug('terminating session'); - reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; - - if (status_code && (status_code < 200 || status_code >= 700)) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } else if (status_code) { - extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\"")); - } - /* RFC 3261 section 15 (Terminating a session): - * - * "...the callee's UA MUST NOT send a BYE on a confirmed dialog - * until it has received an ACK for its 2xx response or until the server - * transaction times out." - */ - - - if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) { - // Save the dialog for later restoration. - var dialog = this._dialog; // Send the BYE as soon as the ACK is received... - - this.receiveRequest = function (_ref) { - var method = _ref.method; - - if (method === JsSIP_C.ACK) { - _this4.sendRequest(JsSIP_C.BYE, { - extraHeaders: extraHeaders, - body: body - }); - - dialog.terminate(); - } - }; // .., or when the INVITE transaction times out - - - this._request.server_transaction.on('stateChanged', function () { - if (_this4._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) { - _this4.sendRequest(JsSIP_C.BYE, { - extraHeaders: extraHeaders, - body: body - }); - - dialog.terminate(); - } - }); - - this._ended('local', null, cause); // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-). - - - this._dialog = dialog; // Restore the dialog into 'ua' so the ACK can reach 'this' session. - - this._ua.newDialog(dialog); - } else { - this.sendRequest(JsSIP_C.BYE, { - extraHeaders: extraHeaders, - body: body - }); - - this._ended('local', null, cause); - } - - } - } - }, { - key: "sendDTMF", - value: function sendDTMF(tones) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendDTMF() | tones: %s', tones); - var position = 0; - var duration = options.duration || null; - var interToneGap = options.interToneGap || null; - var transportType = options.transportType || JsSIP_C.DTMF_TRANSPORT.INFO; - - if (tones === undefined) { - throw new TypeError('Not enough arguments'); - } // Check Session Status. - - - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { - throw new Exceptions.InvalidStateError(this._status); - } // Check Transport type. - - - if (transportType !== JsSIP_C.DTMF_TRANSPORT.INFO && transportType !== JsSIP_C.DTMF_TRANSPORT.RFC2833) { - throw new TypeError("invalid transportType: ".concat(transportType)); - } // Convert to string. - - - if (typeof tones === 'number') { - tones = tones.toString(); - } // Check tones. - - - if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) { - throw new TypeError("Invalid tones: ".concat(tones)); - } // Check duration. - - - if (duration && !Utils.isDecimal(duration)) { - throw new TypeError("Invalid tone duration: ".concat(duration)); - } else if (!duration) { - duration = RTCSession_DTMF.C.DEFAULT_DURATION; - } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { - debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); - duration = RTCSession_DTMF.C.MIN_DURATION; - } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { - debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); - duration = RTCSession_DTMF.C.MAX_DURATION; - } else { - duration = Math.abs(duration); - } - - options.duration = duration; // Check interToneGap. - - if (interToneGap && !Utils.isDecimal(interToneGap)) { - throw new TypeError("Invalid interToneGap: ".concat(interToneGap)); - } else if (!interToneGap) { - interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP; - } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { - debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); - interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; - } else { - interToneGap = Math.abs(interToneGap); - } // RFC2833. Let RTCDTMFSender enqueue the DTMFs. - - - if (transportType === JsSIP_C.DTMF_TRANSPORT.RFC2833) { - // Send DTMF in current audio RTP stream. - var sender = this._getDTMFRTPSender(); - - if (sender) { - // Add remaining buffered tones. - tones = sender.toneBuffer + tones; // Insert tones. - - sender.insertDTMF(tones, duration, interToneGap); - } - - return; - } - - if (this._tones) { - // Tones are already queued, just add to the queue. - this._tones += tones; - return; - } - - this._tones = tones; // Send the first tone. - - _sendDTMF.call(this); - - function _sendDTMF() { - var _this5 = this; - - var timeout; - - if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) { - // Stop sending DTMF. - this._tones = null; - return; - } - - var tone = this._tones[position]; - position += 1; - - if (tone === ',') { - timeout = 2000; - } else { - // Send DTMF via SIP INFO messages. - var dtmf = new RTCSession_DTMF(this); - options.eventHandlers = { - onFailed: function onFailed() { - _this5._tones = null; - } - }; - dtmf.send(tone, options); - timeout = duration + interToneGap; - } // Set timeout for the next tone. - - - setTimeout(_sendDTMF.bind(this), timeout); - } - } - }, { - key: "sendInfo", - value: function sendInfo(contentType, body) { - var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - debug('sendInfo()'); // Check Session Status. - - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { - throw new Exceptions.InvalidStateError(this._status); - } - - var info = new RTCSession_Info(this); - info.send(contentType, body, options); - } - /** - * Mute - */ - - }, { - key: "mute", - value: function mute() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { - audio: true, - video: false - }; - debug('mute()'); - var audioMuted = false, - videoMuted = false; - - if (this._audioMuted === false && options.audio) { - audioMuted = true; - this._audioMuted = true; - - this._toggleMuteAudio(true); - } - - if (this._videoMuted === false && options.video) { - videoMuted = true; - this._videoMuted = true; - - this._toggleMuteVideo(true); - } - - if (audioMuted === true || videoMuted === true) { - this._onmute({ - audio: audioMuted, - video: videoMuted - }); - } - } - /** - * Unmute - */ - - }, { - key: "unmute", - value: function unmute() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { - audio: true, - video: true - }; - debug('unmute()'); - var audioUnMuted = false, - videoUnMuted = false; - - if (this._audioMuted === true && options.audio) { - audioUnMuted = true; - this._audioMuted = false; - - if (this._localHold === false) { - this._toggleMuteAudio(false); - } - } - - if (this._videoMuted === true && options.video) { - videoUnMuted = true; - this._videoMuted = false; - - if (this._localHold === false) { - this._toggleMuteVideo(false); - } - } - - if (audioUnMuted === true || videoUnMuted === true) { - this._onunmute({ - audio: audioUnMuted, - video: videoUnMuted - }); - } - } - /** - * Hold - */ - - }, { - key: "hold", - value: function hold() { - var _this6 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var done = arguments.length > 1 ? arguments[1] : undefined; - debug('hold()'); - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (this._localHold === true) { - return false; - } - - if (!this._isReadyToReOffer()) { - return false; - } - - this._localHold = true; - - this._onhold('local'); - - var eventHandlers = { - succeeded: function succeeded() { - if (done) { - done(); - } - }, - failed: function failed() { - _this6.terminate({ - cause: JsSIP_C.causes.WEBRTC_ERROR, - status_code: 500, - reason_phrase: 'Hold Failed' - }); - } - }; - - if (options.useUpdate) { - this._sendUpdate({ - sdpOffer: true, - eventHandlers: eventHandlers, - extraHeaders: options.extraHeaders - }); - } else { - this._sendReinvite({ - eventHandlers: eventHandlers, - extraHeaders: options.extraHeaders - }); - } - - return true; - } - }, { - key: "unhold", - value: function unhold() { - var _this7 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var done = arguments.length > 1 ? arguments[1] : undefined; - debug('unhold()'); - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (this._localHold === false) { - return false; - } - - if (!this._isReadyToReOffer()) { - return false; - } - - this._localHold = false; - - this._onunhold('local'); - - var eventHandlers = { - succeeded: function succeeded() { - if (done) { - done(); - } - }, - failed: function failed() { - _this7.terminate({ - cause: JsSIP_C.causes.WEBRTC_ERROR, - status_code: 500, - reason_phrase: 'Unhold Failed' - }); - } - }; - - if (options.useUpdate) { - this._sendUpdate({ - sdpOffer: true, - eventHandlers: eventHandlers, - extraHeaders: options.extraHeaders - }); - } else { - this._sendReinvite({ - eventHandlers: eventHandlers, - extraHeaders: options.extraHeaders - }); - } - - return true; - } - }, { - key: "renegotiate", - value: function renegotiate() { - var _this8 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var done = arguments.length > 1 ? arguments[1] : undefined; - debug('renegotiate()'); - var rtcOfferConstraints = options.rtcOfferConstraints || null; - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (!this._isReadyToReOffer()) { - return false; - } - - var eventHandlers = { - succeeded: function succeeded() { - if (done) { - done(); - } - }, - failed: function failed() { - _this8.terminate({ - cause: JsSIP_C.causes.WEBRTC_ERROR, - status_code: 500, - reason_phrase: 'Media Renegotiation Failed' - }); - } - }; - - this._setLocalMediaStatus(); - - if (options.useUpdate) { - this._sendUpdate({ - sdpOffer: true, - eventHandlers: eventHandlers, - rtcOfferConstraints: rtcOfferConstraints, - extraHeaders: options.extraHeaders - }); - } else { - this._sendReinvite({ - eventHandlers: eventHandlers, - rtcOfferConstraints: rtcOfferConstraints, - extraHeaders: options.extraHeaders - }); - } - - return true; - } - /** - * Refer - */ - - }, { - key: "refer", - value: function refer(target, options) { - var _this9 = this; - - debug('refer()'); - var originalTarget = target; - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } // Check target validity. - - - target = this._ua.normalizeTarget(target); - - if (!target) { - throw new TypeError("Invalid target: ".concat(originalTarget)); - } - - var referSubscriber = new RTCSession_ReferSubscriber(this); - referSubscriber.sendRefer(target, options); // Store in the map. - - var id = referSubscriber.id; - this._referSubscribers[id] = referSubscriber; // Listen for ending events so we can remove it from the map. - - referSubscriber.on('requestFailed', function () { - delete _this9._referSubscribers[id]; - }); - referSubscriber.on('accepted', function () { - delete _this9._referSubscribers[id]; - }); - referSubscriber.on('failed', function () { - delete _this9._referSubscribers[id]; - }); - return referSubscriber; - } - /** - * Send a generic in-dialog Request - */ - - }, { - key: "sendRequest", - value: function sendRequest(method, options) { - debug('sendRequest()'); - return this._dialog.sendRequest(method, options); - } - /** - * In dialog Request Reception - */ - - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - var _this10 = this; - - debug('receiveRequest()'); - - if (request.method === JsSIP_C.CANCEL) { - /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL - * was in progress and that the UAC MAY continue with the session established by - * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the - * established session. So the CANCEL is processed only if the session is not yet - * established. - */ - - /* - * Terminate the whole session in case the user didn't accept (or yet send the answer) - * nor reject the request opening the session. - */ - if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) { - this._status = C.STATUS_CANCELED; - - this._request.reply(487); - - this._failed('remote', request, JsSIP_C.causes.CANCELED); - } - } else { - // Requests arriving here are in-dialog requests. - switch (request.method) { - case JsSIP_C.ACK: - if (this._status !== C.STATUS_WAITING_FOR_ACK) { - return; - } // Update signaling status. - - - this._status = C.STATUS_CONFIRMED; - clearTimeout(this._timers.ackTimer); - clearTimeout(this._timers.invite2xxTimer); - - if (this._late_sdp) { - if (!request.body) { - this.terminate({ - cause: JsSIP_C.causes.MISSING_SDP, - status_code: 400 - }); - break; - } - - var e = { - originator: 'remote', - type: 'answer', - sdp: request.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var answer = new RTCSessionDescription({ - type: 'answer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this10._connection.setRemoteDescription(answer); - }).then(function () { - if (!_this10._is_confirmed) { - _this10._confirmed('remote', request); - } - })["catch"](function (error) { - _this10.terminate({ - cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION, - status_code: 488 - }); - - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this10.emit('peerconnection:setremotedescriptionfailed', error); - }); - } else if (!this._is_confirmed) { - this._confirmed('remote', request); - } - - break; - - case JsSIP_C.BYE: - if (this._status === C.STATUS_CONFIRMED || this._status === C.STATUS_WAITING_FOR_ACK) { - request.reply(200); - - this._ended('remote', request, JsSIP_C.causes.BYE); - } else if (this._status === C.STATUS_INVITE_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER) { - request.reply(200); - - this._request.reply(487, 'BYE Received'); - - this._ended('remote', request, JsSIP_C.causes.BYE); - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.INVITE: - if (this._status === C.STATUS_CONFIRMED) { - if (request.hasHeader('replaces')) { - this._receiveReplaces(request); - } else { - this._receiveReinvite(request); - } - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.INFO: - if (this._status === C.STATUS_1XX_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED || this._status === C.STATUS_WAITING_FOR_ACK || this._status === C.STATUS_CONFIRMED) { - var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; - - if (contentType && contentType.match(/^application\/dtmf-relay/i)) { - new RTCSession_DTMF(this).init_incoming(request); - } else if (contentType !== undefined) { - new RTCSession_Info(this).init_incoming(request); - } else { - request.reply(415); - } - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.UPDATE: - if (this._status === C.STATUS_CONFIRMED) { - this._receiveUpdate(request); - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.REFER: - if (this._status === C.STATUS_CONFIRMED) { - this._receiveRefer(request); - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.NOTIFY: - if (this._status === C.STATUS_CONFIRMED) { - this._receiveNotify(request); - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - default: - request.reply(501); - } - } - } - /** - * Session Callbacks - */ - - }, { - key: "onTransportError", - value: function onTransportError() { - debugerror('onTransportError()'); - - if (this._status !== C.STATUS_TERMINATED) { - this.terminate({ - status_code: 500, - reason_phrase: JsSIP_C.causes.CONNECTION_ERROR, - cause: JsSIP_C.causes.CONNECTION_ERROR - }); - } - } - }, { - key: "onRequestTimeout", - value: function onRequestTimeout() { - debugerror('onRequestTimeout()'); - - if (this._status !== C.STATUS_TERMINATED) { - this.terminate({ - status_code: 408, - reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT, - cause: JsSIP_C.causes.REQUEST_TIMEOUT - }); - } - } - }, { - key: "onDialogError", - value: function onDialogError() { - debugerror('onDialogError()'); - - if (this._status !== C.STATUS_TERMINATED) { - this.terminate({ - status_code: 500, - reason_phrase: JsSIP_C.causes.DIALOG_ERROR, - cause: JsSIP_C.causes.DIALOG_ERROR - }); - } - } // Called from DTMF handler. - - }, { - key: "newDTMF", - value: function newDTMF(data) { - debug('newDTMF()'); - this.emit('newDTMF', data); - } // Called from Info handler. - - }, { - key: "newInfo", - value: function newInfo(data) { - debug('newInfo()'); - this.emit('newInfo', data); - } - /** - * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP. - */ - - }, { - key: "_isReadyToReOffer", - value: function _isReadyToReOffer() { - if (!this._rtcReady) { - debug('_isReadyToReOffer() | internal WebRTC status not ready'); - return false; - } // No established yet. - - - if (!this._dialog) { - debug('_isReadyToReOffer() | session not established yet'); - return false; - } // Another INVITE transaction is in progress. - - - if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { - debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); - return false; - } - - return true; - } - }, { - key: "_close", - value: function _close() { - debug('close()'); // Close local MediaStream if it was not given by the user. - - if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { - debug('close() | closing local MediaStream'); - Utils.closeMediaStream(this._localMediaStream); - } - - if (this._status === C.STATUS_TERMINATED) { - return; - } - - this._status = C.STATUS_TERMINATED; // Terminate RTC. - - if (this._connection) { - try { - this._connection.close(); - } catch (error) { - debugerror('close() | error closing the RTCPeerConnection: %o', error); - } - } // Terminate signaling. - // Clear SIP timers. - - - for (var timer in this._timers) { - if (Object.prototype.hasOwnProperty.call(this._timers, timer)) { - clearTimeout(this._timers[timer]); - } - } // Clear Session Timers. - - - clearTimeout(this._sessionTimers.timer); // Terminate confirmed dialog. - - if (this._dialog) { - this._dialog.terminate(); - - delete this._dialog; - } // Terminate early dialogs. - - - for (var dialog in this._earlyDialogs) { - if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) { - this._earlyDialogs[dialog].terminate(); - - delete this._earlyDialogs[dialog]; - } - } // Terminate REFER subscribers. - - - for (var subscriber in this._referSubscribers) { - if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) { - delete this._referSubscribers[subscriber]; - } - } - - this._ua.destroyRTCSession(this); - } - /** - * Private API. - */ - - /** - * RFC3261 13.3.1.4 - * Response retransmissions cannot be accomplished by transaction layer - * since it is destroyed when receiving the first 2xx answer - */ - - }, { - key: "_setInvite2xxTimer", - value: function _setInvite2xxTimer(request, body) { - var timeout = Timers.T1; - - function invite2xxRetransmission() { - if (this._status !== C.STATUS_WAITING_FOR_ACK) { - return; - } - - request.reply(200, null, ["Contact: ".concat(this._contact)], body); - - if (timeout < Timers.T2) { - timeout = timeout * 2; - - if (timeout > Timers.T2) { - timeout = Timers.T2; - } - } - - this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout); - } - - this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout); - } - /** - * RFC3261 14.2 - * If a UAS generates a 2xx response and never receives an ACK, - * it SHOULD generate a BYE to terminate the dialog. - */ - - }, { - key: "_setACKTimer", - value: function _setACKTimer() { - var _this11 = this; - - this._timers.ackTimer = setTimeout(function () { - if (_this11._status === C.STATUS_WAITING_FOR_ACK) { - debug('no ACK received, terminating the session'); - clearTimeout(_this11._timers.invite2xxTimer); - - _this11.sendRequest(JsSIP_C.BYE); - - _this11._ended('remote', null, JsSIP_C.causes.NO_ACK); - } - }, Timers.TIMER_H); - } - }, { - key: "_createRTCConnection", - value: function _createRTCConnection(pcConfig, rtcConstraints) { - var _this12 = this; - - this._connection = new RTCPeerConnection(pcConfig, rtcConstraints); - - this._connection.addEventListener('iceconnectionstatechange', function () { - var state = _this12._connection.iceConnectionState; // TODO: Do more with different states. - - if (state === 'failed') { - _this12.terminate({ - cause: JsSIP_C.causes.RTP_TIMEOUT, - status_code: 408, - reason_phrase: JsSIP_C.causes.RTP_TIMEOUT - }); - } - }); - - debug('emit "peerconnection"'); - this.emit('peerconnection', { - peerconnection: this._connection - }); - } - }, { - key: "_createLocalDescription", - value: function _createLocalDescription(type, constraints) { - var _this13 = this; - - debug('createLocalDescription()'); - if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\"")); - var connection = this._connection; - this._rtcReady = false; - return Promise.resolve() // Create Offer or Answer. - .then(function () { - if (type === 'offer') { - return connection.createOffer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); - - _this13.emit('peerconnection:createofferfailed', error); - - return Promise.reject(error); - }); - } else { - return connection.createAnswer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); - - _this13.emit('peerconnection:createanswerfailed', error); - - return Promise.reject(error); - }); - } - }) // Set local description. - .then(function (desc) { - return connection.setLocalDescription(desc)["catch"](function (error) { - _this13._rtcReady = true; - debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); - - _this13.emit('peerconnection:setlocaldescriptionfailed', error); - - return Promise.reject(error); - }); - }).then(function () { - // Resolve right away if 'pc.iceGatheringState' is 'complete'. - if (connection.iceGatheringState === 'complete' && (!constraints || !constraints.iceRestart)) { - _this13._rtcReady = true; - var e = { - originator: 'local', - type: type, - sdp: connection.localDescription.sdp - }; - debug('emit "sdp"'); - - _this13.emit('sdp', e); - - return Promise.resolve(e.sdp); - } // Add 'pc.onicencandidate' event handler to resolve on last candidate. - - - return new Promise(function (resolve) { - var finished = false; - var iceCandidateListener; - var iceGatheringStateListener; - - var ready = function ready() { - connection.removeEventListener('icecandidate', iceCandidateListener); - connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener); - finished = true; - _this13._rtcReady = true; - var e = { - originator: 'local', - type: type, - sdp: connection.localDescription.sdp - }; - debug('emit "sdp"'); - - _this13.emit('sdp', e); - - resolve(e.sdp); - }; - - connection.addEventListener('icecandidate', iceCandidateListener = function iceCandidateListener(event) { - var candidate = event.candidate; - - if (candidate) { - _this13.emit('icecandidate', { - candidate: candidate, - ready: ready - }); - } else if (!finished) { - ready(); - } - }); - connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = function iceGatheringStateListener() { - if (connection.iceGatheringState === 'complete' && !finished) { - ready(); - } - }); - }); - }); - } - /** - * Dialog Management - */ - - }, { - key: "_createDialog", - value: function _createDialog(message, type, early) { - var local_tag = type === 'UAS' ? message.to_tag : message.from_tag; - var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag; - var id = message.call_id + local_tag + remote_tag; - var early_dialog = this._earlyDialogs[id]; // Early Dialog. - - if (early) { - if (early_dialog) { - return true; - } else { - early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created. - - if (early_dialog.error) { - debug(early_dialog.error); - - this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); - - return false; - } else { - this._earlyDialogs[id] = early_dialog; - return true; - } - } - } // Confirmed Dialog. - else { - this._from_tag = message.from_tag; - this._to_tag = message.to_tag; // In case the dialog is in _early_ state, update it. - - if (early_dialog) { - early_dialog.update(message, type); - this._dialog = early_dialog; - delete this._earlyDialogs[id]; - return true; - } // Otherwise, create a _confirmed_ dialog. - - - var dialog = new Dialog(this, message, type); - - if (dialog.error) { - debug(dialog.error); - - this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); - - return false; - } else { - this._dialog = dialog; - return true; - } - } - } - /** - * In dialog INVITE Reception - */ - - }, { - key: "_receiveReinvite", - value: function _receiveReinvite(request) { - var _this14 = this; - - debug('receiveReinvite()'); - var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; - var data = { - request: request, - callback: undefined, - reject: reject.bind(this) - }; - var rejected = false; - - function reject() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - rejected = true; - var status_code = options.status_code || 403; - var reason_phrase = options.reason_phrase || ''; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - - if (this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (status_code < 300 || status_code >= 700) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } - - request.reply(status_code, reason_phrase, extraHeaders); - } // Emit 'reinvite'. - - - this.emit('reinvite', data); - - if (rejected) { - return; - } - - this._late_sdp = false; // Request without SDP. - - if (!request.body) { - this._late_sdp = true; - - if (this._remoteHold) { - this._remoteHold = false; - - this._onunhold('remote'); - } - - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this14._createLocalDescription('offer', _this14._rtcOfferConstraints); - }).then(function (sdp) { - sendAnswer.call(_this14, sdp); - })["catch"](function () { - request.reply(500); - }); - return; - } // Request with SDP. - - - if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); - request.reply(415); - return; - } - - this._processInDialogSdpOffer(request) // Send answer. - .then(function (desc) { - if (_this14._status === C.STATUS_TERMINATED) { - return; - } - - sendAnswer.call(_this14, desc); - })["catch"](function (error) { - debugerror(error); - }); - - function sendAnswer(desc) { - var _this15 = this; - - var extraHeaders = ["Contact: ".concat(this._contact)]; - - this._handleSessionTimersInIncomingRequest(request, extraHeaders); - - if (this._late_sdp) { - desc = this._mangleOffer(desc); - } - - request.reply(200, null, extraHeaders, desc, function () { - _this15._status = C.STATUS_WAITING_FOR_ACK; - - _this15._setInvite2xxTimer(request, desc); - - _this15._setACKTimer(); - }); // If callback is given execute it. - - if (typeof data.callback === 'function') { - data.callback(); - } - } - } - /** - * In dialog UPDATE Reception - */ - - }, { - key: "_receiveUpdate", - value: function _receiveUpdate(request) { - var _this16 = this; - - debug('receiveUpdate()'); - var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; - var data = { - request: request, - callback: undefined, - reject: reject.bind(this) - }; - var rejected = false; - - function reject() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - rejected = true; - var status_code = options.status_code || 403; - var reason_phrase = options.reason_phrase || ''; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - - if (this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (status_code < 300 || status_code >= 700) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } - - request.reply(status_code, reason_phrase, extraHeaders); - } // Emit 'update'. - - - this.emit('update', data); - - if (rejected) { - return; - } - - if (!request.body) { - sendAnswer.call(this, null); - return; - } - - if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); - request.reply(415); - return; - } - - this._processInDialogSdpOffer(request) // Send answer. - .then(function (desc) { - if (_this16._status === C.STATUS_TERMINATED) { - return; - } - - sendAnswer.call(_this16, desc); - })["catch"](function (error) { - debugerror(error); - }); - - function sendAnswer(desc) { - var extraHeaders = ["Contact: ".concat(this._contact)]; - - this._handleSessionTimersInIncomingRequest(request, extraHeaders); - - request.reply(200, null, extraHeaders, desc); // If callback is given execute it. - - if (typeof data.callback === 'function') { - data.callback(); - } - } - } - }, { - key: "_processInDialogSdpOffer", - value: function _processInDialogSdpOffer(request) { - var _this17 = this; - - debug('_processInDialogSdpOffer()'); - var sdp = request.parseSDP(); - var hold = false; - - var _iterator4 = _createForOfIteratorHelper(sdp.media), - _step4; - - try { - for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - var m = _step4.value; - - if (holdMediaTypes.indexOf(m.type) === -1) { - continue; - } - - var direction = m.direction || sdp.direction || 'sendrecv'; - - if (direction === 'sendonly' || direction === 'inactive') { - hold = true; - } // If at least one of the streams is active don't emit 'hold'. - else { - hold = false; - break; - } - } - } catch (err) { - _iterator4.e(err); - } finally { - _iterator4.f(); - } - - var e = { - originator: 'remote', - type: 'offer', - sdp: request.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var offer = new RTCSessionDescription({ - type: 'offer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue // Set remote description. - .then(function () { - if (_this17._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - return _this17._connection.setRemoteDescription(offer)["catch"](function (error) { - request.reply(488); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this17.emit('peerconnection:setremotedescriptionfailed', error); - - throw error; - }); - }).then(function () { - if (_this17._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - if (_this17._remoteHold === true && hold === false) { - _this17._remoteHold = false; - - _this17._onunhold('remote'); - } else if (_this17._remoteHold === false && hold === true) { - _this17._remoteHold = true; - - _this17._onhold('remote'); - } - }) // Create local description. - .then(function () { - if (_this17._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) { - request.reply(500); - debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); - throw error; - }); - })["catch"](function (error) { - debugerror('_processInDialogSdpOffer() failed [error: %o]', error); - }); - return this._connectionPromiseQueue; - } - /** - * In dialog Refer Reception - */ - - }, { - key: "_receiveRefer", - value: function _receiveRefer(request) { - var _this18 = this; - - debug('receiveRefer()'); - - if (!request.refer_to) { - debug('no Refer-To header field present in REFER'); - request.reply(400); - return; - } - - if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { - debug('Refer-To header field points to a non-SIP URI scheme'); - request.reply(416); - return; - } // Reply before the transaction timer expires. - - - request.reply(202); - var notifier = new RTCSession_ReferNotifier(this, request.cseq); - debug('emit "refer"'); // Emit 'refer'. - - this.emit('refer', { - request: request, - accept: function accept(initCallback, options) { - _accept.call(_this18, initCallback, options); - }, - reject: function reject() { - _reject.call(_this18); - } - }); - - function _accept(initCallback) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - initCallback = typeof initCallback === 'function' ? initCallback : null; - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - var session = new RTCSession(this._ua); - session.on('progress', function (_ref2) { - var response = _ref2.response; - notifier.notify(response.status_code, response.reason_phrase); - }); - session.on('accepted', function (_ref3) { - var response = _ref3.response; - notifier.notify(response.status_code, response.reason_phrase); - }); - session.on('_failed', function (_ref4) { - var message = _ref4.message, - cause = _ref4.cause; - - if (message) { - notifier.notify(message.status_code, message.reason_phrase); - } else { - notifier.notify(487, cause); - } - }); // Consider the Replaces header present in the Refer-To URI. - - if (request.refer_to.uri.hasHeader('replaces')) { - var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces')); - options.extraHeaders = Utils.cloneArray(options.extraHeaders); - options.extraHeaders.push("Replaces: ".concat(replaces)); - } - - session.connect(request.refer_to.uri.toAor(), options, initCallback); - } - - function _reject() { - notifier.notify(603); - } - } - /** - * In dialog Notify Reception - */ - - }, { - key: "_receiveNotify", - value: function _receiveNotify(request) { - debug('receiveNotify()'); - - if (!request.event) { - request.reply(400); - } - - switch (request.event.event) { - case 'refer': - { - var id; - var referSubscriber; - - if (request.event.params && request.event.params.id) { - id = request.event.params.id; - referSubscriber = this._referSubscribers[id]; - } else if (Object.keys(this._referSubscribers).length === 1) { - referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]]; - } else { - request.reply(400, 'Missing event id parameter'); - return; - } - - if (!referSubscriber) { - request.reply(481, 'Subscription does not exist'); - return; - } - - referSubscriber.receiveNotify(request); - request.reply(200); - break; - } - - default: - { - request.reply(489); - } - } - } - /** - * INVITE with Replaces Reception - */ - - }, { - key: "_receiveReplaces", - value: function _receiveReplaces(request) { - var _this20 = this; - - debug('receiveReplaces()'); - - function _accept2(initCallback) { - var _this19 = this; - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - var session = new RTCSession(this._ua); // Terminate the current session when the new one is confirmed. - - session.on('confirmed', function () { - _this19.terminate(); - }); - session.init_incoming(request, initCallback); - } - - function _reject2() { - debug('Replaced INVITE rejected by the user'); - request.reply(486); - } // Emit 'replace'. - - - this.emit('replaces', { - request: request, - accept: function accept(initCallback) { - _accept2.call(_this20, initCallback); - }, - reject: function reject() { - _reject2.call(_this20); - } - }); - } - /** - * Initial Request Sender - */ - - }, { - key: "_sendInitialRequest", - value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) { - var _this21 = this; - - var request_sender = new RequestSender(this._ua, this._request, { - onRequestTimeout: function onRequestTimeout() { - _this21.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this21.onTransportError(); - }, - // Update the request on authentication. - onAuthenticated: function onAuthenticated(request) { - _this21._request = request; - }, - onReceiveResponse: function onReceiveResponse(response) { - _this21._receiveInviteResponse(response); - } - }); // This Promise is resolved within the next iteration, so the app has now - // a chance to set events such as 'peerconnection' and 'connecting'. - - Promise.resolve() // Get a stream if required. - .then(function () { - // A stream is given, let the app set events such as 'peerconnection' and 'connecting'. - if (mediaStream) { - return mediaStream; - } // Request for user media access. - else if (mediaConstraints.audio || mediaConstraints.video) { - _this21._localMediaStreamLocallyGenerated = true; - return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) { - if (_this21._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - - debugerror('emit "getusermediafailed" [error:%o]', error); - - _this21.emit('getusermediafailed', error); - - throw error; - }); - } - }).then(function (stream) { - if (_this21._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this21._localMediaStream = stream; - - if (stream) { - stream.getTracks().forEach(function (track) { - _this21._connection.addTrack(track, stream); - }); - } // TODO: should this be triggered here? - - - _this21._connecting(_this21._request); - - return _this21._createLocalDescription('offer', rtcOfferConstraints)["catch"](function (error) { - _this21._failed('local', null, JsSIP_C.causes.WEBRTC_ERROR); - - throw error; - }); - }).then(function (desc) { - if (_this21._is_canceled || _this21._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this21._request.body = desc; - _this21._status = C.STATUS_INVITE_SENT; - debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. - - _this21.emit('sending', { - request: _this21._request - }); - - request_sender.send(); - })["catch"](function (error) { - if (_this21._status === C.STATUS_TERMINATED) { - return; - } - - debugerror(error); - }); - } - /** - * Get DTMF RTCRtpSender. - */ - - }, { - key: "_getDTMFRTPSender", - value: function _getDTMFRTPSender() { - var sender = this._connection.getSenders().find(function (rtpSender) { - return rtpSender.track && rtpSender.track.kind === 'audio'; - }); - - if (!(sender && sender.dtmf)) { - debugerror('sendDTMF() | no local audio track to send DTMF with'); - return; - } - - return sender.dtmf; - } - /** - * Reception of Response for Initial INVITE - */ - - }, { - key: "_receiveInviteResponse", - value: function _receiveInviteResponse(response) { - var _this22 = this; - - debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. - - if (this._dialog && response.status_code >= 200 && response.status_code <= 299) { - /* - * If it is a retransmission from the endpoint that established - * the dialog, send an ACK - */ - if (this._dialog.id.call_id === response.call_id && this._dialog.id.local_tag === response.from_tag && this._dialog.id.remote_tag === response.to_tag) { - this.sendRequest(JsSIP_C.ACK); - return; - } // If not, send an ACK and terminate. - else { - var dialog = new Dialog(this, response, 'UAC'); - - if (dialog.error !== undefined) { - debug(dialog.error); - return; - } - - this.sendRequest(JsSIP_C.ACK); - this.sendRequest(JsSIP_C.BYE); - return; - } - } // Proceed to cancellation if the user requested. - - - if (this._is_canceled) { - if (response.status_code >= 100 && response.status_code < 200) { - this._request.cancel(this._cancel_reason); - } else if (response.status_code >= 200 && response.status_code < 299) { - this._acceptAndTerminate(response); - } - - return; - } - - if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) { - return; - } - - switch (true) { - case /^100$/.test(response.status_code): - this._status = C.STATUS_1XX_RECEIVED; - break; - - case /^1[0-9]{2}$/.test(response.status_code): - { - // Do nothing with 1xx responses without To tag. - if (!response.to_tag) { - debug('1xx response received without to tag'); - break; - } // Create Early Dialog if 1XX comes with contact. - - - if (response.hasHeader('contact')) { - // An error on dialog creation will fire 'failed' event. - if (!this._createDialog(response, 'UAC', true)) { - break; - } - } - - this._status = C.STATUS_1XX_RECEIVED; - - if (!response.body) { - this._progress('remote', response); - - break; - } - - var e = { - originator: 'remote', - type: 'answer', - sdp: response.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var answer = new RTCSessionDescription({ - type: 'answer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this22._connection.setRemoteDescription(answer); - }).then(function () { - return _this22._progress('remote', response); - })["catch"](function (error) { - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this22.emit('peerconnection:setremotedescriptionfailed', error); - }); - break; - } - - case /^2[0-9]{2}$/.test(response.status_code): - { - this._status = C.STATUS_CONFIRMED; - - if (!response.body) { - this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP); - - this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - - break; - } // An error on dialog creation will fire 'failed' event. - - - if (!this._createDialog(response, 'UAC')) { - break; - } - - var _e = { - originator: 'remote', - type: 'answer', - sdp: response.body - }; - debug('emit "sdp"'); - this.emit('sdp', _e); - - var _answer = new RTCSessionDescription({ - type: 'answer', - sdp: _e.sdp - }); - - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - // Be ready for 200 with SDP after a 180/183 with SDP. - // We created a SDP 'answer' for it, so check the current signaling state. - if (_this22._connection.signalingState === 'stable') { - return _this22._connection.createOffer(_this22._rtcOfferConstraints).then(function (offer) { - return _this22._connection.setLocalDescription(offer); - })["catch"](function (error) { - _this22._acceptAndTerminate(response, 500, error.toString()); - - _this22._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR); - }); - } - }).then(function () { - _this22._connection.setRemoteDescription(_answer).then(function () { - // Handle Session Timers. - _this22._handleSessionTimersInIncomingResponse(response); - - _this22._accepted('remote', response); - - _this22.sendRequest(JsSIP_C.ACK); - - _this22._confirmed('local', null); - })["catch"](function (error) { - _this22._acceptAndTerminate(response, 488, 'Not Acceptable Here'); - - _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this22.emit('peerconnection:setremotedescriptionfailed', error); - }); - }); - break; - } - - default: - { - var cause = Utils.sipErrorCause(response.status_code); - - this._failed('remote', response, cause); - } - } - } - /** - * Send Re-INVITE - */ - - }, { - key: "_sendReinvite", - value: function _sendReinvite() { - var _this23 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendReinvite()'); - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; - var succeeded = false; - extraHeaders.push("Contact: ".concat(this._contact)); - extraHeaders.push('Content-Type: application/sdp'); // Session Timers. - - if (this._sessionTimers.running) { - extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas')); - } - - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this23._createLocalDescription('offer', rtcOfferConstraints); - }).then(function (sdp) { - sdp = _this23._mangleOffer(sdp); - var e = { - originator: 'local', - type: 'offer', - sdp: sdp - }; - debug('emit "sdp"'); - - _this23.emit('sdp', e); - - _this23.sendRequest(JsSIP_C.INVITE, { - extraHeaders: extraHeaders, - body: sdp, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - onSucceeded.call(_this23, response); - succeeded = true; - }, - onErrorResponse: function onErrorResponse(response) { - onFailed.call(_this23, response); - }, - onTransportError: function onTransportError() { - _this23.onTransportError(); // Do nothing because session ends. - - }, - onRequestTimeout: function onRequestTimeout() { - _this23.onRequestTimeout(); // Do nothing because session ends. - - }, - onDialogError: function onDialogError() { - _this23.onDialogError(); // Do nothing because session ends. - - } - } - }); - })["catch"](function () { - onFailed(); - }); - - function onSucceeded(response) { - var _this24 = this; - - if (this._status === C.STATUS_TERMINATED) { - return; - } - - this.sendRequest(JsSIP_C.ACK); // If it is a 2XX retransmission exit now. - - if (succeeded) { - return; - } // Handle Session Timers. - - - this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer. - - - if (!response.body) { - onFailed.call(this); - return; - } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') { - onFailed.call(this); - return; - } - - var e = { - originator: 'remote', - type: 'answer', - sdp: response.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var answer = new RTCSessionDescription({ - type: 'answer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this24._connection.setRemoteDescription(answer); - }).then(function () { - if (eventHandlers.succeeded) { - eventHandlers.succeeded(response); - } - })["catch"](function (error) { - onFailed.call(_this24); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this24.emit('peerconnection:setremotedescriptionfailed', error); - }); - } - - function onFailed(response) { - if (eventHandlers.failed) { - eventHandlers.failed(response); - } - } - } - /** - * Send UPDATE - */ - - }, { - key: "_sendUpdate", - value: function _sendUpdate() { - var _this25 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendUpdate()'); - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; - var sdpOffer = options.sdpOffer || false; - var succeeded = false; - extraHeaders.push("Contact: ".concat(this._contact)); // Session Timers. - - if (this._sessionTimers.running) { - extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas')); - } - - if (sdpOffer) { - extraHeaders.push('Content-Type: application/sdp'); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this25._createLocalDescription('offer', rtcOfferConstraints); - }).then(function (sdp) { - sdp = _this25._mangleOffer(sdp); - var e = { - originator: 'local', - type: 'offer', - sdp: sdp - }; - debug('emit "sdp"'); - - _this25.emit('sdp', e); - - _this25.sendRequest(JsSIP_C.UPDATE, { - extraHeaders: extraHeaders, - body: sdp, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - onSucceeded.call(_this25, response); - succeeded = true; - }, - onErrorResponse: function onErrorResponse(response) { - onFailed.call(_this25, response); - }, - onTransportError: function onTransportError() { - _this25.onTransportError(); // Do nothing because session ends. - - }, - onRequestTimeout: function onRequestTimeout() { - _this25.onRequestTimeout(); // Do nothing because session ends. - - }, - onDialogError: function onDialogError() { - _this25.onDialogError(); // Do nothing because session ends. - - } - } - }); - })["catch"](function () { - onFailed.call(_this25); - }); - } // No SDP. - else { - this.sendRequest(JsSIP_C.UPDATE, { - extraHeaders: extraHeaders, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - onSucceeded.call(_this25, response); - }, - onErrorResponse: function onErrorResponse(response) { - onFailed.call(_this25, response); - }, - onTransportError: function onTransportError() { - _this25.onTransportError(); // Do nothing because session ends. - - }, - onRequestTimeout: function onRequestTimeout() { - _this25.onRequestTimeout(); // Do nothing because session ends. - - }, - onDialogError: function onDialogError() { - _this25.onDialogError(); // Do nothing because session ends. - - } - } - }); - } - - function onSucceeded(response) { - var _this26 = this; - - if (this._status === C.STATUS_TERMINATED) { - return; - } // If it is a 2XX retransmission exit now. - - - if (succeeded) { - return; - } // Handle Session Timers. - - - this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer. - - - if (sdpOffer) { - if (!response.body) { - onFailed.call(this); - return; - } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') { - onFailed.call(this); - return; - } - - var e = { - originator: 'remote', - type: 'answer', - sdp: response.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var answer = new RTCSessionDescription({ - type: 'answer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this26._connection.setRemoteDescription(answer); - }).then(function () { - if (eventHandlers.succeeded) { - eventHandlers.succeeded(response); - } - })["catch"](function (error) { - onFailed.call(_this26); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this26.emit('peerconnection:setremotedescriptionfailed', error); - }); - } // No SDP answer. - else if (eventHandlers.succeeded) { - eventHandlers.succeeded(response); - } - } - - function onFailed(response) { - if (eventHandlers.failed) { - eventHandlers.failed(response); - } - } - } - }, { - key: "_acceptAndTerminate", - value: function _acceptAndTerminate(response, status_code, reason_phrase) { - debug('acceptAndTerminate()'); - var extraHeaders = []; - - if (status_code) { - reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; - extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\"")); - } // An error on dialog creation will fire 'failed' event. - - - if (this._dialog || this._createDialog(response, 'UAC')) { - this.sendRequest(JsSIP_C.ACK); - this.sendRequest(JsSIP_C.BYE, { - extraHeaders: extraHeaders - }); - } // Update session status. - - - this._status = C.STATUS_TERMINATED; - } - /** - * Correctly set the SDP direction attributes if the call is on local hold - */ - - }, { - key: "_mangleOffer", - value: function _mangleOffer(sdp) { - if (!this._localHold && !this._remoteHold) { - return sdp; - } - - sdp = sdp_transform.parse(sdp); // Local hold. - - if (this._localHold && !this._remoteHold) { - debug('mangleOffer() | me on hold, mangling offer'); - - var _iterator5 = _createForOfIteratorHelper(sdp.media), - _step5; - - try { - for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { - var m = _step5.value; - - if (holdMediaTypes.indexOf(m.type) === -1) { - continue; - } - - if (!m.direction) { - m.direction = 'sendonly'; - } else if (m.direction === 'sendrecv') { - m.direction = 'sendonly'; - } else if (m.direction === 'recvonly') { - m.direction = 'inactive'; - } - } - } catch (err) { - _iterator5.e(err); - } finally { - _iterator5.f(); - } - } // Local and remote hold. - else if (this._localHold && this._remoteHold) { - debug('mangleOffer() | both on hold, mangling offer'); - - var _iterator6 = _createForOfIteratorHelper(sdp.media), - _step6; - - try { - for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { - var _m = _step6.value; - - if (holdMediaTypes.indexOf(_m.type) === -1) { - continue; - } - - _m.direction = 'inactive'; - } - } catch (err) { - _iterator6.e(err); - } finally { - _iterator6.f(); - } - } // Remote hold. - else if (this._remoteHold) { - debug('mangleOffer() | remote on hold, mangling offer'); - - var _iterator7 = _createForOfIteratorHelper(sdp.media), - _step7; - - try { - for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { - var _m2 = _step7.value; - - if (holdMediaTypes.indexOf(_m2.type) === -1) { - continue; - } - - if (!_m2.direction) { - _m2.direction = 'recvonly'; - } else if (_m2.direction === 'sendrecv') { - _m2.direction = 'recvonly'; - } else if (_m2.direction === 'recvonly') { - _m2.direction = 'inactive'; - } - } - } catch (err) { - _iterator7.e(err); - } finally { - _iterator7.f(); - } - } - - return sdp_transform.write(sdp); - } - }, { - key: "_setLocalMediaStatus", - value: function _setLocalMediaStatus() { - var enableAudio = true, - enableVideo = true; - - if (this._localHold || this._remoteHold) { - enableAudio = false; - enableVideo = false; - } - - if (this._audioMuted) { - enableAudio = false; - } - - if (this._videoMuted) { - enableVideo = false; - } - - this._toggleMuteAudio(!enableAudio); - - this._toggleMuteVideo(!enableVideo); - } - /** - * Handle SessionTimers for an incoming INVITE or UPDATE. - * @param {IncomingRequest} request - * @param {Array} responseExtraHeaders Extra headers for the 200 response. - */ - - }, { - key: "_handleSessionTimersInIncomingRequest", - value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) { - if (!this._sessionTimers.enabled) { - return; - } - - var session_expires_refresher; - - if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) { - this._sessionTimers.currentExpires = request.session_expires; - session_expires_refresher = request.session_expires_refresher || 'uas'; - } else { - this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires; - session_expires_refresher = 'uas'; - } - - responseExtraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(session_expires_refresher)); - this._sessionTimers.refresher = session_expires_refresher === 'uas'; - - this._runSessionTimer(); - } - /** - * Handle SessionTimers for an incoming response to INVITE or UPDATE. - * @param {IncomingResponse} response - */ - - }, { - key: "_handleSessionTimersInIncomingResponse", - value: function _handleSessionTimersInIncomingResponse(response) { - if (!this._sessionTimers.enabled) { - return; - } - - var session_expires_refresher; - - if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) { - this._sessionTimers.currentExpires = response.session_expires; - session_expires_refresher = response.session_expires_refresher || 'uac'; - } else { - this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires; - session_expires_refresher = 'uac'; - } - - this._sessionTimers.refresher = session_expires_refresher === 'uac'; - - this._runSessionTimer(); - } - }, { - key: "_runSessionTimer", - value: function _runSessionTimer() { - var _this27 = this; - - var expires = this._sessionTimers.currentExpires; - this._sessionTimers.running = true; - clearTimeout(this._sessionTimers.timer); // I'm the refresher. - - if (this._sessionTimers.refresher) { - this._sessionTimers.timer = setTimeout(function () { - if (_this27._status === C.STATUS_TERMINATED) { - return; - } - - debug('runSessionTimer() | sending session refresh request'); - - if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { - _this27._sendUpdate(); - } else { - _this27._sendReinvite(); - } - }, expires * 500); // Half the given interval (as the RFC states). - } // I'm not the refresher. - else { - this._sessionTimers.timer = setTimeout(function () { - if (_this27._status === C.STATUS_TERMINATED) { - return; - } - - debugerror('runSessionTimer() | timer expired, terminating the session'); - - _this27.terminate({ - cause: JsSIP_C.causes.REQUEST_TIMEOUT, - status_code: 408, - reason_phrase: 'Session Timer Expired' - }); - }, expires * 1100); - } - } - }, { - key: "_toggleMuteAudio", - value: function _toggleMuteAudio(mute) { - var senders = this._connection.getSenders().filter(function (sender) { - return sender.track && sender.track.kind === 'audio'; - }); - - var _iterator8 = _createForOfIteratorHelper(senders), - _step8; - - try { - for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { - var sender = _step8.value; - sender.track.enabled = !mute; - } - } catch (err) { - _iterator8.e(err); - } finally { - _iterator8.f(); - } - } - }, { - key: "_toggleMuteVideo", - value: function _toggleMuteVideo(mute) { - var senders = this._connection.getSenders().filter(function (sender) { - return sender.track && sender.track.kind === 'video'; - }); - - var _iterator9 = _createForOfIteratorHelper(senders), - _step9; - - try { - for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { - var sender = _step9.value; - sender.track.enabled = !mute; - } - } catch (err) { - _iterator9.e(err); - } finally { - _iterator9.f(); - } - } - }, { - key: "_newRTCSession", - value: function _newRTCSession(originator, request) { - debug('newRTCSession()'); - - this._ua.newRTCSession(this, { - originator: originator, - session: this, - request: request - }); - } - }, { - key: "_connecting", - value: function _connecting(request) { - debug('session connecting'); - debug('emit "connecting"'); - this.emit('connecting', { - request: request - }); - } - }, { - key: "_progress", - value: function _progress(originator, response) { - debug('session progress'); - debug('emit "progress"'); - this.emit('progress', { - originator: originator, - response: response || null - }); - } - }, { - key: "_accepted", - value: function _accepted(originator, message) { - debug('session accepted'); - this._start_time = new Date(); - debug('emit "accepted"'); - this.emit('accepted', { - originator: originator, - response: message || null - }); - } - }, { - key: "_confirmed", - value: function _confirmed(originator, ack) { - debug('session confirmed'); - this._is_confirmed = true; - debug('emit "confirmed"'); - this.emit('confirmed', { - originator: originator, - ack: ack || null - }); - } - }, { - key: "_ended", - value: function _ended(originator, message, cause) { - debug('session ended'); - this._end_time = new Date(); - - this._close(); - - debug('emit "ended"'); - this.emit('ended', { - originator: originator, - message: message || null, - cause: cause - }); - } - }, { - key: "_failed", - value: function _failed(originator, message, cause) { - debug('session failed'); // Emit private '_failed' event first. - - debug('emit "_failed"'); - this.emit('_failed', { - originator: originator, - message: message || null, - cause: cause - }); - - this._close(); - - debug('emit "failed"'); - this.emit('failed', { - originator: originator, - message: message || null, - cause: cause - }); - } - }, { - key: "_onhold", - value: function _onhold(originator) { - debug('session onhold'); - - this._setLocalMediaStatus(); - - debug('emit "hold"'); - this.emit('hold', { - originator: originator - }); - } - }, { - key: "_onunhold", - value: function _onunhold(originator) { - debug('session onunhold'); - - this._setLocalMediaStatus(); - - debug('emit "unhold"'); - this.emit('unhold', { - originator: originator - }); - } - }, { - key: "_onmute", - value: function _onmute(_ref5) { - var audio = _ref5.audio, - video = _ref5.video; - debug('session onmute'); - - this._setLocalMediaStatus(); - - debug('emit "muted"'); - this.emit('muted', { - audio: audio, - video: video - }); - } - }, { - key: "_onunmute", - value: function _onunmute(_ref6) { - var audio = _ref6.audio, - video = _ref6.video; - debug('session onunmute'); - - this._setLocalMediaStatus(); - - debug('emit "unmuted"'); - this.emit('unmuted', { - audio: audio, - video: video - }); - } - }], [{ - key: "C", - get: - /** - * Expose C object. - */ - function get() { - return C; - } - }]); - - return RTCSession; -}(EventEmitter); -},{"./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(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('../Constants'); - -var Exceptions = require('../Exceptions'); - -var Utils = require('../Utils'); - -var debug = require('debug')('JsSIP:RTCSession:DTMF'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); - -debugerror.log = console.warn.bind(console); -var C = { - MIN_DURATION: 70, - MAX_DURATION: 6000, - DEFAULT_DURATION: 100, - MIN_INTER_TONE_GAP: 50, - DEFAULT_INTER_TONE_GAP: 500 -}; - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(DTMF, _EventEmitter); - - var _super = _createSuper(DTMF); - - function DTMF(session) { - var _this; - - _classCallCheck(this, DTMF); - - _this = _super.call(this); - _this._session = session; - _this._direction = null; - _this._tone = null; - _this._duration = null; - _this._request = null; - return _this; - } - - _createClass(DTMF, [{ - key: "tone", - get: function get() { - return this._tone; - } - }, { - key: "duration", - get: function get() { - return this._duration; - } - }, { - key: "send", - value: function send(tone) { - var _this2 = this; - - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - - if (tone === undefined) { - throw new TypeError('Not enough arguments'); - } - - this._direction = 'outgoing'; // Check RTCSession Status. - - if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) { - throw new Exceptions.InvalidStateError(this._session.status); - } - - var extraHeaders = Utils.cloneArray(options.extraHeaders); - this.eventHandlers = Utils.cloneObject(options.eventHandlers); // Check tone type. - - if (typeof tone === 'string') { - tone = tone.toUpperCase(); - } else if (typeof tone === 'number') { - tone = tone.toString(); - } else { - throw new TypeError("Invalid tone: ".concat(tone)); - } // Check tone value. - - - if (!tone.match(/^[0-9A-DR#*]$/)) { - throw new TypeError("Invalid tone: ".concat(tone)); - } else { - this._tone = tone; - } // Duration is checked/corrected in RTCSession. - - - this._duration = options.duration; - extraHeaders.push('Content-Type: application/dtmf-relay'); - var body = "Signal=".concat(this._tone, "\r\n"); - body += "Duration=".concat(this._duration); - - this._session.newDTMF({ - originator: 'local', - dtmf: this, - request: this._request - }); - - this._session.sendRequest(JsSIP_C.INFO, { - extraHeaders: extraHeaders, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - _this2.emit('succeeded', { - originator: 'remote', - response: response - }); - }, - onErrorResponse: function onErrorResponse(response) { - if (_this2.eventHandlers.onFailed) { - _this2.eventHandlers.onFailed(); - } - - _this2.emit('failed', { - originator: 'remote', - response: response - }); - }, - onRequestTimeout: function onRequestTimeout() { - _this2._session.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this2._session.onTransportError(); - }, - onDialogError: function onDialogError() { - _this2._session.onDialogError(); - } - }, - body: body - }); - } - }, { - key: "init_incoming", - value: function init_incoming(request) { - var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/; - var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/; - this._direction = 'incoming'; - this._request = request; - request.reply(200); - - if (request.body) { - var body = request.body.split('\n'); - - if (body.length >= 1) { - if (reg_tone.test(body[0])) { - this._tone = body[0].replace(reg_tone, '$2'); - } - } - - if (body.length >= 2) { - if (reg_duration.test(body[1])) { - this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10); - } - } - } - - if (!this._duration) { - this._duration = C.DEFAULT_DURATION; - } - - if (!this._tone) { - debug('invalid INFO DTMF received, discarded'); - } else { - this._session.newDTMF({ - originator: 'remote', - dtmf: this, - request: request - }); - } - } - }]); - - return DTMF; -}(EventEmitter); -/** - * Expose C object. - */ - - -module.exports.C = C; -},{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],14:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); - -debugerror.log = console.warn.bind(console); - -var JsSIP_C = require('../Constants'); - -var Exceptions = require('../Exceptions'); - -var Utils = require('../Utils'); - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(Info, _EventEmitter); - - var _super = _createSuper(Info); - - function Info(session) { - var _this; - - _classCallCheck(this, Info); - - _this = _super.call(this); - _this._session = session; - _this._direction = null; - _this._contentType = null; - _this._body = null; - return _this; - } - - _createClass(Info, [{ - key: "contentType", - get: function get() { - return this._contentType; - } - }, { - key: "body", - get: function get() { - return this._body; - } - }, { - key: "send", - value: function send(contentType, body) { - var _this2 = this; - - var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - this._direction = 'outgoing'; - - if (contentType === undefined) { - throw new TypeError('Not enough arguments'); - } // Check RTCSession Status. - - - if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) { - throw new Exceptions.InvalidStateError(this._session.status); - } - - this._contentType = contentType; - this._body = body; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - extraHeaders.push("Content-Type: ".concat(contentType)); - - this._session.newInfo({ - originator: 'local', - info: this, - request: this.request - }); - - this._session.sendRequest(JsSIP_C.INFO, { - extraHeaders: extraHeaders, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - _this2.emit('succeeded', { - originator: 'remote', - response: response - }); - }, - onErrorResponse: function onErrorResponse(response) { - _this2.emit('failed', { - originator: 'remote', - response: response - }); - }, - onTransportError: function onTransportError() { - _this2._session.onTransportError(); - }, - onRequestTimeout: function onRequestTimeout() { - _this2._session.onRequestTimeout(); - }, - onDialogError: function onDialogError() { - _this2._session.onDialogError(); - } - }, - body: body - }); - } - }, { - key: "init_incoming", - value: function init_incoming(request) { - this._direction = 'incoming'; - this.request = request; - request.reply(200); - this._contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; - this._body = request.body; - - this._session.newInfo({ - originator: 'remote', - info: this, - request: request - }); - } - }]); - - return Info; -}(EventEmitter); -},{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],15:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var JsSIP_C = require('../Constants'); - -var debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); - -var C = { - event_type: 'refer', - body_type: 'message/sipfrag;version=2.0', - expires: 300 -}; - -module.exports = /*#__PURE__*/function () { - function ReferNotifier(session, id, expires) { - _classCallCheck(this, ReferNotifier); - - this._session = session; - this._id = id; - this._expires = expires || C.expires; - this._active = true; // The creation of a Notifier results in an immediate NOTIFY. - - this.notify(100); - } - - _createClass(ReferNotifier, [{ - key: "notify", - value: function notify(code, reason) { - debug('notify()'); - - if (this._active === false) { - return; - } - - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - var state; - - if (code >= 200) { - state = 'terminated;reason=noresource'; - } else { - state = "active;expires=".concat(this._expires); - } // Put this in a try/catch block. - - - this._session.sendRequest(JsSIP_C.NOTIFY, { - extraHeaders: ["Event: ".concat(C.event_type, ";id=").concat(this._id), "Subscription-State: ".concat(state), "Content-Type: ".concat(C.body_type)], - body: "SIP/2.0 ".concat(code, " ").concat(reason), - eventHandlers: { - // If a negative response is received, subscription is canceled. - onErrorResponse: function onErrorResponse() { - this._active = false; - } - } - }); - } - }]); - - return ReferNotifier; -}(); -},{"../Constants":2,"debug":30}],16:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('../Constants'); - -var Grammar = require('../Grammar'); - -var Utils = require('../Utils'); - -var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(ReferSubscriber, _EventEmitter); - - var _super = _createSuper(ReferSubscriber); - - function ReferSubscriber(session) { - var _this; - - _classCallCheck(this, ReferSubscriber); - - _this = _super.call(this); - _this._id = null; - _this._session = session; - return _this; - } - - _createClass(ReferSubscriber, [{ - key: "id", - get: function get() { - return this._id; - } - }, { - key: "sendRefer", - value: function sendRefer(target) { - var _this2 = this; - - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendRefer()'); - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers. - - for (var event in eventHandlers) { - if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { - this.on(event, eventHandlers[event]); - } - } // Replaces URI header field. - - - var replaces = null; - - if (options.replaces) { - replaces = options.replaces._request.call_id; - replaces += ";to-tag=".concat(options.replaces._to_tag); - replaces += ";from-tag=".concat(options.replaces._from_tag); - replaces = encodeURIComponent(replaces); - } // Refer-To header field. - - - var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">"); - extraHeaders.push(referTo); // Referred-By header field. - - var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); - extraHeaders.push(referredBy); - extraHeaders.push("Contact: ".concat(this._session.contact)); - - var request = this._session.sendRequest(JsSIP_C.REFER, { - extraHeaders: extraHeaders, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - _this2._requestSucceeded(response); - }, - onErrorResponse: function onErrorResponse(response) { - _this2._requestFailed(response, JsSIP_C.causes.REJECTED); - }, - onTransportError: function onTransportError() { - _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR); - }, - onRequestTimeout: function onRequestTimeout() { - _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT); - }, - onDialogError: function onDialogError() { - _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR); - } - } - }); - - this._id = request.cseq; - } - }, { - key: "receiveNotify", - value: function receiveNotify(request) { - debug('receiveNotify()'); - - if (!request.body) { - return; - } - - var status_line = Grammar.parse(request.body.trim(), 'Status_Line'); - - if (status_line === -1) { - debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); - return; - } - - switch (true) { - case /^100$/.test(status_line.status_code): - this.emit('trying', { - request: request, - status_line: status_line - }); - break; - - case /^1[0-9]{2}$/.test(status_line.status_code): - this.emit('progress', { - request: request, - status_line: status_line - }); - break; - - case /^2[0-9]{2}$/.test(status_line.status_code): - this.emit('accepted', { - request: request, - status_line: status_line - }); - break; - - default: - this.emit('failed', { - request: request, - status_line: status_line - }); - break; - } - } - }, { - key: "_requestSucceeded", - value: function _requestSucceeded(response) { - debug('REFER succeeded'); - debug('emit "requestSucceeded"'); - this.emit('requestSucceeded', { - response: response - }); - } - }, { - key: "_requestFailed", - value: function _requestFailed(response, cause) { - debug('REFER failed'); - debug('emit "requestFailed"'); - this.emit('requestFailed', { - response: response || null, - cause: cause - }); - } - }]); - - return ReferSubscriber; -}(EventEmitter); -},{"../Constants":2,"../Grammar":7,"../Utils":26,"debug":30,"events":29}],17:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Utils = require('./Utils'); - -var JsSIP_C = require('./Constants'); - -var SIPMessage = require('./SIPMessage'); - -var RequestSender = require('./RequestSender'); - -var debug = require('debug')('JsSIP:Registrator'); - -var MIN_REGISTER_EXPIRES = 10; // In seconds. - -module.exports = /*#__PURE__*/function () { - function Registrator(ua, transport) { - _classCallCheck(this, Registrator); - - var reg_id = 1; // Force reg_id to 1. - - this._ua = ua; - this._transport = transport; - this._registrar = ua.configuration.registrar_server; - this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2. - - this._call_id = Utils.createRandomToken(22); - this._cseq = 0; - this._to_uri = ua.configuration.uri; - this._registrationTimer = null; // Ongoing Register request. - - this._registering = false; // Set status. - - this._registered = false; // Contact header. - - this._contact = this._ua.contact.toString(); // Sip.ice media feature tag (RFC 5768). - - this._contact += ';+sip.ice'; // Custom headers for REGISTER and un-REGISTER. - - this._extraHeaders = []; // Custom Contact header params for REGISTER and un-REGISTER. - - this._extraContactParams = ''; - - if (reg_id) { - this._contact += ";reg-id=".concat(reg_id); - this._contact += ";+sip.instance=\"\""); - } - } - - _createClass(Registrator, [{ - key: "registered", - get: function get() { - return this._registered; - } - }, { - key: "setExtraHeaders", - value: function setExtraHeaders(extraHeaders) { - if (!Array.isArray(extraHeaders)) { - extraHeaders = []; - } - - this._extraHeaders = extraHeaders.slice(); - } - }, { - key: "setExtraContactParams", - value: function setExtraContactParams(extraContactParams) { - if (!(extraContactParams instanceof Object)) { - extraContactParams = {}; - } // Reset it. - - - this._extraContactParams = ''; - - for (var param_key in extraContactParams) { - if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) { - var param_value = extraContactParams[param_key]; - this._extraContactParams += ";".concat(param_key); - - if (param_value) { - this._extraContactParams += "=".concat(param_value); - } - } - } - } - }, { - key: "register", - value: function register() { - var _this = this; - - if (this._registering) { - debug('Register request in progress...'); - return; - } - - var extraHeaders = this._extraHeaders.slice(); - - extraHeaders.push("Contact: ".concat(this._contact, ";expires=").concat(this._expires).concat(this._extraContactParams)); - extraHeaders.push("Expires: ".concat(this._expires)); - var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, { - 'to_uri': this._to_uri, - 'call_id': this._call_id, - 'cseq': this._cseq += 1 - }, extraHeaders); - var request_sender = new RequestSender(this._ua, request, { - onRequestTimeout: function onRequestTimeout() { - _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT); - }, - onTransportError: function onTransportError() { - _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR); - }, - // Increase the CSeq on authentication. - onAuthenticated: function onAuthenticated() { - _this._cseq += 1; - }, - onReceiveResponse: function onReceiveResponse(response) { - // Discard responses to older REGISTER/un-REGISTER requests. - if (response.cseq !== _this._cseq) { - return; - } // Clear registration timer. - - - if (_this._registrationTimer !== null) { - clearTimeout(_this._registrationTimer); - _this._registrationTimer = null; - } - - switch (true) { - case /^1[0-9]{2}$/.test(response.status_code): - { - // Ignore provisional responses. - break; - } - - case /^2[0-9]{2}$/.test(response.status_code): - { - _this._registering = false; - - if (!response.hasHeader('Contact')) { - debug('no Contact header in response to REGISTER, response ignored'); - break; - } - - var contacts = response.headers['Contact'].reduce(function (a, b) { - return a.concat(b.parsed); - }, []); // Get the Contact pointing to us and update the expires value accordingly. - - var contact = contacts.find(function (element) { - return element.uri.user === _this._ua.contact.uri.user; - }); - - if (!contact) { - debug('no Contact header pointing to us, response ignored'); - break; - } - - var expires = contact.getParam('expires'); - - if (!expires && response.hasHeader('expires')) { - expires = response.getHeader('expires'); - } - - if (!expires) { - expires = _this._expires; - } - - expires = Number(expires); - if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES; - var timeout = expires > 64 ? expires * 1000 / 2 + Math.floor((expires / 2 - 32) * 1000 * Math.random()) : expires * 1000 - 5000; // Re-Register or emit an event before the expiration interval has elapsed. - // For that, decrease the expires value. ie: 3 seconds. - - _this._registrationTimer = setTimeout(function () { - _this._registrationTimer = null; // If there are no listeners for registrationExpiring, renew registration. - // If there are listeners, let the function listening do the register call. - - if (_this._ua.listeners('registrationExpiring').length === 0) { - _this.register(); - } else { - _this._ua.emit('registrationExpiring'); - } - }, timeout); // Save gruu values. - - if (contact.hasParam('temp-gruu')) { - _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, ''); - } - - if (contact.hasParam('pub-gruu')) { - _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, ''); - } - - if (!_this._registered) { - _this._registered = true; - - _this._ua.registered({ - response: response - }); - } - - break; - } - // Interval too brief RFC3261 10.2.8. - - case /^423$/.test(response.status_code): - { - if (response.hasHeader('min-expires')) { - // Increase our registration interval to the suggested minimum. - _this._expires = Number(response.getHeader('min-expires')); - if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES; // Attempt the registration again immediately. - - _this.register(); - } else { - // This response MUST contain a Min-Expires header field. - debug('423 response received for REGISTER without Min-Expires'); - - _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); - } - - break; - } - - default: - { - var cause = Utils.sipErrorCause(response.status_code); - - _this._registrationFailure(response, cause); - } - } - } - }); - this._registering = true; - request_sender.send(); - } - }, { - key: "unregister", - value: function unregister() { - var _this2 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - if (!this._registered) { - debug('already unregistered'); - return; - } - - this._registered = false; // Clear the registration timer. - - if (this._registrationTimer !== null) { - clearTimeout(this._registrationTimer); - this._registrationTimer = null; - } - - var extraHeaders = this._extraHeaders.slice(); - - if (options.all) { - extraHeaders.push("Contact: *".concat(this._extraContactParams)); - } else { - extraHeaders.push("Contact: ".concat(this._contact, ";expires=0").concat(this._extraContactParams)); - } - - extraHeaders.push('Expires: 0'); - var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, { - 'to_uri': this._to_uri, - 'call_id': this._call_id, - 'cseq': this._cseq += 1 - }, extraHeaders); - var request_sender = new RequestSender(this._ua, request, { - onRequestTimeout: function onRequestTimeout() { - _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT); - }, - onTransportError: function onTransportError() { - _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR); - }, - // Increase the CSeq on authentication. - onAuthenticated: function onAuthenticated() { - _this2._cseq += 1; - }, - onReceiveResponse: function onReceiveResponse(response) { - switch (true) { - case /^1[0-9]{2}$/.test(response.status_code): - // Ignore provisional responses. - break; - - case /^2[0-9]{2}$/.test(response.status_code): - _this2._unregistered(response); - - break; - - default: - { - var cause = Utils.sipErrorCause(response.status_code); - - _this2._unregistered(response, cause); - } - } - } - }); - request_sender.send(); - } - }, { - key: "close", - value: function close() { - if (this._registered) { - this.unregister(); - } - } - }, { - key: "onTransportClosed", - value: function onTransportClosed() { - this._registering = false; - - if (this._registrationTimer !== null) { - clearTimeout(this._registrationTimer); - this._registrationTimer = null; - } - - if (this._registered) { - this._registered = false; - - this._ua.unregistered({}); - } - } - }, { - key: "_registrationFailure", - value: function _registrationFailure(response, cause) { - this._registering = false; - - this._ua.registrationFailed({ - response: response || null, - cause: cause - }); - - if (this._registered) { - this._registered = false; - - this._ua.unregistered({ - response: response || null, - cause: cause - }); - } - } - }, { - key: "_unregistered", - value: function _unregistered(response, cause) { - this._registering = false; - this._registered = false; - - this._ua.unregistered({ - response: response || null, - cause: cause || null - }); - } - }]); - - return Registrator; -}(); -},{"./Constants":2,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30}],18:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var JsSIP_C = require('./Constants'); - -var DigestAuthentication = require('./DigestAuthentication'); - -var Transactions = require('./Transactions'); - -var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers. - - -var EventHandlers = { - onRequestTimeout: function onRequestTimeout() {}, - onTransportError: function onTransportError() {}, - onReceiveResponse: function onReceiveResponse() {}, - onAuthenticated: function onAuthenticated() {} -}; - -module.exports = /*#__PURE__*/function () { - // Igor's extension: alternative credential - function RequestSender(ua, request, eventHandlers) { - var config2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; - - _classCallCheck(this, RequestSender); - - this._ua = ua; - this._eventHandlers = eventHandlers; - this._method = request.method; - this._request = request; - this._auth = null; - this._challenged = false; - this._staled = false; - this._config2 = config2; // Define the undefined handlers. - - for (var handler in EventHandlers) { - if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { - if (!this._eventHandlers[handler]) { - this._eventHandlers[handler] = EventHandlers[handler]; - } - } - } // If ua is in closing process or even closed just allow sending Bye and ACK. - - - if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) { - this._eventHandlers.onTransportError(); - } - } - /** - * Create the client transaction and send the message. - */ - - - _createClass(RequestSender, [{ - key: "send", - value: function send() { - var _this = this; - - var eventHandlers = { - onRequestTimeout: function onRequestTimeout() { - _this._eventHandlers.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this._eventHandlers.onTransportError(); - }, - onReceiveResponse: function onReceiveResponse(response) { - _this._receiveResponse(response); - } - }; - - switch (this._method) { - case 'INVITE': - this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); - break; - - case 'ACK': - this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); - break; - - default: - this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); - } // If authorization JWT is present, use it. - - - if (this._ua._configuration.authorization_jwt) { - this._request.setHeader('Authorization', this._ua._configuration.authorization_jwt); - } - - this.clientTransaction.send(); - } - /** - * Called from client transaction when receiving a correct response to the request. - * Authenticate request if needed or pass the response back to the applicant. - */ - - }, { - key: "_receiveResponse", - value: function _receiveResponse(response) { - var challenge; - var authorization_header_name; - var status_code = response.status_code; - /* - * Authentication - * Authenticate once. _challenged_ flag used to avoid infinite authentications. - */ - - if ((status_code === 401 || status_code === 407) && (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { - // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. - if (response.status_code === 401) { - challenge = response.parseHeader('www-authenticate'); - authorization_header_name = 'authorization'; - } else { - challenge = response.parseHeader('proxy-authenticate'); - authorization_header_name = 'proxy-authorization'; - } // Verify it seems a valid challenge. - - - if (!challenge) { - debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); - - this._eventHandlers.onReceiveResponse(response); - - return; - } - - if (!this._challenged || !this._staled && challenge.stale === true) { - if (!this._auth) { - var cnf = this._config2 ? this._config2 : this._ua.configuration; - this._auth = new DigestAuthentication({ - username: cnf.authorization_user, - password: cnf.password, - realm: cnf.realm, - ha1: cnf.ha1 - }); - } // Verify that the challenge is really valid. - - - if (!this._auth.authenticate(this._request, challenge)) { - this._eventHandlers.onReceiveResponse(response); - - return; - } - - this._challenged = true; // Update ha1 and realm in the UA or in alternative config. - - if (!this._config2) { - this._ua.set('realm', this._auth.get('realm')); - - this._ua.set('ha1', this._auth.get('ha1')); - } else { - this._config2.realm = this._auth.get('realm'); - this._config2.ha1 = this._auth.get('ha1'); - } - - if (challenge.stale) { - this._staled = true; - } - - this._request = this._request.clone(); - this._request.cseq += 1; - - this._request.setHeader('cseq', "".concat(this._request.cseq, " ").concat(this._method)); - - this._request.setHeader(authorization_header_name, this._auth.toString()); - - this._eventHandlers.onAuthenticated(this._request); - - this.send(); - } else { - this._eventHandlers.onReceiveResponse(response); - } - } else { - this._eventHandlers.onReceiveResponse(response); - } - } - }]); - - return RequestSender; -}(); -},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":22,"debug":30}],19:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var sdp_transform = require('sdp-transform'); - -var JsSIP_C = require('./Constants'); - -var Utils = require('./Utils'); - -var NameAddrHeader = require('./NameAddrHeader'); - -var Grammar = require('./Grammar'); - -var debug = require('debug')('JsSIP:SIPMessage'); -/** - * -param {String} method request method - * -param {String} ruri request uri - * -param {UA} ua - * -param {Object} params parameters that will have priority over ua.configuration parameters: - *
- * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set - * -param {Object} [headers] extra headers - * -param {String} [body] - */ - - -var OutgoingRequest = /*#__PURE__*/function () { - function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) { - _classCallCheck(this, OutgoingRequest); - - // Mandatory parameters check. - if (!method || !ruri || !ua) { - return null; - } - - params = params || {}; - this.ua = ua; - this.headers = {}; - this.method = method; - this.ruri = ruri; - this.body = body; - this.extraHeaders = Utils.cloneArray(extraHeaders); // Fill the Common SIP Request Headers. - // Route. - - if (params.route_set) { - this.setHeader('route', params.route_set); - } else if (ua.configuration.use_preloaded_route) { - this.setHeader('route', "<".concat(ua.transport.sip_uri, ";lr>")); - } // Via. - // Empty Via header. Will be filled by the client transaction. - - - this.setHeader('via', ''); // Max-Forwards. - - this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS); // To - - var to_uri = params.to_uri || ruri; - var to_params = params.to_tag ? { - tag: params.to_tag - } : null; - var to_display_name = typeof params.to_display_name !== 'undefined' ? params.to_display_name : null; - this.to = new NameAddrHeader(to_uri, to_display_name, to_params); - this.setHeader('to', this.to.toString()); // From. - - var from_uri = params.from_uri || ua.configuration.uri; - var from_params = { - tag: params.from_tag || Utils.newTag() - }; - var display_name; - - if (typeof params.from_display_name !== 'undefined') { - display_name = params.from_display_name; - } else if (ua.configuration.display_name) { - display_name = ua.configuration.display_name; - } else { - display_name = null; - } - - this.from = new NameAddrHeader(from_uri, display_name, from_params); - this.setHeader('from', this.from.toString()); // Call-ID. - - var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15); - this.call_id = call_id; - this.setHeader('call-id', call_id); // CSeq. - - var cseq = params.cseq || Math.floor(Math.random() * 10000); - this.cseq = cseq; - this.setHeader('cseq', "".concat(cseq, " ").concat(method)); - } - /** - * Replace the the given header by the given value. - * -param {String} name header name - * -param {String | Array} value header value - */ - - - _createClass(OutgoingRequest, [{ - key: "setHeader", - value: function setHeader(name, value) { - // Remove the header from extraHeaders if present. - var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); - - for (var idx = 0; idx < this.extraHeaders.length; idx++) { - if (regexp.test(this.extraHeaders[idx])) { - this.extraHeaders.splice(idx, 1); - } - } - - this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value]; - } - /** - * Get the value of the given header name at the given position. - * -param {String} name header name - * -returns {String|undefined} Returns the specified header, null if header doesn't exist. - */ - - }, { - key: "getHeader", - value: function getHeader(name) { - var headers = this.headers[Utils.headerize(name)]; - - if (headers) { - if (headers[0]) { - return headers[0]; - } - } else { - var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); - - var _iterator = _createForOfIteratorHelper(this.extraHeaders), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var header = _step.value; - - if (regexp.test(header)) { - return header.substring(header.indexOf(':') + 1).trim(); - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } - - return; - } - /** - * Get the header/s of the given name. - * -param {String} name header name - * -returns {Array} Array with all the headers of the specified name. - */ - - }, { - key: "getHeaders", - value: function getHeaders(name) { - var headers = this.headers[Utils.headerize(name)]; - var result = []; - - if (headers) { - var _iterator2 = _createForOfIteratorHelper(headers), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var header = _step2.value; - result.push(header); - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - - return result; - } else { - var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); - - var _iterator3 = _createForOfIteratorHelper(this.extraHeaders), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var _header = _step3.value; - - if (regexp.test(_header)) { - result.push(_header.substring(_header.indexOf(':') + 1).trim()); - } - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } - - return result; - } - } - /** - * Verify the existence of the given header. - * -param {String} name header name - * -returns {boolean} true if header with given name exists, false otherwise - */ - - }, { - key: "hasHeader", - value: function hasHeader(name) { - if (this.headers[Utils.headerize(name)]) { - return true; - } else { - var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); - - var _iterator4 = _createForOfIteratorHelper(this.extraHeaders), - _step4; - - try { - for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - var header = _step4.value; - - if (regexp.test(header)) { - return true; - } - } - } catch (err) { - _iterator4.e(err); - } finally { - _iterator4.f(); - } - } - - return false; - } - /** - * Parse the current body as a SDP and store the resulting object - * into this.sdp. - * -param {Boolean} force: Parse even if this.sdp already exists. - * - * Returns this.sdp. - */ - - }, { - key: "parseSDP", - value: function parseSDP(force) { - if (!force && this.sdp) { - return this.sdp; - } else { - this.sdp = sdp_transform.parse(this.body || ''); - return this.sdp; - } - } - }, { - key: "toString", - value: function toString() { - var msg = "".concat(this.method, " ").concat(this.ruri, " SIP/2.0\r\n"); - - for (var headerName in this.headers) { - if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) { - var _iterator5 = _createForOfIteratorHelper(this.headers[headerName]), - _step5; - - try { - for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { - var headerValue = _step5.value; - msg += "".concat(headerName, ": ").concat(headerValue, "\r\n"); - } - } catch (err) { - _iterator5.e(err); - } finally { - _iterator5.f(); - } - } - } - - var _iterator6 = _createForOfIteratorHelper(this.extraHeaders), - _step6; - - try { - for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { - var header = _step6.value; - msg += "".concat(header.trim(), "\r\n"); - } // Supported. - - } catch (err) { - _iterator6.e(err); - } finally { - _iterator6.f(); - } - - var supported = []; - - switch (this.method) { - case JsSIP_C.REGISTER: - supported.push('path', 'gruu'); - break; - - case JsSIP_C.INVITE: - if (this.ua.configuration.session_timers) { - supported.push('timer'); - } - - if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) { - supported.push('gruu'); - } - - supported.push('ice', 'replaces'); - break; - - case JsSIP_C.UPDATE: - if (this.ua.configuration.session_timers) { - supported.push('timer'); - } - - supported.push('ice'); - break; - } - - supported.push('outbound'); - var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT; // Allow. - - msg += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); - msg += "Supported: ".concat(supported, "\r\n"); - msg += "User-Agent: ".concat(userAgent, "\r\n"); - - if (this.body) { - var length = Utils.str_utf8_length(this.body); - msg += "Content-Length: ".concat(length, "\r\n\r\n"); - msg += this.body; - } else { - msg += 'Content-Length: 0\r\n\r\n'; - } - - return msg; - } - }, { - key: "clone", - value: function clone() { - var request = new OutgoingRequest(this.method, this.ruri, this.ua); - Object.keys(this.headers).forEach(function (name) { - request.headers[name] = this.headers[name].slice(); - }, this); - request.body = this.body; - request.extraHeaders = Utils.cloneArray(this.extraHeaders); - request.to = this.to; - request.from = this.from; - request.call_id = this.call_id; - request.cseq = this.cseq; - return request; - } - }]); - - return OutgoingRequest; -}(); - -var InitialOutgoingInviteRequest = /*#__PURE__*/function (_OutgoingRequest) { - _inherits(InitialOutgoingInviteRequest, _OutgoingRequest); - - var _super = _createSuper(InitialOutgoingInviteRequest); - - function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) { - var _this; - - _classCallCheck(this, InitialOutgoingInviteRequest); - - _this = _super.call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body); - _this.transaction = null; - return _this; - } - - _createClass(InitialOutgoingInviteRequest, [{ - key: "cancel", - value: function cancel(reason) { - this.transaction.cancel(reason); - } - }, { - key: "clone", - value: function clone() { - var request = new InitialOutgoingInviteRequest(this.ruri, this.ua); - Object.keys(this.headers).forEach(function (name) { - request.headers[name] = this.headers[name].slice(); - }, this); - request.body = this.body; - request.extraHeaders = Utils.cloneArray(this.extraHeaders); - request.to = this.to; - request.from = this.from; - request.call_id = this.call_id; - request.cseq = this.cseq; - request.transaction = this.transaction; - return request; - } - }]); - - return InitialOutgoingInviteRequest; -}(OutgoingRequest); - -var IncomingMessage = /*#__PURE__*/function () { - function IncomingMessage() { - _classCallCheck(this, IncomingMessage); - - 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; - } - /** - * Insert a header of the given name and value into the last position of the - * header array. - */ - - - _createClass(IncomingMessage, [{ - key: "addHeader", - value: function addHeader(name, value) { - var header = { - raw: value - }; - name = Utils.headerize(name); - - if (this.headers[name]) { - this.headers[name].push(header); - } else { - this.headers[name] = [header]; - } - } - /** - * Get the value of the given header name at the given position. - */ - - }, { - key: "getHeader", - value: function getHeader(name) { - var header = this.headers[Utils.headerize(name)]; - - if (header) { - if (header[0]) { - return header[0].raw; - } - } else { - return; - } - } - /** - * Get the header/s of the given name. - */ - - }, { - key: "getHeaders", - value: function getHeaders(name) { - var headers = this.headers[Utils.headerize(name)]; - var result = []; - - if (!headers) { - return []; - } - - var _iterator7 = _createForOfIteratorHelper(headers), - _step7; - - try { - for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { - var header = _step7.value; - result.push(header.raw); - } - } catch (err) { - _iterator7.e(err); - } finally { - _iterator7.f(); - } - - return result; - } - /** - * Verify the existence of the given header. - */ - - }, { - key: "hasHeader", - value: function hasHeader(name) { - return this.headers[Utils.headerize(name)] ? true : false; - } - /** - * Parse the given header on the given index. - * -param {String} name header name - * -param {Number} [idx=0] header index - * -returns {Object|undefined} Parsed header object, undefined if the header - * is not present or in case of a parsing error. - */ - - }, { - key: "parseHeader", - value: function parseHeader(name) { - var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - name = Utils.headerize(name); - - if (!this.headers[name]) { - debug("header \"".concat(name, "\" not present")); - return; - } else if (idx >= this.headers[name].length) { - debug("not so many \"".concat(name, "\" headers present")); - return; - } - - var header = this.headers[name][idx]; - var value = header.raw; - - if (header.parsed) { - return header.parsed; - } // Substitute '-' by '_' for grammar rule matching. - - - var parsed = Grammar.parse(value, name.replace(/-/g, '_')); - - if (parsed === -1) { - this.headers[name].splice(idx, 1); // delete from headers - - debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); - return; - } else { - header.parsed = parsed; - return parsed; - } - } - /** - * Message Header attribute selector. Alias of parseHeader. - * -param {String} name header name - * -param {Number} [idx=0] header index - * -returns {Object|undefined} Parsed header object, undefined if the header - * is not present or in case of a parsing error. - * - * -example - * message.s('via',3).port - */ - - }, { - key: "s", - value: function s(name, idx) { - return this.parseHeader(name, idx); - } - /** - * Replace the value of the given header by the value. - * -param {String} name header name - * -param {String} value header value - */ - - }, { - key: "setHeader", - value: function setHeader(name, value) { - var header = { - raw: value - }; - this.headers[Utils.headerize(name)] = [header]; - } - /** - * Parse the current body as a SDP and store the resulting object - * into this.sdp. - * -param {Boolean} force: Parse even if this.sdp already exists. - * - * Returns this.sdp. - */ - - }, { - key: "parseSDP", - value: function parseSDP(force) { - if (!force && this.sdp) { - return this.sdp; - } else { - this.sdp = sdp_transform.parse(this.body || ''); - return this.sdp; - } - } - }, { - key: "toString", - value: function toString() { - return this.data; - } - }]); - - return IncomingMessage; -}(); - -var IncomingRequest = /*#__PURE__*/function (_IncomingMessage) { - _inherits(IncomingRequest, _IncomingMessage); - - var _super2 = _createSuper(IncomingRequest); - - function IncomingRequest(ua) { - var _this2; - - _classCallCheck(this, IncomingRequest); - - _this2 = _super2.call(this); - _this2.ua = ua; - _this2.headers = {}; - _this2.ruri = null; - _this2.transport = null; - _this2.server_transaction = null; - return _this2; - } - /** - * Stateful reply. - * -param {Number} code status code - * -param {String} reason reason phrase - * -param {Object} headers extra headers - * -param {String} body body - * -param {Function} [onSuccess] onSuccess callback - * -param {Function} [onFailure] onFailure callback - */ - - - _createClass(IncomingRequest, [{ - key: "reply", - value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) { - var supported = []; - var to = this.getHeader('To'); - code = code || null; - reason = reason || null; // Validate code and reason values. - - if (!code || code < 100 || code > 699) { - throw new TypeError("Invalid status_code: ".concat(code)); - } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { - throw new TypeError("Invalid reason_phrase: ".concat(reason)); - } - - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - extraHeaders = Utils.cloneArray(extraHeaders); - var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); - - if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) { - var headers = this.getHeaders('record-route'); - - var _iterator8 = _createForOfIteratorHelper(headers), - _step8; - - try { - for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { - var header = _step8.value; - response += "Record-Route: ".concat(header, "\r\n"); - } - } catch (err) { - _iterator8.e(err); - } finally { - _iterator8.f(); - } - } - - var vias = this.getHeaders('via'); - - var _iterator9 = _createForOfIteratorHelper(vias), - _step9; - - try { - for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { - var via = _step9.value; - response += "Via: ".concat(via, "\r\n"); - } - } catch (err) { - _iterator9.e(err); - } finally { - _iterator9.f(); - } - - if (!this.to_tag && code > 100) { - to += ";tag=".concat(Utils.newTag()); - } else if (this.to_tag && !this.s('to').hasParam('tag')) { - to += ";tag=".concat(this.to_tag); - } - - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(this.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(this.call_id, "\r\n"); - response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); - - var _iterator10 = _createForOfIteratorHelper(extraHeaders), - _step10; - - try { - for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { - var _header2 = _step10.value; - response += "".concat(_header2.trim(), "\r\n"); - } // Supported. - - } catch (err) { - _iterator10.e(err); - } finally { - _iterator10.f(); - } - - switch (this.method) { - case JsSIP_C.INVITE: - if (this.ua.configuration.session_timers) { - supported.push('timer'); - } - - if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) { - supported.push('gruu'); - } - - supported.push('ice', 'replaces'); - break; - - case JsSIP_C.UPDATE: - if (this.ua.configuration.session_timers) { - supported.push('timer'); - } - - if (body) { - supported.push('ice'); - } - - supported.push('replaces'); - } - - supported.push('outbound'); // Allow and Accept. - - if (this.method === JsSIP_C.OPTIONS) { - response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); - response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n"); - } else if (code === 405) { - response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); - } else if (code === 415) { - response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n"); - } - - response += "Supported: ".concat(supported, "\r\n"); - - if (body) { - var length = Utils.str_utf8_length(body); - response += 'Content-Type: application/sdp\r\n'; - response += "Content-Length: ".concat(length, "\r\n\r\n"); - response += body; - } else { - response += "Content-Length: ".concat(0, "\r\n\r\n"); - } - - this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); - } - /** - * Stateless reply. - * -param {Number} code status code - * -param {String} reason reason phrase - */ - - }, { - key: "reply_sl", - value: function reply_sl() { - var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var vias = this.getHeaders('via'); // Validate code and reason values. - - if (!code || code < 100 || code > 699) { - throw new TypeError("Invalid status_code: ".concat(code)); - } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { - throw new TypeError("Invalid reason_phrase: ".concat(reason)); - } - - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); - - var _iterator11 = _createForOfIteratorHelper(vias), - _step11; - - try { - for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { - var via = _step11.value; - response += "Via: ".concat(via, "\r\n"); - } - } catch (err) { - _iterator11.e(err); - } finally { - _iterator11.f(); - } - - var to = this.getHeader('To'); - - if (!this.to_tag && code > 100) { - to += ";tag=".concat(Utils.newTag()); - } else if (this.to_tag && !this.s('to').hasParam('tag')) { - to += ";tag=".concat(this.to_tag); - } - - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(this.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(this.call_id, "\r\n"); - response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); - response += "Content-Length: ".concat(0, "\r\n\r\n"); - this.transport.send(response); - } - }]); - - return IncomingRequest; -}(IncomingMessage); - -var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { - _inherits(IncomingResponse, _IncomingMessage2); - - var _super3 = _createSuper(IncomingResponse); - - function IncomingResponse() { - var _this3; - - _classCallCheck(this, IncomingResponse); - - _this3 = _super3.call(this); - _this3.headers = {}; - _this3.status_code = null; - _this3.reason_phrase = null; - return _this3; - } - - return IncomingResponse; -}(IncomingMessage); - -module.exports = { - OutgoingRequest: OutgoingRequest, - InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, - IncomingRequest: IncomingRequest, - IncomingResponse: IncomingResponse -}; -},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":26,"debug":30,"sdp-transform":35}],20:[function(require,module,exports){ -"use strict"; - -var Utils = require('./Utils'); - -var Grammar = require('./Grammar'); - -var debugerror = require('debug')('JsSIP:ERROR:Socket'); - -debugerror.log = console.warn.bind(console); -/** - * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ - * - * interface Socket { - * attribute String via_transport - * attribute String url - * attribute String sip_uri - * - * method connect(); - * method disconnect(); - * method send(data); - * - * attribute EventHandler onconnect - * attribute EventHandler ondisconnect - * attribute EventHandler ondata - * } - * - */ - -exports.isSocket = function (socket) { - // Ignore if an array is given. - if (Array.isArray(socket)) { - return false; - } - - if (typeof socket === 'undefined') { - debugerror('undefined JsSIP.Socket instance'); - return false; - } // Check Properties. - - - try { - if (!Utils.isString(socket.url)) { - debugerror('missing or invalid JsSIP.Socket url property'); - throw new Error(); - } - - if (!Utils.isString(socket.via_transport)) { - debugerror('missing or invalid JsSIP.Socket via_transport property'); - throw new Error(); - } - - if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { - debugerror('missing or invalid JsSIP.Socket sip_uri property'); - throw new Error(); - } - } catch (e) { - return false; - } // Check Methods. - - - try { - ['connect', 'disconnect', 'send'].forEach(function (method) { - if (!Utils.isFunction(socket[method])) { - debugerror("missing or invalid JsSIP.Socket method: ".concat(method)); - throw new Error(); - } - }); - } catch (e) { - return false; - } - - return true; -}; -},{"./Grammar":7,"./Utils":26,"debug":30}],21:[function(require,module,exports){ -"use strict"; - -var T1 = 500, - T2 = 4000, - T4 = 5000; -module.exports = { - T1: T1, - T2: T2, - T4: T4, - TIMER_B: 64 * T1, - TIMER_D: 0 * T1, - TIMER_F: 64 * T1, - TIMER_H: 64 * T1, - TIMER_I: 0 * T1, - TIMER_J: 0 * T1, - TIMER_K: 0 * T4, - TIMER_L: 64 * T1, - TIMER_M: 64 * T1, - PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 - -}; -},{}],22:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('./Constants'); - -var SIPMessage = require('./SIPMessage'); - -var Timers = require('./Timers'); - -var debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); - -var debugict = require('debug')('JsSIP:InviteClientTransaction'); - -var debugact = require('debug')('JsSIP:AckClientTransaction'); - -var debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); - -var debugist = require('debug')('JsSIP:InviteServerTransaction'); - -var C = { - // Transaction states. - STATUS_TRYING: 1, - STATUS_PROCEEDING: 2, - STATUS_CALLING: 3, - STATUS_ACCEPTED: 4, - STATUS_COMPLETED: 5, - STATUS_TERMINATED: 6, - STATUS_CONFIRMED: 7, - // Transaction types. - NON_INVITE_CLIENT: 'nict', - NON_INVITE_SERVER: 'nist', - INVITE_CLIENT: 'ict', - INVITE_SERVER: 'ist' -}; - -var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { - _inherits(NonInviteClientTransaction, _EventEmitter); - - var _super = _createSuper(NonInviteClientTransaction); - - function NonInviteClientTransaction(ua, transport, request, eventHandlers) { - var _this; - - _classCallCheck(this, NonInviteClientTransaction); - - _this = _super.call(this); - _this.type = C.NON_INVITE_CLIENT; - _this.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); - _this.ua = ua; - _this.transport = transport; - _this.request = request; - _this.eventHandlers = eventHandlers; - var via = "SIP/2.0/".concat(transport.via_transport); - via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this.id); - - _this.request.setHeader('via', via); - - _this.ua.newTransaction(_assertThisInitialized(_this)); - - return _this; - } - - _createClass(NonInviteClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "stateChanged", - value: function stateChanged(state) { - this.state = state; - this.emit('stateChanged'); - } - }, { - key: "send", - value: function send() { - var _this2 = this; - - this.stateChanged(C.STATUS_TRYING); - this.F = setTimeout(function () { - _this2.timer_F(); - }, Timers.TIMER_F); - - if (!this.transport.send(this.request)) { - this.onTransportError(); - } - } - }, { - key: "onTransportError", - value: function onTransportError() { - debugnict("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 timer_F() { - debugnict("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 timer_K() { - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - }, { - key: "receiveResponse", - value: function receiveResponse(response) { - var _this3 = this; - - var status_code = response.status_code; - - if (status_code < 200) { - switch (this.state) { - case C.STATUS_TRYING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_PROCEEDING); - this.eventHandlers.onReceiveResponse(response); - break; - } - } else { - switch (this.state) { - case C.STATUS_TRYING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_COMPLETED); - clearTimeout(this.F); - - if (status_code === 408) { - this.eventHandlers.onRequestTimeout(); - } else { - this.eventHandlers.onReceiveResponse(response); - } - - this.K = setTimeout(function () { - _this3.timer_K(); - }, Timers.TIMER_K); - break; - - case C.STATUS_COMPLETED: - break; - } - } - } - }]); - - return NonInviteClientTransaction; -}(EventEmitter); - -var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { - _inherits(InviteClientTransaction, _EventEmitter2); - - var _super2 = _createSuper(InviteClientTransaction); - - function InviteClientTransaction(ua, transport, request, eventHandlers) { - var _this4; - - _classCallCheck(this, InviteClientTransaction); - - _this4 = _super2.call(this); - _this4.type = C.INVITE_CLIENT; - _this4.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); - _this4.ua = ua; - _this4.transport = transport; - _this4.request = request; - _this4.eventHandlers = eventHandlers; - request.transaction = _assertThisInitialized(_this4); - var via = "SIP/2.0/".concat(transport.via_transport); - via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this4.id); - - _this4.request.setHeader('via', via); - - _this4.ua.newTransaction(_assertThisInitialized(_this4)); - - return _this4; - } - - _createClass(InviteClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "stateChanged", - value: function stateChanged(state) { - this.state = state; - this.emit('stateChanged'); - } - }, { - key: "send", - value: function send() { - var _this5 = this; - - this.stateChanged(C.STATUS_CALLING); - this.B = setTimeout(function () { - _this5.timer_B(); - }, Timers.TIMER_B); - - if (!this.transport.send(this.request)) { - this.onTransportError(); - } - } - }, { - key: "onTransportError", - value: function onTransportError() { - clearTimeout(this.B); - clearTimeout(this.D); - clearTimeout(this.M); - - if (this.state !== C.STATUS_ACCEPTED) { - debugict("transport error occurred, deleting transaction ".concat(this.id)); - this.eventHandlers.onTransportError(); - } - - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } // RFC 6026 7.2. - - }, { - key: "timer_M", - value: function timer_M() { - debugict("Timer M expired for transaction ".concat(this.id)); - - if (this.state === C.STATUS_ACCEPTED) { - clearTimeout(this.B); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - } // RFC 3261 17.1.1. - - }, { - key: "timer_B", - value: function timer_B() { - debugict("Timer B expired for transaction ".concat(this.id)); - - if (this.state === C.STATUS_CALLING) { - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - this.eventHandlers.onRequestTimeout(); - } - } - }, { - key: "timer_D", - value: function timer_D() { - debugict("Timer D expired for transaction ".concat(this.id)); - clearTimeout(this.B); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - }, { - key: "sendACK", - value: function sendACK(response) { - var _this6 = this; - - var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, { - 'route_set': this.request.getHeaders('route'), - 'call_id': this.request.getHeader('call-id'), - 'cseq': this.request.cseq - }); - ack.setHeader('from', this.request.getHeader('from')); - ack.setHeader('via', this.request.getHeader('via')); - ack.setHeader('to', response.getHeader('to')); - this.D = setTimeout(function () { - _this6.timer_D(); - }, Timers.TIMER_D); - this.transport.send(ack); - } - }, { - key: "cancel", - value: function cancel(reason) { - // Send only if a provisional response (>100) has been received. - if (this.state !== C.STATUS_PROCEEDING) { - return; - } - - var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, { - 'route_set': this.request.getHeaders('route'), - 'call_id': this.request.getHeader('call-id'), - 'cseq': this.request.cseq - }); - cancel.setHeader('from', this.request.getHeader('from')); - cancel.setHeader('via', this.request.getHeader('via')); - cancel.setHeader('to', this.request.getHeader('to')); - - if (reason) { - cancel.setHeader('reason', reason); - } - - this.transport.send(cancel); - } - }, { - key: "receiveResponse", - value: function receiveResponse(response) { - var _this7 = this; - - var status_code = response.status_code; - - if (status_code >= 100 && status_code <= 199) { - switch (this.state) { - case C.STATUS_CALLING: - this.stateChanged(C.STATUS_PROCEEDING); - this.eventHandlers.onReceiveResponse(response); - break; - - case C.STATUS_PROCEEDING: - this.eventHandlers.onReceiveResponse(response); - break; - } - } else if (status_code >= 200 && status_code <= 299) { - switch (this.state) { - case C.STATUS_CALLING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_ACCEPTED); - this.M = setTimeout(function () { - _this7.timer_M(); - }, Timers.TIMER_M); - this.eventHandlers.onReceiveResponse(response); - break; - - case C.STATUS_ACCEPTED: - this.eventHandlers.onReceiveResponse(response); - break; - } - } else if (status_code >= 300 && status_code <= 699) { - switch (this.state) { - case C.STATUS_CALLING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_COMPLETED); - this.sendACK(response); - this.eventHandlers.onReceiveResponse(response); - break; - - case C.STATUS_COMPLETED: - this.sendACK(response); - break; - } - } - } - }]); - - return InviteClientTransaction; -}(EventEmitter); - -var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { - _inherits(AckClientTransaction, _EventEmitter3); - - var _super3 = _createSuper(AckClientTransaction); - - function AckClientTransaction(ua, transport, request, eventHandlers) { - var _this8; - - _classCallCheck(this, AckClientTransaction); - - _this8 = _super3.call(this); - _this8.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); - _this8.transport = transport; - _this8.request = request; - _this8.eventHandlers = eventHandlers; - var via = "SIP/2.0/".concat(transport.via_transport); - via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this8.id); - - _this8.request.setHeader('via', via); - - return _this8; - } - - _createClass(AckClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "send", - value: function send() { - if (!this.transport.send(this.request)) { - this.onTransportError(); - } - } - }, { - key: "onTransportError", - value: function onTransportError() { - debugact("transport error occurred for transaction ".concat(this.id)); - this.eventHandlers.onTransportError(); - } - }]); - - return AckClientTransaction; -}(EventEmitter); - -var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { - _inherits(NonInviteServerTransaction, _EventEmitter4); - - var _super4 = _createSuper(NonInviteServerTransaction); - - function NonInviteServerTransaction(ua, transport, request) { - var _this9; - - _classCallCheck(this, NonInviteServerTransaction); - - _this9 = _super4.call(this); - _this9.type = C.NON_INVITE_SERVER; - _this9.id = request.via_branch; - _this9.ua = ua; - _this9.transport = transport; - _this9.request = request; - _this9.last_response = ''; - request.server_transaction = _assertThisInitialized(_this9); - _this9.state = C.STATUS_TRYING; - ua.newTransaction(_assertThisInitialized(_this9)); - return _this9; - } - - _createClass(NonInviteServerTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "stateChanged", - value: function stateChanged(state) { - this.state = state; - this.emit('stateChanged'); - } - }, { - key: "timer_J", - value: function timer_J() { - debugnist("Timer J expired for transaction ".concat(this.id)); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - }, { - key: "onTransportError", - value: function onTransportError() { - if (!this.transportError) { - this.transportError = true; - debugnist("transport error occurred, deleting transaction ".concat(this.id)); - clearTimeout(this.J); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - } - }, { - key: "receiveResponse", - value: function receiveResponse(status_code, response, onSuccess, onFailure) { - var _this10 = this; - - if (status_code === 100) { - /* RFC 4320 4.1 - * 'A SIP element MUST NOT - * send any provisional response with a - * Status-Code other than 100 to a non-INVITE request.' - */ - switch (this.state) { - case C.STATUS_TRYING: - this.stateChanged(C.STATUS_PROCEEDING); - - if (!this.transport.send(response)) { - this.onTransportError(); - } - - break; - - case C.STATUS_PROCEEDING: - this.last_response = response; - - if (!this.transport.send(response)) { - this.onTransportError(); - - if (onFailure) { - onFailure(); - } - } else if (onSuccess) { - onSuccess(); - } - - break; - } - } else if (status_code >= 200 && status_code <= 699) { - switch (this.state) { - case C.STATUS_TRYING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_COMPLETED); - this.last_response = response; - this.J = setTimeout(function () { - _this10.timer_J(); - }, Timers.TIMER_J); - - if (!this.transport.send(response)) { - this.onTransportError(); - - if (onFailure) { - onFailure(); - } - } else if (onSuccess) { - onSuccess(); - } - - break; - - case C.STATUS_COMPLETED: - break; - } - } - } - }]); - - return NonInviteServerTransaction; -}(EventEmitter); - -var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { - _inherits(InviteServerTransaction, _EventEmitter5); - - var _super5 = _createSuper(InviteServerTransaction); - - function InviteServerTransaction(ua, transport, request) { - var _this11; - - _classCallCheck(this, InviteServerTransaction); - - _this11 = _super5.call(this); - _this11.type = C.INVITE_SERVER; - _this11.id = request.via_branch; - _this11.ua = ua; - _this11.transport = transport; - _this11.request = request; - _this11.last_response = ''; - request.server_transaction = _assertThisInitialized(_this11); - _this11.state = C.STATUS_PROCEEDING; - ua.newTransaction(_assertThisInitialized(_this11)); - _this11.resendProvisionalTimer = null; - request.reply(100); - return _this11; - } - - _createClass(InviteServerTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "stateChanged", - value: function stateChanged(state) { - this.state = state; - this.emit('stateChanged'); - } - }, { - key: "timer_H", - value: function timer_H() { - debugist("Timer H expired for transaction ".concat(this.id)); - - if (this.state === C.STATUS_COMPLETED) { - debugist('ACK not received, dialog will be terminated'); - } - - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - }, { - key: "timer_I", - value: function timer_I() { - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } // RFC 6026 7.1. - - }, { - key: "timer_L", - value: function timer_L() { - debugist("Timer L expired for transaction ".concat(this.id)); - - if (this.state === C.STATUS_ACCEPTED) { - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - } - }, { - key: "onTransportError", - value: function onTransportError() { - if (!this.transportError) { - this.transportError = true; - debugist("transport error occurred, deleting transaction ".concat(this.id)); - - if (this.resendProvisionalTimer !== null) { - clearInterval(this.resendProvisionalTimer); - this.resendProvisionalTimer = null; - } - - clearTimeout(this.L); - clearTimeout(this.H); - clearTimeout(this.I); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - } - }, { - key: "resend_provisional", - value: function resend_provisional() { - if (!this.transport.send(this.last_response)) { - this.onTransportError(); - } - } // INVITE Server Transaction RFC 3261 17.2.1. - - }, { - key: "receiveResponse", - value: function receiveResponse(status_code, response, onSuccess, onFailure) { - var _this12 = this; - - if (status_code >= 100 && status_code <= 199) { - switch (this.state) { - case C.STATUS_PROCEEDING: - if (!this.transport.send(response)) { - this.onTransportError(); - } - - this.last_response = response; - break; - } - } - - if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) { - // Trigger the resendProvisionalTimer only for the first non 100 provisional response. - if (this.resendProvisionalTimer === null) { - this.resendProvisionalTimer = setInterval(function () { - _this12.resend_provisional(); - }, Timers.PROVISIONAL_RESPONSE_INTERVAL); - } - } else if (status_code >= 200 && status_code <= 299) { - switch (this.state) { - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_ACCEPTED); - this.last_response = response; - this.L = setTimeout(function () { - _this12.timer_L(); - }, Timers.TIMER_L); - - if (this.resendProvisionalTimer !== null) { - clearInterval(this.resendProvisionalTimer); - this.resendProvisionalTimer = null; - } - - /* falls through */ - - case C.STATUS_ACCEPTED: - // Note that this point will be reached for proceeding this.state also. - if (!this.transport.send(response)) { - this.onTransportError(); - - if (onFailure) { - onFailure(); - } - } else if (onSuccess) { - onSuccess(); - } - - break; - } - } else if (status_code >= 300 && status_code <= 699) { - switch (this.state) { - case C.STATUS_PROCEEDING: - if (this.resendProvisionalTimer !== null) { - clearInterval(this.resendProvisionalTimer); - this.resendProvisionalTimer = null; - } - - if (!this.transport.send(response)) { - this.onTransportError(); - - if (onFailure) { - onFailure(); - } - } else { - this.stateChanged(C.STATUS_COMPLETED); - this.H = setTimeout(function () { - _this12.timer_H(); - }, Timers.TIMER_H); - - if (onSuccess) { - onSuccess(); - } - } - - break; - } - } - } - }]); - - return InviteServerTransaction; -}(EventEmitter); -/** - * INVITE: - * _true_ if retransmission - * _false_ new request - * - * ACK: - * _true_ ACK to non2xx response - * _false_ ACK must be passed to TU (accepted state) - * ACK to 2xx response - * - * CANCEL: - * _true_ no matching invite transaction - * _false_ matching invite transaction and no final response sent - * - * OTHER: - * _true_ retransmission - * _false_ new request - */ - - -function checkTransaction(_ref, request) { - var _transactions = _ref._transactions; - var tr; - - switch (request.method) { - case JsSIP_C.INVITE: - tr = _transactions.ist[request.via_branch]; - - if (tr) { - switch (tr.state) { - case C.STATUS_PROCEEDING: - tr.transport.send(tr.last_response); - break; - // RFC 6026 7.1 Invite retransmission. - // Received while in C.STATUS_ACCEPTED state. Absorb it. - - case C.STATUS_ACCEPTED: - break; - } - - return true; - } - - break; - - case JsSIP_C.ACK: - tr = _transactions.ist[request.via_branch]; // RFC 6026 7.1. - - if (tr) { - if (tr.state === C.STATUS_ACCEPTED) { - return false; - } else if (tr.state === C.STATUS_COMPLETED) { - tr.state = C.STATUS_CONFIRMED; - tr.I = setTimeout(function () { - tr.timer_I(); - }, Timers.TIMER_I); - return true; - } - } // ACK to 2XX Response. - else { - return false; - } - - break; - - case JsSIP_C.CANCEL: - tr = _transactions.ist[request.via_branch]; - - if (tr) { - request.reply_sl(200); - - if (tr.state === C.STATUS_PROCEEDING) { - return false; - } else { - return true; - } - } else { - request.reply_sl(481); - return true; - } - - default: - // Non-INVITE Server Transaction RFC 3261 17.2.2. - tr = _transactions.nist[request.via_branch]; - - if (tr) { - switch (tr.state) { - case C.STATUS_TRYING: - break; - - case C.STATUS_PROCEEDING: - case C.STATUS_COMPLETED: - tr.transport.send(tr.last_response); - break; - } - - return true; - } - - break; - } -} - -module.exports = { - C: C, - NonInviteClientTransaction: NonInviteClientTransaction, - InviteClientTransaction: InviteClientTransaction, - AckClientTransaction: AckClientTransaction, - NonInviteServerTransaction: NonInviteServerTransaction, - InviteServerTransaction: InviteServerTransaction, - checkTransaction: checkTransaction -}; -},{"./Constants":2,"./SIPMessage":19,"./Timers":21,"debug":30,"events":29}],23:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Socket = require('./Socket'); - -var debug = require('debug')('JsSIP:Transport'); - -var debugerror = require('debug')('JsSIP:ERROR:Transport'); - -var JsSIP_C = require('./Constants'); - -debugerror.log = console.warn.bind(console); -/** - * Constants - */ - -var C = { - // Transport status. - STATUS_CONNECTED: 0, - STATUS_CONNECTING: 1, - STATUS_DISCONNECTED: 2, - // Socket status. - SOCKET_STATUS_READY: 0, - SOCKET_STATUS_ERROR: 1, - // Recovery options. - recovery_options: { - // minimum interval in seconds between recover attempts. - min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL, - // maximum interval in seconds between recover attempts. - max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL - } -}; -/* - * Manages one or multiple JsSIP.Socket instances. - * Is reponsible for transport recovery logic among all socket instances. - * - * @socket JsSIP::Socket instance - */ - -module.exports = /*#__PURE__*/function () { - function Transport(sockets) { - var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options; - - _classCallCheck(this, Transport); - - debug('new()'); - this.status = C.STATUS_DISCONNECTED; // Current socket. - - this.socket = null; // Socket collection. - - this.sockets = []; - this.recovery_options = recovery_options; - this.recover_attempts = 0; - this.recovery_timer = null; - this.close_requested = false; // It seems that TextDecoder is not available in some versions of React-Native. - // See https://github.com/versatica/JsSIP/issues/695 - - try { - this.textDecoder = new TextDecoder('utf8'); - } catch (error) { - debugerror("cannot use TextDecoder: ".concat(error)); - } - - if (typeof sockets === 'undefined') { - throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument'); - } - - if (!(sockets instanceof Array)) { - sockets = [sockets]; - } - - sockets.forEach(function (socket) { - if (!Socket.isSocket(socket.socket)) { - throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance'); - } - - if (socket.weight && !Number(socket.weight)) { - throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number'); - } - - this.sockets.push({ - socket: socket.socket, - weight: socket.weight || 0, - status: C.SOCKET_STATUS_READY - }); - }, this); // Get the socket with higher weight. - - this._getSocket(); - } - /** - * Instance Methods - */ - - - _createClass(Transport, [{ - key: "via_transport", - get: function get() { - return this.socket.via_transport; - } - }, { - key: "url", - get: function get() { - return this.socket.url; - } - }, { - key: "sip_uri", - get: function get() { - return this.socket.sip_uri; - } - }, { - key: "connect", - value: function connect() { - debug('connect()'); - - if (this.isConnected()) { - debug('Transport is already connected'); - return; - } else if (this.isConnecting()) { - debug('Transport is connecting'); - return; - } - - this.close_requested = false; - this.status = C.STATUS_CONNECTING; - this.onconnecting({ - socket: this.socket, - attempts: this.recover_attempts - }); - - if (!this.close_requested) { - // Bind socket event callbacks. - this.socket.onconnect = this._onConnect.bind(this); - this.socket.ondisconnect = this._onDisconnect.bind(this); - this.socket.ondata = this._onData.bind(this); - this.socket.connect(); - } - - return; - } - }, { - key: "disconnect", - value: function disconnect() { - debug('close()'); - this.close_requested = true; - this.recover_attempts = 0; - this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer. - - if (this.recovery_timer !== null) { - clearTimeout(this.recovery_timer); - this.recovery_timer = null; - } // Unbind socket event callbacks. - - - this.socket.onconnect = function () {}; - - this.socket.ondisconnect = function () {}; - - this.socket.ondata = function () {}; - - this.socket.disconnect(); - this.ondisconnect({ - socket: this.socket, - error: false - }); - } - }, { - key: "send", - value: function send(data) { - debug('send()'); - - if (!this.isConnected()) { - debugerror('unable to send message, transport is not connected'); - return false; - } - - var message = data.toString(); - debug("sending message:\n\n".concat(message, "\n")); - return this.socket.send(message); - } - }, { - key: "isConnected", - value: function isConnected() { - return this.status === C.STATUS_CONNECTED; - } - }, { - key: "isConnecting", - value: function isConnecting() { - return this.status === C.STATUS_CONNECTING; - } - /** - * Private API. - */ - - }, { - key: "_reconnect", - value: function _reconnect() { - var _this = this; - - this.recover_attempts += 1; - var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1); - - if (k < this.recovery_options.min_interval) { - k = this.recovery_options.min_interval; - } else if (k > this.recovery_options.max_interval) { - k = this.recovery_options.max_interval; - } - - debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); - this.recovery_timer = setTimeout(function () { - if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) { - // Get the next available socket with higher weight. - _this._getSocket(); // Connect the socket. - - - _this.connect(); - } - }, k * 1000); - } - /** - * get the next available socket with higher weight - */ - - }, { - key: "_getSocket", - value: function _getSocket() { - var candidates = []; - this.sockets.forEach(function (socket) { - if (socket.status === C.SOCKET_STATUS_ERROR) { - return; // continue the array iteration - } else if (candidates.length === 0) { - candidates.push(socket); - } else if (socket.weight > candidates[0].weight) { - candidates = [socket]; - } else if (socket.weight === candidates[0].weight) { - candidates.push(socket); - } - }); - - if (candidates.length === 0) { - // All sockets have failed. reset sockets status. - this.sockets.forEach(function (socket) { - socket.status = C.SOCKET_STATUS_READY; - }); // Get next available socket. - - this._getSocket(); - - return; - } - - var idx = Math.floor(Math.random() * candidates.length); - this.socket = candidates[idx].socket; - } - /** - * Socket Event Handlers - */ - - }, { - key: "_onConnect", - value: function _onConnect() { - this.recover_attempts = 0; - this.status = C.STATUS_CONNECTED; // Clear recovery_timer. - - if (this.recovery_timer !== null) { - clearTimeout(this.recovery_timer); - this.recovery_timer = null; - } - - this.onconnect({ - socket: this - }); - } - }, { - key: "_onDisconnect", - value: function _onDisconnect(error, code, reason) { - this.status = C.STATUS_DISCONNECTED; - this.ondisconnect({ - socket: this.socket, - error: error, - code: code, - reason: reason - }); - - if (this.close_requested) { - return; - } // Update socket status. - else { - this.sockets.forEach(function (socket) { - if (this.socket === socket.socket) { - socket.status = C.SOCKET_STATUS_ERROR; - } - }, this); - } - - this._reconnect(error); - } - }, { - key: "_onData", - value: function _onData(data) { - // CRLF Keep Alive response from server. Ignore it. - if (data === '\r\n') { - debug('received message with CRLF Keep Alive response'); - return; - } // Binary message. - else if (typeof data !== 'string') { - try { - if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data)); - } catch (evt) { - debug('received binary message failed to be converted into string,' + ' message discarded'); - return; - } - - debug("received binary message:\n\n".concat(data, "\n")); - } // Text message. - else { - debug("received text message:\n\n".concat(data, "\n")); - } - - this.ondata({ - transport: this, - message: data - }); - } - }]); - - return Transport; -}(); -},{"./Constants":2,"./Socket":20,"debug":30}],24:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('./Constants'); - -var Registrator = require('./Registrator'); - -var RTCSession = require('./RTCSession'); - -var Message = require('./Message'); - -var Transactions = require('./Transactions'); - -var Transport = require('./Transport'); - -var Utils = require('./Utils'); - -var Exceptions = require('./Exceptions'); - -var URI = require('./URI'); - -var Parser = require('./Parser'); - -var SIPMessage = require('./SIPMessage'); - -var RequestSender = require('./RequestSender'); - -var sanityCheck = require('./sanityCheck'); - -var config = require('./Config'); - -var debug = require('debug')('JsSIP:UA'); - -var debugerror = require('debug')('JsSIP:ERROR:UA'); - -debugerror.log = console.warn.bind(console); -var C = { - // UA status codes. - STATUS_INIT: 0, - STATUS_READY: 1, - STATUS_USER_CLOSED: 2, - STATUS_NOT_READY: 3, - // UA error codes. - CONFIGURATION_ERROR: 1, - NETWORK_ERROR: 2 -}; -/** - * The User-Agent class. - * @class JsSIP.UA - * @param {Object} configuration Configuration parameters. - * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid. - * @throws {TypeError} If no configuration is given. - */ - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(UA, _EventEmitter); - - var _super = _createSuper(UA); - - function UA(configuration) { - var _this; - - _classCallCheck(this, UA); - - debug('new() [configuration:%o]', configuration); - _this = _super.call(this); - _this._cache = { - credentials: {} - }; - _this._configuration = Object.assign({}, config.settings); - _this._dynConfiguration = {}; - _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE). - - _this._applicants = {}; - _this._sessions = {}; - _this._transport = null; - _this._contact = null; - _this._status = C.STATUS_INIT; - _this._error = null; - _this._transactions = { - nist: {}, - nict: {}, - ist: {}, - ict: {} - }; // Custom UA empty object for high level use. - - _this._data = {}; - _this._closeTimer = null; // Check configuration argument. - - if (configuration === undefined) { - throw new TypeError('Not enough arguments'); - } // Load configuration. - - - try { - _this._loadConfig(configuration); - } catch (e) { - _this._status = C.STATUS_NOT_READY; - _this._error = C.CONFIGURATION_ERROR; - throw e; - } // Initialize registrator. - - - _this._registrator = new Registrator(_assertThisInitialized(_this)); - return _this; - } - - _createClass(UA, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "configuration", - get: function get() { - return this._configuration; - } - }, { - key: "transport", - get: function get() { - return this._transport; - } // ================= - // High Level API - // ================= - - /** - * Connect to the server if status = STATUS_INIT. - * Resume UA after being closed. - */ - - }, { - key: "start", - value: function start() { - debug('start()'); - - if (this._status === C.STATUS_INIT) { - this._transport.connect(); - } else if (this._status === C.STATUS_USER_CLOSED) { - debug('restarting UA'); // Disconnect. - - if (this._closeTimer !== null) { - clearTimeout(this._closeTimer); - this._closeTimer = null; - - this._transport.disconnect(); - } // Reconnect. - - - this._status = C.STATUS_INIT; - - this._transport.connect(); - } else if (this._status === C.STATUS_READY) { - debug('UA is in READY status, not restarted'); - } else { - debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); - } // Set dynamic configuration. - - - this._dynConfiguration.register = this._configuration.register; - } - /** - * Register. - */ - - }, { - key: "register", - value: function register() { - debug('register()'); - this._dynConfiguration.register = true; - - this._registrator.register(); - } - /** - * Unregister. - */ - - }, { - key: "unregister", - value: function unregister(options) { - debug('unregister()'); - this._dynConfiguration.register = false; - - this._registrator.unregister(options); - } - /** - * Get the Registrator instance. - */ - - }, { - key: "registrator", - value: function registrator() { - return this._registrator; - } - /** - * Registration state. - */ - - }, { - key: "isRegistered", - value: function isRegistered() { - return this._registrator.registered; - } - /** - * Connection state. - */ - - }, { - key: "isConnected", - value: function isConnected() { - return this._transport.isConnected(); - } - /** - * Make an outgoing call. - * - * -param {String} target - * -param {Object} [options] - * - * -throws {TypeError} - * - */ - - }, { - key: "call", - value: function call(target, options) { - debug('call()'); - var session = new RTCSession(this); - session.connect(target, options); - return session; - } - /** - * Send a message. - * - * -param {String} target - * -param {String} body - * -param {Object} [options] - * - * -throws {TypeError} - * - */ - - }, { - key: "sendMessage", - value: function sendMessage(target, body, options) { - debug('sendMessage()'); - var message = new Message(this); - message.send(target, body, options); - return message; - } - /* arbitrary client transaction */ - - }, { - key: "sendRequest", - value: function sendRequest(method, target, params, headers, body, handlers, credential) { - debug('sendRequest()'); - var request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); - var requestSender = new RequestSender(this, request, handlers, credential); - requestSender.send(); - } - /** - * Terminate ongoing sessions. - */ - - }, { - key: "terminateSessions", - value: function terminateSessions(options) { - debug('terminateSessions()'); - - for (var idx in this._sessions) { - if (!this._sessions[idx].isEnded()) { - this._sessions[idx].terminate(options); - } - } - } - /** - * Gracefully close. - * - */ - - }, { - key: "stop", - value: function stop() { - var _this2 = this; - - debug('stop()'); // Remove dynamic settings. - - this._dynConfiguration = {}; - - if (this._status === C.STATUS_USER_CLOSED) { - debug('UA already closed'); - return; - } // Close registrator. - - - this._registrator.close(); // If there are session wait a bit so CANCEL/BYE can be sent and their responses received. - - - var num_sessions = Object.keys(this._sessions).length; // Run _terminate_ on every Session. - - for (var session in this._sessions) { - if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { - debug("closing session ".concat(session)); - - try { - this._sessions[session].terminate(); - } catch (error) {} - } - } // Run _close_ on every applicant. - - - for (var applicant in this._applicants) { - if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try { - this._applicants[applicant].close(); - } catch (error) {} - } - - this._status = C.STATUS_USER_CLOSED; - var num_transactions = Object.keys(this._transactions.nict).length + Object.keys(this._transactions.nist).length + Object.keys(this._transactions.ict).length + Object.keys(this._transactions.ist).length; - - if (num_transactions === 0 && num_sessions === 0) { - this._transport.disconnect(); - } else { - this._closeTimer = setTimeout(function () { - _this2._closeTimer = null; - - _this2._transport.disconnect(); - }, 2000); - } - } - /** - * Normalice a string into a valid SIP request URI - * -param {String} target - * -returns {JsSIP.URI|undefined} - */ - - }, { - key: "normalizeTarget", - value: function normalizeTarget(target) { - return Utils.normalizeTarget(target, this._configuration.hostport_params); - } - /** - * Allow retrieving configuration and autogenerated fields in runtime. - */ - - }, { - key: "get", - value: function get(parameter) { - switch (parameter) { - case 'authorization_user': - return this._configuration.authorization_user; - - case 'realm': - return this._configuration.realm; - - case 'ha1': - return this._configuration.ha1; - - case 'authorization_jwt': - return this._configuration.authorization_jwt; - - default: - debugerror('get() | cannot get "%s" parameter in runtime', parameter); - return undefined; - } - } - /** - * Allow configuration changes in runtime. - * Returns true if the parameter could be set. - */ - - }, { - key: "set", - value: function set(parameter, value) { - switch (parameter) { - case 'authorization_user': - { - this._configuration.authorization_user = String(value); - break; - } - - case 'password': - { - this._configuration.password = String(value); - break; - } - - case 'realm': - { - this._configuration.realm = String(value); - break; - } - - case 'ha1': - { - this._configuration.ha1 = String(value); // Delete the plain SIP password. - - this._configuration.password = null; - break; - } - - case 'authorization_jwt': - { - this._configuration.authorization_jwt = String(value); - break; - } - - case 'display_name': - { - this._configuration.display_name = value; - break; - } - - default: - debugerror('set() | cannot set "%s" parameter in runtime', parameter); - return false; - } - - return true; - } // ========================== - // Event Handlers. - // ========================== - - /** - * new Transaction - */ - - }, { - key: "newTransaction", - value: function newTransaction(transaction) { - this._transactions[transaction.type][transaction.id] = transaction; - this.emit('newTransaction', { - transaction: transaction - }); - } - /** - * Transaction destroyed. - */ - - }, { - key: "destroyTransaction", - value: function destroyTransaction(transaction) { - delete this._transactions[transaction.type][transaction.id]; - this.emit('transactionDestroyed', { - transaction: transaction - }); - } - /** - * new Dialog - */ - - }, { - key: "newDialog", - value: function newDialog(dialog) { - this._dialogs[dialog.id] = dialog; - } - /** - * Dialog destroyed. - */ - - }, { - key: "destroyDialog", - value: function destroyDialog(dialog) { - delete this._dialogs[dialog.id]; - } - /** - * new Message - */ - - }, { - key: "newMessage", - value: function newMessage(message, data) { - this._applicants[message] = message; - this.emit('newMessage', data); - } - /** - * Message destroyed. - */ - - }, { - key: "destroyMessage", - value: function destroyMessage(message) { - delete this._applicants[message]; - } - /** - * new RTCSession - */ - - }, { - key: "newRTCSession", - value: function newRTCSession(session, data) { - this._sessions[session.id] = session; - this.emit('newRTCSession', data); - } - /** - * RTCSession destroyed. - */ - - }, { - key: "destroyRTCSession", - value: function destroyRTCSession(session) { - delete this._sessions[session.id]; - } - /** - * Registered - */ - - }, { - key: "registered", - value: function registered(data) { - this.emit('registered', data); - } - /** - * Unregistered - */ - - }, { - key: "unregistered", - value: function unregistered(data) { - this.emit('unregistered', data); - } - /** - * Registration Failed - */ - - }, { - key: "registrationFailed", - value: function registrationFailed(data) { - this.emit('registrationFailed', data); - } // ========================= - // ReceiveRequest. - // ========================= - - /** - * Request reception - */ - - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - var method = request.method; // Check that request URI points to us. - - if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { - debug('Request-URI does not point to us'); - - if (request.method !== JsSIP_C.ACK) { - request.reply_sl(404); - } - - return; - } // Check request URI scheme. - - - if (request.ruri.scheme === JsSIP_C.SIPS) { - request.reply_sl(416); - return; - } // Check transaction. - - - if (Transactions.checkTransaction(this, request)) { - return; - } // Create the server transaction. - - - if (method === JsSIP_C.INVITE) { - /* eslint-disable no-new */ - new Transactions.InviteServerTransaction(this, this._transport, request); - /* eslint-enable no-new */ - } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) { - /* eslint-disable no-new */ - new Transactions.NonInviteServerTransaction(this, this._transport, request); - /* eslint-enable no-new */ - } - /* RFC3261 12.2.2 - * Requests that do not change in any way the state of a dialog may be - * received within a dialog (for example, an OPTIONS request). - * They are processed as if they had been received outside the dialog. - */ - - - if (method === JsSIP_C.OPTIONS) { - request.reply(200); - } else if (method === JsSIP_C.MESSAGE) { - if (this.listeners('newMessage').length === 0) { - request.reply(405); - return; - } - - var message = new Message(this); - message.init_incoming(request); - } // incoming subscribe - else if (method === JsSIP_C.SUBSCRIBE) { - if (this.listeners('newSubscribe').length === 0) { - request.reply(405); - return; - } - } else if (method === JsSIP_C.INVITE) { - // Initial INVITE. - if (!request.to_tag && this.listeners('newRTCSession').length === 0) { - request.reply(405); - return; - } - } - - var dialog; - var session; // Initial Request. - - if (!request.to_tag) { - switch (method) { - case JsSIP_C.INVITE: - if (window.RTCPeerConnection) { - // TODO - if (request.hasHeader('replaces')) { - var replaces = request.replaces; - dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag); - - if (dialog) { - session = dialog.owner; - - if (!session.isEnded()) { - session.receiveRequest(request); - } else { - request.reply(603); - } - } else { - request.reply(481); - } - } else { - session = new RTCSession(this); - session.init_incoming(request); - } - } else { - debugerror('INVITE received but WebRTC is not supported'); - request.reply(488); - } - - break; - - case JsSIP_C.BYE: - // Out of dialog BYE received. - request.reply(481); - break; - - case JsSIP_C.CANCEL: - session = this._findSession(request); - - if (session) { - session.receiveRequest(request); - } else { - debug('received CANCEL request for a non existent session'); - } - - break; - - case JsSIP_C.ACK: - /* Absorb it. - * ACK request without a corresponding Invite Transaction - * and without To tag. - */ - break; - - case JsSIP_C.NOTIFY: - // Receive new sip event. - this.emit('sipEvent', { - event: request.event, - request: request - }); - request.reply(200); - break; - - case JsSIP_C.SUBSCRIBE: - // Igor's extension: incoming SUBSCRIBE - this.emit('newSubscribe', { - event: request.event, - request: request - }); - break; - - default: - request.reply(405); - break; - } - } // In-dialog request. - else { - dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag); - - if (dialog) { - dialog.receiveRequest(request); - } else if (method === JsSIP_C.NOTIFY) { - session = this._findSession(request); - - if (session) { - session.receiveRequest(request); - } else { - debug('received NOTIFY request for a non existent subscription'); - request.reply(481, 'Subscription does not exist'); - } - } - /* RFC3261 12.2.2 - * Request with to tag, but no matching dialog found. - * Exception: ACK for an Invite request for which a dialog has not - * been created. - */ - else if (method !== JsSIP_C.ACK) { - request.reply(481); - } - } - } // ================= - // Utils. - // ================= - - /** - * Get the session to which the request belongs to, if any. - */ - - }, { - key: "_findSession", - value: function _findSession(_ref) { - var call_id = _ref.call_id, - from_tag = _ref.from_tag, - to_tag = _ref.to_tag; - var sessionIDa = call_id + from_tag; - var sessionA = this._sessions[sessionIDa]; - var sessionIDb = call_id + to_tag; - var sessionB = this._sessions[sessionIDb]; - - if (sessionA) { - return sessionA; - } else if (sessionB) { - return sessionB; - } else { - return null; - } - } - /** - * Get the dialog to which the request belongs to, if any. - */ - - }, { - key: "_findDialog", - value: function _findDialog(call_id, from_tag, to_tag) { - var id = call_id + from_tag + to_tag; - var dialog = this._dialogs[id]; - - if (dialog) { - return dialog; - } else { - id = call_id + to_tag + from_tag; - dialog = this._dialogs[id]; - - if (dialog) { - return dialog; - } else { - return null; - } - } - } - }, { - key: "_loadConfig", - value: function _loadConfig(configuration) { - // Check and load the given configuration. - try { - config.load(this._configuration, configuration); - } catch (e) { - throw e; - } // Post Configuration Process. - // Allow passing 0 number as display_name. - - - if (this._configuration.display_name === 0) { - this._configuration.display_name = '0'; - } // Instance-id for GRUU. - - - if (!this._configuration.instance_id) { - this._configuration.instance_id = Utils.newUUID(); - } // Jssip_id instance parameter. Static random tag of length 5. - - - this._configuration.jssip_id = Utils.createRandomToken(5); // String containing this._configuration.uri without scheme and user. - - var hostport_params = this._configuration.uri.clone(); - - hostport_params.user = null; - this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, ''); // Transport. - - try { - this._transport = new Transport(this._configuration.sockets, { - // Recovery options. - max_interval: this._configuration.connection_recovery_max_interval, - min_interval: this._configuration.connection_recovery_min_interval - }); // Transport event callbacks. - - this._transport.onconnecting = onTransportConnecting.bind(this); - this._transport.onconnect = onTransportConnect.bind(this); - this._transport.ondisconnect = onTransportDisconnect.bind(this); - this._transport.ondata = onTransportData.bind(this); - } catch (e) { - debugerror(e); - throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); - } // Remove sockets instance from configuration object. - - - delete this._configuration.sockets; // Check whether authorization_user is explicitly defined. - // Take 'this._configuration.uri.user' value if not. - - if (!this._configuration.authorization_user) { - this._configuration.authorization_user = this._configuration.uri.user; - } // If no 'registrar_server' is set use the 'uri' value without user portion and - // without URI params/headers. - - - if (!this._configuration.registrar_server) { - var registrar_server = this._configuration.uri.clone(); - - registrar_server.user = null; - registrar_server.clearParams(); - registrar_server.clearHeaders(); - this._configuration.registrar_server = registrar_server; - } // User no_answer_timeout. - - - this._configuration.no_answer_timeout *= 1000; // Via Host. - - if (this._configuration.contact_uri) { - this._configuration.via_host = this._configuration.contact_uri.host; - } // Contact URI. - else { - this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, { - transport: 'ws' - }); - } - - this._contact = { - pub_gruu: null, - temp_gruu: null, - uri: this._configuration.contact_uri, - toString: function toString() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var anonymous = options.anonymous || null; - var outbound = options.outbound || null; - var contact = '<'; - - if (anonymous) { - contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws'; - } else { - contact += this.pub_gruu || this.uri.toString(); - } - - if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) { - contact += ';ob'; - } - - contact += '>'; - return contact; - } - }; // Seal the configuration. - - var writable_parameters = ['authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register']; - - for (var parameter in this._configuration) { - if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) { - if (writable_parameters.indexOf(parameter) !== -1) { - Object.defineProperty(this._configuration, parameter, { - writable: true, - configurable: false - }); - } else { - Object.defineProperty(this._configuration, parameter, { - writable: false, - configurable: false - }); - } - } - } - - debug('configuration parameters after validation:'); - - for (var _parameter in this._configuration) { - // Only show the user user configurable parameters. - if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) { - switch (_parameter) { - case 'uri': - case 'registrar_server': - debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); - break; - - case 'password': - case 'ha1': - case 'authorization_jwt': - debug("- ".concat(_parameter, ": NOT SHOWN")); - break; - - default: - debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); - } - } - } - - return; - } - }], [{ - key: "C", - get: // Expose C object. - function get() { - return C; - } - }]); - - return UA; -}(EventEmitter); -/** - * Transport event handlers - */ -// Transport connecting event. - - -function onTransportConnecting(data) { - this.emit('connecting', data); -} // Transport connected event. - - -function onTransportConnect(data) { - if (this._status === C.STATUS_USER_CLOSED) { - return; - } - - this._status = C.STATUS_READY; - this._error = null; - this.emit('connected', data); - - if (this._dynConfiguration.register) { - this._registrator.register(); - } -} // Transport disconnected event. - - -function onTransportDisconnect(data) { - // Run _onTransportError_ callback on every client transaction using _transport_. - var client_transactions = ['nict', 'ict', 'nist', 'ist']; - - for (var _i = 0, _client_transactions = client_transactions; _i < _client_transactions.length; _i++) { - var type = _client_transactions[_i]; - - for (var id in this._transactions[type]) { - if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) { - this._transactions[type][id].onTransportError(); - } - } - } - - this.emit('disconnected', data); // Call registrator _onTransportClosed_. - - this._registrator.onTransportClosed(); - - if (this._status !== C.STATUS_USER_CLOSED) { - this._status = C.STATUS_NOT_READY; - this._error = C.NETWORK_ERROR; - } -} // Transport data event. - - -function onTransportData(data) { - var transport = data.transport; - var message = data.message; - message = Parser.parseMessage(message, this); - - if (!message) { - return; - } - - if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) { - return; - } // Do some sanity check. - - - if (!sanityCheck(message, this, transport)) { - return; - } - - if (message instanceof SIPMessage.IncomingRequest) { - message.transport = transport; - this.receiveRequest(message); - } else if (message instanceof SIPMessage.IncomingResponse) { - /* Unike stated in 18.1.2, if a response does not match - * any transaction, it is discarded here and no passed to the core - * in order to be discarded there. - */ - var transaction; - - switch (message.method) { - case JsSIP_C.INVITE: - transaction = this._transactions.ict[message.via_branch]; - - if (transaction) { - transaction.receiveResponse(message); - } - - break; - - case JsSIP_C.ACK: - // Just in case ;-). - break; - - default: - transaction = this._transactions.nict[message.via_branch]; - - if (transaction) { - transaction.receiveResponse(message); - } - - break; - } - } -} -},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./RequestSender":18,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":30,"events":29}],25:[function(require,module,exports){ -"use strict"; - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var JsSIP_C = require('./Constants'); - -var Utils = require('./Utils'); - -var Grammar = require('./Grammar'); -/** - * -param {String} [scheme] - * -param {String} [user] - * -param {String} host - * -param {String} [port] - * -param {Object} [parameters] - * -param {Object} [headers] - * - */ - - -module.exports = /*#__PURE__*/function () { - function URI(scheme, user, host, port) { - var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; - var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; - - _classCallCheck(this, URI); - - // Checks. - if (!host) { - throw new TypeError('missing or invalid "host" parameter'); - } // Initialize parameters. - - - this._parameters = {}; - this._headers = {}; - this._scheme = scheme || JsSIP_C.SIP; - this._user = user; - this._host = host; - this._port = port; - - for (var param in parameters) { - if (Object.prototype.hasOwnProperty.call(parameters, param)) { - this.setParam(param, parameters[param]); - } - } - - for (var header in headers) { - if (Object.prototype.hasOwnProperty.call(headers, header)) { - this.setHeader(header, headers[header]); - } - } - } - - _createClass(URI, [{ - key: "scheme", - get: function get() { - return this._scheme; - }, - set: function set(value) { - this._scheme = value.toLowerCase(); - } - }, { - key: "user", - get: function get() { - return this._user; - }, - set: function set(value) { - this._user = value; - } - }, { - key: "host", - get: function get() { - return this._host; - }, - set: function set(value) { - this._host = value.toLowerCase(); - } - }, { - key: "port", - get: function get() { - return this._port; - }, - set: function set(value) { - this._port = value === 0 ? value : parseInt(value, 10) || null; - } - }, { - key: "setParam", - value: function setParam(key, value) { - if (key) { - this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString(); - } - } - }, { - key: "getParam", - value: function getParam(key) { - if (key) { - return this._parameters[key.toLowerCase()]; - } - } - }, { - key: "hasParam", - value: function hasParam(key) { - if (key) { - return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false; - } - } - }, { - key: "deleteParam", - value: function deleteParam(parameter) { - parameter = parameter.toLowerCase(); - - if (this._parameters.hasOwnProperty(parameter)) { - var value = this._parameters[parameter]; - delete this._parameters[parameter]; - return value; - } - } - }, { - key: "clearParams", - value: function clearParams() { - this._parameters = {}; - } - }, { - key: "setHeader", - value: function setHeader(name, value) { - this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value]; - } - }, { - key: "getHeader", - value: function getHeader(name) { - if (name) { - return this._headers[Utils.headerize(name)]; - } - } - }, { - key: "hasHeader", - value: function hasHeader(name) { - if (name) { - return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false; - } - } - }, { - key: "deleteHeader", - value: function deleteHeader(header) { - header = Utils.headerize(header); - - if (this._headers.hasOwnProperty(header)) { - var value = this._headers[header]; - delete this._headers[header]; - return value; - } - } - }, { - key: "clearHeaders", - value: function clearHeaders() { - this._headers = {}; - } - }, { - key: "clone", - value: function clone() { - return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers))); - } - }, { - key: "toString", - value: function toString() { - var headers = []; - var uri = "".concat(this._scheme, ":"); - - if (this._user) { - uri += "".concat(Utils.escapeUser(this._user), "@"); - } - - uri += this._host; - - if (this._port || this._port === 0) { - uri += ":".concat(this._port); - } - - for (var parameter in this._parameters) { - if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) { - uri += ";".concat(parameter); - - if (this._parameters[parameter] !== null) { - uri += "=".concat(this._parameters[parameter]); - } - } - } - - for (var header in this._headers) { - if (Object.prototype.hasOwnProperty.call(this._headers, header)) { - var _iterator = _createForOfIteratorHelper(this._headers[header]), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var item = _step.value; - headers.push("".concat(header, "=").concat(item)); - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } - } - - if (headers.length > 0) { - uri += "?".concat(headers.join('&')); - } - - return uri; - } - }, { - key: "toAor", - value: function toAor(show_port) { - var aor = "".concat(this._scheme, ":"); - - if (this._user) { - aor += "".concat(Utils.escapeUser(this._user), "@"); - } - - aor += this._host; - - if (show_port && (this._port || this._port === 0)) { - aor += ":".concat(this._port); - } - - return aor; - } - }], [{ - key: "parse", - value: - /** - * Parse the given string and returns a JsSIP.URI instance or undefined if - * it is an invalid URI. - */ - function parse(uri) { - uri = Grammar.parse(uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } else { - return undefined; - } - } - }]); - - return URI; -}(); -},{"./Constants":2,"./Grammar":7,"./Utils":26}],26:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var JsSIP_C = require('./Constants'); - -var URI = require('./URI'); - -var Grammar = require('./Grammar'); - -exports.str_utf8_length = function (string) { - return unescape(encodeURIComponent(string)).length; -}; // Used by 'hasMethods'. - - -var isFunction = exports.isFunction = function (fn) { - if (fn !== undefined) { - return Object.prototype.toString.call(fn) === '[object Function]' ? true : false; - } else { - return false; - } -}; - -exports.isString = function (str) { - if (str !== undefined) { - return Object.prototype.toString.call(str) === '[object String]' ? true : false; - } else { - return false; - } -}; - -exports.isDecimal = function (num) { - return !isNaN(num) && parseFloat(num) === parseInt(num, 10); -}; - -exports.isEmpty = function (value) { - return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value); -}; - -exports.hasMethods = function (obj) { - for (var _len = arguments.length, methodNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - methodNames[_key - 1] = arguments[_key]; - } - - for (var _i = 0, _methodNames = methodNames; _i < _methodNames.length; _i++) { - var methodName = _methodNames[_i]; - - if (isFunction(obj[methodName])) { - return false; - } - } - - return true; -}; // Used by 'newTag'. - - -var createRandomToken = exports.createRandomToken = function (size) { - var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32; - var i, - r, - token = ''; - - for (i = 0; i < size; i++) { - r = Math.random() * base | 0; - token += r.toString(base); - } - - return token; -}; - -exports.newTag = function () { - return createRandomToken(10); -}; // https://stackoverflow.com/users/109538/broofa. - - -exports.newUUID = function () { - var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r = Math.random() * 16 | 0, - v = c === 'x' ? r : r & 0x3 | 0x8; - return v.toString(16); - }); - return UUID; -}; - -exports.hostType = function (host) { - if (!host) { - return; - } else { - host = Grammar.parse(host, 'host'); - - if (host !== -1) { - return host.host_type; - } - } -}; -/** -* Hex-escape a SIP URI user. -* Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F). -* -* Used by 'normalizeTarget'. -*/ - - -var escapeUser = exports.escapeUser = function (user) { - return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/'); -}; -/** -* Normalize SIP URI. -* NOTE: It does not allow a SIP URI without username. -* Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'. -* Detects the domain part (if given) and properly hex-escapes the user portion. -* If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators. -*/ - - -exports.normalizeTarget = function (target, domain) { - // If no target is given then raise an error. - if (!target) { - return; // If a URI instance is given then return it. - } else if (target instanceof URI) { - return target; // If a string is given split it by '@': - // - Last fragment is the desired domain. - // - Otherwise append the given domain argument. - } else if (typeof target === 'string') { - var target_array = target.split('@'); - var target_user; - var target_domain; - - switch (target_array.length) { - case 1: - if (!domain) { - return; - } - - target_user = target; - target_domain = domain; - break; - - case 2: - target_user = target_array[0]; - target_domain = target_array[1]; - break; - - default: - target_user = target_array.slice(0, target_array.length - 1).join('@'); - target_domain = target_array[target_array.length - 1]; - } // Remove the URI scheme (if present). - - - target_user = target_user.replace(/^(sips?|tel):/i, ''); // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols. - - if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) { - target_user = target_user.replace(/[-.()]/g, ''); - } // Build the complete SIP URI. - - - target = "".concat(JsSIP_C.SIP, ":").concat(escapeUser(target_user), "@").concat(target_domain); // Finally parse the resulting URI. - - var uri; - - if (uri = URI.parse(target)) { - return uri; - } else { - return; - } - } else { - return; - } -}; - -exports.headerize = function (string) { - var exceptions = { - 'Call-Id': 'Call-ID', - 'Cseq': 'CSeq', - 'Www-Authenticate': 'WWW-Authenticate' - }; - var name = string.toLowerCase().replace(/_/g, '-').split('-'); - var hname = ''; - var parts = name.length; - var part; - - for (part = 0; part < parts; part++) { - if (part !== 0) { - hname += '-'; - } - - hname += name[part].charAt(0).toUpperCase() + name[part].substring(1); - } - - if (exceptions[hname]) { - hname = exceptions[hname]; - } - - return hname; -}; - -exports.sipErrorCause = function (status_code) { - for (var cause in JsSIP_C.SIP_ERROR_CAUSES) { - if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) { - return JsSIP_C.causes[cause]; - } - } - - return JsSIP_C.causes.SIP_FAILURE_CODE; -}; -/** -* Generate a random Test-Net IP (https://tools.ietf.org/html/rfc5735) -*/ - - -exports.getRandomTestNetIP = function () { - function getOctet(from, to) { - return Math.floor(Math.random() * (to - from + 1) + from); - } - - return "192.0.2.".concat(getOctet(1, 254)); -}; // MD5 (Message-Digest Algorithm) https://www.webtoolkit.info. - - -exports.calculateMD5 = function (string) { - function rotateLeft(lValue, iShiftBits) { - return lValue << iShiftBits | lValue >>> 32 - iShiftBits; - } - - function addUnsigned(lX, lY) { - var lX8 = lX & 0x80000000; - var lY8 = lY & 0x80000000; - var lX4 = lX & 0x40000000; - var lY4 = lY & 0x40000000; - var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); - - if (lX4 & lY4) { - return lResult ^ 0x80000000 ^ lX8 ^ lY8; - } - - if (lX4 | lY4) { - if (lResult & 0x40000000) { - return lResult ^ 0xC0000000 ^ lX8 ^ lY8; - } else { - return lResult ^ 0x40000000 ^ lX8 ^ lY8; - } - } else { - return lResult ^ lX8 ^ lY8; - } - } - - function doF(x, y, z) { - return x & y | ~x & z; - } - - function doG(x, y, z) { - return x & z | y & ~z; - } - - function doH(x, y, z) { - return x ^ y ^ z; - } - - function doI(x, y, z) { - return y ^ (x | ~z); - } - - function doFF(a, b, c, d, x, s, ac) { - a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac)); - return addUnsigned(rotateLeft(a, s), b); - } - - function doGG(a, b, c, d, x, s, ac) { - a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac)); - return addUnsigned(rotateLeft(a, s), b); - } - - function doHH(a, b, c, d, x, s, ac) { - a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac)); - return addUnsigned(rotateLeft(a, s), b); - } - - function doII(a, b, c, d, x, s, ac) { - a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac)); - return addUnsigned(rotateLeft(a, s), b); - } - - function convertToWordArray(str) { - var lWordCount; - var lMessageLength = str.length; - var lNumberOfWords_temp1 = lMessageLength + 8; - var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64; - var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; - var lWordArray = new Array(lNumberOfWords - 1); - var lBytePosition = 0; - var lByteCount = 0; - - while (lByteCount < lMessageLength) { - lWordCount = (lByteCount - lByteCount % 4) / 4; - lBytePosition = lByteCount % 4 * 8; - lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition; - lByteCount++; - } - - lWordCount = (lByteCount - lByteCount % 4) / 4; - lBytePosition = lByteCount % 4 * 8; - lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition; - lWordArray[lNumberOfWords - 2] = lMessageLength << 3; - lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; - return lWordArray; - } - - function wordToHex(lValue) { - var wordToHexValue = '', - wordToHexValue_temp = '', - lByte, - lCount; - - for (lCount = 0; lCount <= 3; lCount++) { - lByte = lValue >>> lCount * 8 & 255; - wordToHexValue_temp = "0".concat(lByte.toString(16)); - wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2); - } - - return wordToHexValue; - } - - function utf8Encode(str) { - str = str.replace(/\r\n/g, '\n'); - var utftext = ''; - - for (var n = 0; n < str.length; n++) { - var _c = str.charCodeAt(n); - - if (_c < 128) { - utftext += String.fromCharCode(_c); - } else if (_c > 127 && _c < 2048) { - utftext += String.fromCharCode(_c >> 6 | 192); - utftext += String.fromCharCode(_c & 63 | 128); - } else { - utftext += String.fromCharCode(_c >> 12 | 224); - utftext += String.fromCharCode(_c >> 6 & 63 | 128); - utftext += String.fromCharCode(_c & 63 | 128); - } - } - - return utftext; - } - - var x = []; - var k, AA, BB, CC, DD, a, b, c, d; - var S11 = 7, - S12 = 12, - S13 = 17, - S14 = 22; - var S21 = 5, - S22 = 9, - S23 = 14, - S24 = 20; - var S31 = 4, - S32 = 11, - S33 = 16, - S34 = 23; - var S41 = 6, - S42 = 10, - S43 = 15, - S44 = 21; - string = utf8Encode(string); - x = convertToWordArray(string); - a = 0x67452301; - b = 0xEFCDAB89; - c = 0x98BADCFE; - d = 0x10325476; - - for (k = 0; k < x.length; k += 16) { - AA = a; - BB = b; - CC = c; - DD = d; - a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478); - d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); - c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB); - b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); - a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); - d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A); - c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613); - b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501); - a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8); - d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); - c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); - b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); - a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122); - d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193); - c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E); - b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821); - a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562); - d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340); - c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51); - b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); - a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D); - d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453); - c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); - b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); - a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); - d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6); - c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); - b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED); - a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); - d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); - c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9); - b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); - a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); - d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681); - c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); - b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); - a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); - d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); - c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); - b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); - a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); - d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); - c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); - b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05); - a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); - d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); - c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); - b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); - a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244); - d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97); - c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7); - b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039); - a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3); - d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); - c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); - b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1); - a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); - d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); - c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314); - b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1); - a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82); - d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235); - c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); - b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391); - a = addUnsigned(a, AA); - b = addUnsigned(b, BB); - c = addUnsigned(c, CC); - d = addUnsigned(d, DD); - } - - var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); - return temp.toLowerCase(); -}; - -exports.closeMediaStream = function (stream) { - if (!stream) { - return; - } // Latest spec states that MediaStream has no stop() method and instead must - // call stop() on every MediaStreamTrack. - - - try { - var tracks; - - if (stream.getTracks) { - tracks = stream.getTracks(); - - var _iterator = _createForOfIteratorHelper(tracks), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var track = _step.value; - track.stop(); - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } else { - tracks = stream.getAudioTracks(); - - var _iterator2 = _createForOfIteratorHelper(tracks), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var _track = _step2.value; - - _track.stop(); - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - - tracks = stream.getVideoTracks(); - - var _iterator3 = _createForOfIteratorHelper(tracks), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var _track2 = _step3.value; - - _track2.stop(); - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } - } - } catch (error) { - // Deprecated by the spec, but still in use. - // NOTE: In Temasys IE plugin stream.stop is a callable 'object'. - if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') { - stream.stop(); - } - } -}; - -exports.cloneArray = function (array) { - return array && array.slice() || []; -}; - -exports.cloneObject = function (obj) { - var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - return obj && Object.assign({}, obj) || fallback; -}; -},{"./Constants":2,"./Grammar":7,"./URI":25}],27:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Grammar = require('./Grammar'); - -var debug = require('debug')('JsSIP:WebSocketInterface'); - -var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); - -debugerror.log = console.warn.bind(console); - -module.exports = /*#__PURE__*/function () { - function WebSocketInterface(url) { - _classCallCheck(this, WebSocketInterface); - - debug('new() [url:"%s"]', url); - this._url = url; - this._sip_uri = null; - this._via_transport = null; - this._ws = null; - var parsed_url = Grammar.parse(url, 'absoluteURI'); - - if (parsed_url === -1) { - debugerror("invalid WebSocket URI: ".concat(url)); - throw new TypeError("Invalid argument: ".concat(url)); - } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { - debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); - throw new TypeError("Invalid argument: ".concat(url)); - } else { - this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws"); - this._via_transport = parsed_url.scheme.toUpperCase(); - } - } - - _createClass(WebSocketInterface, [{ - key: "via_transport", - get: function get() { - return this._via_transport; - }, - set: function set(value) { - this._via_transport = value.toUpperCase(); - } - }, { - key: "sip_uri", - get: function get() { - return this._sip_uri; - } - }, { - key: "url", - get: function get() { - return this._url; - } - }, { - key: "connect", - value: function connect() { - debug('connect()'); - - if (this.isConnected()) { - debug("WebSocket ".concat(this._url, " is already connected")); - return; - } else if (this.isConnecting()) { - debug("WebSocket ".concat(this._url, " is connecting")); - return; - } - - if (this._ws) { - this.disconnect(); - } - - debug("connecting to WebSocket ".concat(this._url)); - - try { - this._ws = new WebSocket(this._url, 'sip'); - this._ws.binaryType = 'arraybuffer'; - this._ws.onopen = this._onOpen.bind(this); - this._ws.onclose = this._onClose.bind(this); - this._ws.onmessage = this._onMessage.bind(this); - this._ws.onerror = this._onError.bind(this); - } catch (e) { - this._onError(e); - } - } - }, { - key: "disconnect", - value: function disconnect() { - debug('disconnect()'); - - if (this._ws) { - // Unbind websocket event callbacks. - 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 send(message) { - debug('send()'); - - if (this.isConnected()) { - this._ws.send(message); - - return true; - } else { - debugerror('unable to send message, WebSocket is not open'); - return false; - } - } - }, { - key: "isConnected", - value: function isConnected() { - return this._ws && this._ws.readyState === this._ws.OPEN; - } - }, { - key: "isConnecting", - value: function isConnecting() { - return this._ws && this._ws.readyState === this._ws.CONNECTING; - } - /** - * WebSocket Event Handlers - */ - - }, { - key: "_onOpen", - value: function _onOpen() { - debug("WebSocket ".concat(this._url, " connected")); - this.onconnect(); - } - }, { - key: "_onClose", - value: function _onClose(_ref) { - var wasClean = _ref.wasClean, - code = _ref.code, - reason = _ref.reason; - debug("WebSocket ".concat(this._url, " closed")); - - if (wasClean === false) { - debug('WebSocket abrupt disconnection'); - } - - this.ondisconnect(!wasClean, code, reason); - } - }, { - key: "_onMessage", - value: function _onMessage(_ref2) { - var data = _ref2.data; - debug('received WebSocket message'); - this.ondata(data); - } - }, { - key: "_onError", - value: function _onError(e) { - debugerror("WebSocket ".concat(this._url, " error: "), e); - } - }]); - - return WebSocketInterface; -}(); -},{"./Grammar":7,"debug":30}],28:[function(require,module,exports){ -"use strict"; - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var JsSIP_C = require('./Constants'); - -var SIPMessage = require('./SIPMessage'); - -var Utils = require('./Utils'); - -var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses. - - -var all = [minimumHeaders]; // Checks for requests. - -var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2]; // Checks for responses. - -var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response]; // local variables. - -var message; -var ua; -var transport; - -module.exports = function (m, u, t) { - message = m; - ua = u; - transport = t; - - var _iterator = _createForOfIteratorHelper(all), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var _check2 = _step.value; - - if (_check2() === false) { - return false; - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - - if (message instanceof SIPMessage.IncomingRequest) { - var _iterator2 = _createForOfIteratorHelper(requests), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var check = _step2.value; - - if (check() === false) { - return false; - } - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - } else if (message instanceof SIPMessage.IncomingResponse) { - var _iterator3 = _createForOfIteratorHelper(responses), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var _check = _step3.value; - - if (_check() === false) { - return false; - } - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } - } // Everything is OK. - - - return true; -}; -/* - * Sanity Check for incoming Messages - * - * Requests: - * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme - * - _rfc3261_16_3_4_ Receive a Request already sent by us - * Does not look at via sent-by but at jssip_id, which is inserted as - * a prefix in all initial requests generated by the ua - * - _rfc3261_18_3_request_ Body Content-Length - * - _rfc3261_8_2_2_2_ Merged Requests - * - * Responses: - * - _rfc3261_8_1_3_3_ Multiple Via headers - * - _rfc3261_18_3_response_ Body Content-Length - * - * All: - * - Minimum headers in a SIP message - */ -// Sanity Check functions for requests. - - -function rfc3261_8_2_2_1() { - if (message.s('to').uri.scheme !== 'sip') { - reply(416); - return false; - } -} - -function rfc3261_16_3_4() { - if (!message.to_tag) { - if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) { - reply(482); - return false; - } - } -} - -function rfc3261_18_3_request() { - var len = Utils.str_utf8_length(message.body); - var contentLength = message.getHeader('content-length'); - - if (len < contentLength) { - reply(400); - return false; - } -} - -function rfc3261_8_2_2_2() { - var fromTag = message.from_tag; - var call_id = message.call_id; - var cseq = message.cseq; - var tr; // Accept any in-dialog request. - - if (message.to_tag) { - return; - } // INVITE request. - - - if (message.method === JsSIP_C.INVITE) { - // If the branch matches the key of any IST then assume it is a retransmission - // and ignore the INVITE. - // TODO: we should reply the last response. - if (ua._transactions.ist[message.via_branch]) { - return false; - } // Otherwise check whether it is a merged request. - else { - for (var transaction in ua._transactions.ist) { - if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) { - tr = ua._transactions.ist[transaction]; - - if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) { - reply(482); - return false; - } - } - } - } - } // Non INVITE request. - // If the branch matches the key of any NIST then assume it is a retransmission - // and ignore the request. - // TODO: we should reply the last response. - else if (ua._transactions.nist[message.via_branch]) { - return false; - } // Otherwise check whether it is a merged request. - else { - for (var _transaction in ua._transactions.nist) { - if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) { - tr = ua._transactions.nist[_transaction]; - - if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) { - reply(482); - return false; - } - } - } - } -} // Sanity Check functions for responses. - - -function rfc3261_8_1_3_3() { - if (message.getHeaders('via').length > 1) { - debug('more than one Via header field present in the response, dropping the response'); - return false; - } -} - -function rfc3261_18_3_response() { - var len = Utils.str_utf8_length(message.body), - contentLength = message.getHeader('content-length'); - - if (len < contentLength) { - debug('message body length is lower than the value in Content-Length header field, dropping the response'); - return false; - } -} // Sanity Check functions for requests and responses. - - -function minimumHeaders() { - var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via']; - - for (var _i = 0, _mandatoryHeaders = mandatoryHeaders; _i < _mandatoryHeaders.length; _i++) { - var header = _mandatoryHeaders[_i]; - - if (!message.hasHeader(header)) { - debug("missing mandatory header field : ".concat(header, ", dropping the response")); - return false; - } - } -} // Reply. - - -function reply(status_code) { - var vias = message.getHeaders('via'); - var to; - var response = "SIP/2.0 ".concat(status_code, " ").concat(JsSIP_C.REASON_PHRASE[status_code], "\r\n"); - - var _iterator4 = _createForOfIteratorHelper(vias), - _step4; - - try { - for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - var via = _step4.value; - response += "Via: ".concat(via, "\r\n"); - } - } catch (err) { - _iterator4.e(err); - } finally { - _iterator4.f(); - } - - to = message.getHeader('To'); - - if (!message.to_tag) { - to += ";tag=".concat(Utils.newTag()); - } - - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(message.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(message.call_id, "\r\n"); - response += "CSeq: ".concat(message.cseq, " ").concat(message.method, "\r\n"); - response += '\r\n'; - transport.send(response); -} -},{"./Constants":2,"./SIPMessage":19,"./Utils":26,"debug":30}],29:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var objectCreate = Object.create || objectCreatePolyfill -var objectKeys = Object.keys || objectKeysPolyfill -var bind = Function.prototype.bind || functionBindPolyfill - -function EventEmitter() { - if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) { - this._events = objectCreate(null); - this._eventsCount = 0; - } - - this._maxListeners = this._maxListeners || undefined; -} -module.exports = EventEmitter; - -// Backwards-compat with node 0.10.x -EventEmitter.EventEmitter = EventEmitter; - -EventEmitter.prototype._events = undefined; -EventEmitter.prototype._maxListeners = undefined; - -// By default EventEmitters will print a warning if more than 10 listeners are -// added to it. This is a useful default which helps finding memory leaks. -var defaultMaxListeners = 10; - -var hasDefineProperty; -try { - var o = {}; - if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 }); - hasDefineProperty = o.x === 0; -} catch (err) { hasDefineProperty = false } -if (hasDefineProperty) { - Object.defineProperty(EventEmitter, 'defaultMaxListeners', { - enumerable: true, - get: function() { - return defaultMaxListeners; - }, - set: function(arg) { - // check whether the input is a positive number (whose value is zero or - // greater and not a NaN). - if (typeof arg !== 'number' || arg < 0 || arg !== arg) - throw new TypeError('"defaultMaxListeners" must be a positive number'); - defaultMaxListeners = arg; - } - }); -} else { - EventEmitter.defaultMaxListeners = defaultMaxListeners; -} - -// Obviously not all Emitters should be limited to 10. This function allows -// that to be increased. Set to zero for unlimited. -EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { - if (typeof n !== 'number' || n < 0 || isNaN(n)) - throw new TypeError('"n" argument must be a positive number'); - this._maxListeners = n; - return this; -}; - -function $getMaxListeners(that) { - if (that._maxListeners === undefined) - return EventEmitter.defaultMaxListeners; - return that._maxListeners; -} - -EventEmitter.prototype.getMaxListeners = function getMaxListeners() { - return $getMaxListeners(this); -}; - -// These standalone emit* functions are used to optimize calling of event -// handlers for fast cases because emit() itself often has a variable number of -// arguments and can be deoptimized because of that. These functions always have -// the same number of arguments and thus do not get deoptimized, so the code -// inside them can execute faster. -function emitNone(handler, isFn, self) { - if (isFn) - handler.call(self); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].call(self); - } -} -function emitOne(handler, isFn, self, arg1) { - if (isFn) - handler.call(self, arg1); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].call(self, arg1); - } -} -function emitTwo(handler, isFn, self, arg1, arg2) { - if (isFn) - handler.call(self, arg1, arg2); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].call(self, arg1, arg2); - } -} -function emitThree(handler, isFn, self, arg1, arg2, arg3) { - if (isFn) - handler.call(self, arg1, arg2, arg3); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].call(self, arg1, arg2, arg3); - } -} - -function emitMany(handler, isFn, self, args) { - if (isFn) - handler.apply(self, args); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].apply(self, args); - } -} - -EventEmitter.prototype.emit = function emit(type) { - var er, handler, len, args, i, events; - var doError = (type === 'error'); - - events = this._events; - if (events) - doError = (doError && events.error == null); - else if (!doError) - return false; - - // If there is no 'error' event listener then throw. - if (doError) { - if (arguments.length > 1) - er = arguments[1]; - if (er instanceof Error) { - throw er; // Unhandled 'error' event - } else { - // At least give some kind of context to the user - var err = new Error('Unhandled "error" event. (' + er + ')'); - err.context = er; - throw err; - } - return false; - } - - handler = events[type]; - - if (!handler) - return false; - - var isFn = typeof handler === 'function'; - len = arguments.length; - switch (len) { - // fast cases - case 1: - emitNone(handler, isFn, this); - break; - case 2: - emitOne(handler, isFn, this, arguments[1]); - break; - case 3: - emitTwo(handler, isFn, this, arguments[1], arguments[2]); - break; - case 4: - emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]); - break; - // slower - default: - args = new Array(len - 1); - for (i = 1; i < len; i++) - args[i - 1] = arguments[i]; - emitMany(handler, isFn, this, args); - } - - return true; -}; - -function _addListener(target, type, listener, prepend) { - var m; - var events; - var existing; - - if (typeof listener !== 'function') - throw new TypeError('"listener" argument must be a function'); - - events = target._events; - if (!events) { - events = target._events = objectCreate(null); - target._eventsCount = 0; - } else { - // To avoid recursion in the case that type === "newListener"! Before - // adding it to the listeners, first emit "newListener". - if (events.newListener) { - target.emit('newListener', type, - listener.listener ? listener.listener : listener); - - // Re-assign `events` because a newListener handler could have caused the - // this._events to be assigned to a new object - events = target._events; - } - existing = events[type]; - } - - if (!existing) { - // Optimize the case of one listener. Don't need the extra array object. - existing = events[type] = listener; - ++target._eventsCount; - } else { - if (typeof existing === 'function') { - // Adding the second element, need to change to array. - existing = events[type] = - prepend ? [listener, existing] : [existing, listener]; - } else { - // If we've already got an array, just append. - if (prepend) { - existing.unshift(listener); - } else { - existing.push(listener); - } - } - - // Check for listener leak - if (!existing.warned) { - m = $getMaxListeners(target); - if (m && m > 0 && existing.length > m) { - existing.warned = true; - var w = new Error('Possible EventEmitter memory leak detected. ' + - existing.length + ' "' + String(type) + '" listeners ' + - 'added. Use emitter.setMaxListeners() to ' + - 'increase limit.'); - w.name = 'MaxListenersExceededWarning'; - w.emitter = target; - w.type = type; - w.count = existing.length; - if (typeof console === 'object' && console.warn) { - console.warn('%s: %s', w.name, w.message); - } - } - } - } - - return target; -} - -EventEmitter.prototype.addListener = function addListener(type, listener) { - return _addListener(this, type, listener, false); -}; - -EventEmitter.prototype.on = EventEmitter.prototype.addListener; - -EventEmitter.prototype.prependListener = - function prependListener(type, listener) { - return _addListener(this, type, listener, true); - }; - -function onceWrapper() { - if (!this.fired) { - this.target.removeListener(this.type, this.wrapFn); - this.fired = true; - switch (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: - var args = new Array(arguments.length); - for (var i = 0; i < args.length; ++i) - args[i] = arguments[i]; - this.listener.apply(this.target, args); - } - } -} - -function _onceWrap(target, type, listener) { - var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener }; - var wrapped = bind.call(onceWrapper, state); - wrapped.listener = listener; - state.wrapFn = wrapped; - return wrapped; -} - -EventEmitter.prototype.once = function once(type, listener) { - if (typeof listener !== 'function') - throw new TypeError('"listener" argument must be a function'); - this.on(type, _onceWrap(this, type, listener)); - return this; -}; - -EventEmitter.prototype.prependOnceListener = - function prependOnceListener(type, listener) { - if (typeof listener !== 'function') - throw new TypeError('"listener" argument must be a function'); - this.prependListener(type, _onceWrap(this, type, listener)); - return this; - }; - -// Emits a 'removeListener' event if and only if the listener was removed. -EventEmitter.prototype.removeListener = - function removeListener(type, listener) { - var list, events, position, i, originalListener; - - if (typeof listener !== 'function') - throw new TypeError('"listener" argument must be a function'); - - events = this._events; - if (!events) - return this; - - list = events[type]; - if (!list) - return this; - - if (list === listener || list.listener === listener) { - if (--this._eventsCount === 0) - this._events = objectCreate(null); - else { - delete events[type]; - if (events.removeListener) - this.emit('removeListener', type, list.listener || listener); - } - } else if (typeof list !== 'function') { - position = -1; - - for (i = list.length - 1; i >= 0; i--) { - if (list[i] === listener || list[i].listener === listener) { - originalListener = list[i].listener; - position = i; - break; - } - } - - if (position < 0) - return this; - - if (position === 0) - list.shift(); - else - spliceOne(list, position); - - if (list.length === 1) - events[type] = list[0]; - - if (events.removeListener) - this.emit('removeListener', type, originalListener || listener); - } - - return this; - }; - -EventEmitter.prototype.removeAllListeners = - function removeAllListeners(type) { - var listeners, events, i; - - events = this._events; - if (!events) - return this; - - // not listening for removeListener, no need to emit - if (!events.removeListener) { - if (arguments.length === 0) { - this._events = objectCreate(null); - this._eventsCount = 0; - } else if (events[type]) { - if (--this._eventsCount === 0) - this._events = objectCreate(null); - else - delete events[type]; - } - return this; - } - - // emit removeListener for all listeners on all events - if (arguments.length === 0) { - var keys = objectKeys(events); - var key; - for (i = 0; i < keys.length; ++i) { - key = keys[i]; - if (key === 'removeListener') continue; - this.removeAllListeners(key); - } - this.removeAllListeners('removeListener'); - this._events = objectCreate(null); - this._eventsCount = 0; - return this; - } - - listeners = events[type]; - - if (typeof listeners === 'function') { - this.removeListener(type, listeners); - } else if (listeners) { - // LIFO order - for (i = listeners.length - 1; i >= 0; i--) { - this.removeListener(type, listeners[i]); - } - } - - return this; - }; - -function _listeners(target, type, unwrap) { - var events = target._events; - - if (!events) - return []; - - var evlistener = events[type]; - if (!evlistener) - return []; - - if (typeof evlistener === 'function') - return unwrap ? [evlistener.listener || evlistener] : [evlistener]; - - return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); -} - -EventEmitter.prototype.listeners = function listeners(type) { - return _listeners(this, type, true); -}; - -EventEmitter.prototype.rawListeners = function rawListeners(type) { - return _listeners(this, type, false); -}; - -EventEmitter.listenerCount = function(emitter, type) { - if (typeof emitter.listenerCount === 'function') { - return emitter.listenerCount(type); - } else { - return listenerCount.call(emitter, type); - } -}; - -EventEmitter.prototype.listenerCount = listenerCount; -function listenerCount(type) { - var events = this._events; - - if (events) { - var evlistener = events[type]; - - if (typeof evlistener === 'function') { - return 1; - } else if (evlistener) { - return evlistener.length; - } - } - - return 0; -} - -EventEmitter.prototype.eventNames = function eventNames() { - return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : []; -}; - -// About 1.5x faster than the two-arg version of Array#splice(). -function spliceOne(list, index) { - for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) - list[i] = list[k]; - list.pop(); -} - -function arrayClone(arr, n) { - var copy = new Array(n); - for (var i = 0; i < n; ++i) - copy[i] = arr[i]; - return copy; -} - -function unwrapListeners(arr) { - var ret = new Array(arr.length); - for (var i = 0; i < ret.length; ++i) { - ret[i] = arr[i].listener || arr[i]; - } - return ret; -} - -function objectCreatePolyfill(proto) { - var F = function() {}; - F.prototype = proto; - return new F; -} -function objectKeysPolyfill(obj) { - var keys = []; - for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) { - keys.push(k); - } - return k; -} -function functionBindPolyfill(context) { - var fn = this; - return function () { - return fn.apply(context, arguments); - }; -} - -},{}],30:[function(require,module,exports){ -(function (process){(function (){ -/* eslint-env browser */ - -/** - * This is the web browser implementation of `debug()`. - */ - -exports.formatArgs = formatArgs; -exports.save = save; -exports.load = load; -exports.useColors = useColors; -exports.storage = localstorage(); -exports.destroy = (() => { - let warned = false; - - return () => { - if (!warned) { - warned = true; - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); - } - }; -})(); - -/** - * Colors. - */ - -exports.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' -]; - -/** - * Currently only WebKit-based Web Inspectors, Firefox >= v31, - * and the Firebug extension (any Firefox version) are known - * to support "%c" CSS customizations. - * - * TODO: add a `localStorage` variable to explicitly enable/disable colors - */ - -// eslint-disable-next-line complexity -function useColors() { - // NB: In an Electron preload script, document will be defined but not fully - // initialized. Since we know we're in Chrome, we'll just detect this case - // explicitly - if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { - return true; - } - - // Internet Explorer and Edge do not support colors. - if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { - return false; - } - - // Is webkit? http://stackoverflow.com/a/16459606/376773 - // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 - return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || - // Is firebug? http://stackoverflow.com/a/398120/376773 - (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || - // Is firefox >= v31? - // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages - (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || - // Double check webkit in userAgent just in case we are in a worker - (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); -} - -/** - * Colorize log arguments if enabled. - * - * @api public - */ - -function formatArgs(args) { - args[0] = (this.useColors ? '%c' : '') + - this.namespace + - (this.useColors ? ' %c' : ' ') + - args[0] + - (this.useColors ? '%c ' : ' ') + - '+' + module.exports.humanize(this.diff); - - if (!this.useColors) { - return; - } - - const c = 'color: ' + this.color; - args.splice(1, 0, c, 'color: inherit'); - - // The final "%c" is somewhat tricky, because there could be other - // arguments passed either before or after the %c, so we need to - // figure out the correct index to insert the CSS into - let index = 0; - let lastC = 0; - args[0].replace(/%[a-zA-Z%]/g, match => { - if (match === '%%') { - return; - } - index++; - if (match === '%c') { - // We only are interested in the *last* %c - // (the user may have provided their own) - lastC = index; - } - }); - - args.splice(lastC, 0, c); -} - -/** - * Invokes `console.debug()` when available. - * No-op when `console.debug` is not a "function". - * If `console.debug` is not available, falls back - * to `console.log`. - * - * @api public - */ -exports.log = console.debug || console.log || (() => {}); - -/** - * Save `namespaces`. - * - * @param {String} namespaces - * @api private - */ -function save(namespaces) { - try { - if (namespaces) { - exports.storage.setItem('debug', namespaces); - } else { - exports.storage.removeItem('debug'); - } - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? - } -} - -/** - * Load `namespaces`. - * - * @return {String} returns the previously persisted debug modes - * @api private - */ -function load() { - let r; - try { - r = exports.storage.getItem('debug'); - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? - } - - // If debug isn't set in LS, and we're in Electron, try to load $DEBUG - if (!r && typeof process !== 'undefined' && 'env' in process) { - r = process.env.DEBUG; - } - - return r; -} - -/** - * Localstorage attempts to return the localstorage. - * - * This is necessary because safari throws - * when a user disables cookies/localstorage - * and you attempt to access it. - * - * @return {LocalStorage} - * @api private - */ - -function localstorage() { - try { - // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context - // The Browser also has localStorage in the global context. - return localStorage; - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? - } -} - -module.exports = require('./common')(exports); - -const {formatters} = module.exports; - -/** - * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. - */ - -formatters.j = function (v) { - try { - return JSON.stringify(v); - } catch (error) { - return '[UnexpectedJSONParseError]: ' + error.message; - } -}; - -}).call(this)}).call(this,require('_process')) -},{"./common":31,"_process":33}],31:[function(require,module,exports){ - -/** - * This is the common logic for both the Node.js and web browser - * implementations of `debug()`. - */ - -function setup(env) { - createDebug.debug = createDebug; - createDebug.default = createDebug; - createDebug.coerce = coerce; - createDebug.disable = disable; - createDebug.enable = enable; - createDebug.enabled = enabled; - createDebug.humanize = require('ms'); - createDebug.destroy = destroy; - - Object.keys(env).forEach(key => { - createDebug[key] = env[key]; - }); - - /** - * The currently active debug mode names, and names to skip. - */ - - createDebug.names = []; - createDebug.skips = []; - - /** - * Map of special "%n" handling functions, for the debug "format" argument. - * - * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". - */ - createDebug.formatters = {}; - - /** - * Selects a color for a debug namespace - * @param {String} namespace The namespace string for the for the debug instance to be colored - * @return {Number|String} An ANSI color code for the given namespace - * @api private - */ - function selectColor(namespace) { - let hash = 0; - - for (let i = 0; i < namespace.length; i++) { - hash = ((hash << 5) - hash) + namespace.charCodeAt(i); - hash |= 0; // Convert to 32bit integer - } - - return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; - } - createDebug.selectColor = selectColor; - - /** - * Create a debugger with the given `namespace`. - * - * @param {String} namespace - * @return {Function} - * @api public - */ - function createDebug(namespace) { - let prevTime; - let enableOverride = null; - - function debug(...args) { - // Disabled? - if (!debug.enabled) { - return; - } - - const self = debug; - - // Set `diff` timestamp - const curr = Number(new Date()); - const ms = curr - (prevTime || curr); - self.diff = ms; - self.prev = prevTime; - self.curr = curr; - prevTime = curr; - - args[0] = createDebug.coerce(args[0]); - - if (typeof args[0] !== 'string') { - // Anything else let's inspect with %O - args.unshift('%O'); - } - - // Apply any `formatters` transformations - let index = 0; - args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { - // If we encounter an escaped % then don't increase the array index - if (match === '%%') { - return '%'; - } - index++; - const formatter = createDebug.formatters[format]; - if (typeof formatter === 'function') { - const val = args[index]; - match = formatter.call(self, val); - - // Now we need to remove `args[index]` since it's inlined in the `format` - args.splice(index, 1); - index--; - } - return match; - }); - - // Apply env-specific formatting (colors, etc.) - createDebug.formatArgs.call(self, args); - - const logFn = self.log || createDebug.log; - logFn.apply(self, args); - } - - debug.namespace = namespace; - debug.useColors = createDebug.useColors(); - debug.color = createDebug.selectColor(namespace); - debug.extend = extend; - debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. - - Object.defineProperty(debug, 'enabled', { - enumerable: true, - configurable: false, - get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, - set: v => { - enableOverride = v; - } - }); - - // Env-specific initialization logic for debug instances - if (typeof createDebug.init === 'function') { - createDebug.init(debug); - } - - return debug; - } - - function extend(namespace, delimiter) { - const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); - newDebug.log = this.log; - return newDebug; - } - - /** - * Enables a debug mode by namespaces. This can include modes - * separated by a colon and wildcards. - * - * @param {String} namespaces - * @api public - */ - function enable(namespaces) { - createDebug.save(namespaces); - - createDebug.names = []; - createDebug.skips = []; - - let i; - const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); - const len = split.length; - - for (i = 0; i < len; i++) { - if (!split[i]) { - // ignore empty strings - continue; - } - - namespaces = split[i].replace(/\*/g, '.*?'); - - if (namespaces[0] === '-') { - createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); - } else { - createDebug.names.push(new RegExp('^' + namespaces + '$')); - } - } - } - - /** - * Disable debug output. - * - * @return {String} namespaces - * @api public - */ - function disable() { - const namespaces = [ - ...createDebug.names.map(toNamespace), - ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace) - ].join(','); - createDebug.enable(''); - return namespaces; - } - - /** - * Returns true if the given mode name is enabled, false otherwise. - * - * @param {String} name - * @return {Boolean} - * @api public - */ - function enabled(name) { - if (name[name.length - 1] === '*') { - return true; - } - - let i; - let len; - - for (i = 0, len = createDebug.skips.length; i < len; i++) { - if (createDebug.skips[i].test(name)) { - return false; - } - } - - for (i = 0, len = createDebug.names.length; i < len; i++) { - if (createDebug.names[i].test(name)) { - return true; - } - } - - return false; - } - - /** - * Convert regexp to namespace - * - * @param {RegExp} regxep - * @return {String} namespace - * @api private - */ - function toNamespace(regexp) { - return regexp.toString() - .substring(2, regexp.toString().length - 2) - .replace(/\.\*\?$/, '*'); - } - - /** - * Coerce `val`. - * - * @param {Mixed} val - * @return {Mixed} - * @api private - */ - function coerce(val) { - if (val instanceof Error) { - return val.stack || val.message; - } - return val; - } - - /** - * XXX DO NOT USE. This is a temporary stub function. - * XXX It WILL be removed in the next major release. - */ - function destroy() { - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); - } - - createDebug.enable(createDebug.load()); - - return createDebug; -} - -module.exports = setup; - -},{"ms":32}],32:[function(require,module,exports){ -/** - * Helpers. - */ - -var s = 1000; -var m = s * 60; -var h = m * 60; -var d = h * 24; -var w = d * 7; -var y = d * 365.25; - -/** - * Parse or format the given `val`. - * - * Options: - * - * - `long` verbose formatting [false] - * - * @param {String|Number} val - * @param {Object} [options] - * @throws {Error} throw an error if val is not a non-empty string or a number - * @return {String|Number} - * @api public - */ - -module.exports = function(val, options) { - options = options || {}; - var type = typeof val; - if (type === 'string' && val.length > 0) { - return parse(val); - } else if (type === 'number' && isFinite(val)) { - return options.long ? fmtLong(val) : fmtShort(val); - } - throw new Error( - 'val is not a non-empty string or a valid number. val=' + - JSON.stringify(val) - ); -}; - -/** - * Parse the given `str` and return milliseconds. - * - * @param {String} str - * @return {Number} - * @api private - */ - -function parse(str) { - str = String(str); - if (str.length > 100) { - return; - } - var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( - str - ); - if (!match) { - return; - } - var n = parseFloat(match[1]); - var type = (match[2] || 'ms').toLowerCase(); - switch (type) { - case 'years': - case 'year': - case 'yrs': - case 'yr': - case 'y': - return n * y; - case 'weeks': - case 'week': - case 'w': - return n * w; - case 'days': - case 'day': - case 'd': - return n * d; - case 'hours': - case 'hour': - case 'hrs': - case 'hr': - case 'h': - return n * h; - case 'minutes': - case 'minute': - case 'mins': - case 'min': - case 'm': - return n * m; - case 'seconds': - case 'second': - case 'secs': - case 'sec': - case 's': - return n * s; - case 'milliseconds': - case 'millisecond': - case 'msecs': - case 'msec': - case 'ms': - return n; - default: - return undefined; - } -} - -/** - * Short format for `ms`. - * - * @param {Number} ms - * @return {String} - * @api private - */ - -function fmtShort(ms) { - var msAbs = Math.abs(ms); - if (msAbs >= d) { - return Math.round(ms / d) + 'd'; - } - if (msAbs >= h) { - return Math.round(ms / h) + 'h'; - } - if (msAbs >= m) { - return Math.round(ms / m) + 'm'; - } - if (msAbs >= s) { - return Math.round(ms / s) + 's'; - } - return ms + 'ms'; -} - -/** - * Long format for `ms`. - * - * @param {Number} ms - * @return {String} - * @api private - */ - -function fmtLong(ms) { - var msAbs = Math.abs(ms); - if (msAbs >= d) { - return plural(ms, msAbs, d, 'day'); - } - if (msAbs >= h) { - return plural(ms, msAbs, h, 'hour'); - } - if (msAbs >= m) { - return plural(ms, msAbs, m, 'minute'); - } - if (msAbs >= s) { - return plural(ms, msAbs, s, 'second'); - } - return ms + ' ms'; -} - -/** - * Pluralization helper. - */ - -function plural(ms, msAbs, n, name) { - var isPlural = msAbs >= n * 1.5; - return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); -} - -},{}],33:[function(require,module,exports){ -// shim for using process in browser -var process = module.exports = {}; - -// cached from whatever global is present so that test runners that stub it -// don't break things. But we need to wrap it in a try catch in case it is -// wrapped in strict mode code which doesn't define any globals. It's inside a -// function because try/catches deoptimize in certain engines. - -var cachedSetTimeout; -var cachedClearTimeout; - -function defaultSetTimout() { - throw new Error('setTimeout has not been defined'); -} -function defaultClearTimeout () { - throw new Error('clearTimeout has not been defined'); -} -(function () { - try { - if (typeof setTimeout === 'function') { - cachedSetTimeout = setTimeout; - } else { - cachedSetTimeout = defaultSetTimout; - } - } catch (e) { - cachedSetTimeout = defaultSetTimout; - } - try { - if (typeof clearTimeout === 'function') { - cachedClearTimeout = clearTimeout; - } else { - cachedClearTimeout = defaultClearTimeout; - } - } catch (e) { - cachedClearTimeout = defaultClearTimeout; - } -} ()) -function runTimeout(fun) { - if (cachedSetTimeout === setTimeout) { - //normal enviroments in sane situations - return setTimeout(fun, 0); - } - // if setTimeout wasn't available but was latter defined - if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { - cachedSetTimeout = setTimeout; - return setTimeout(fun, 0); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedSetTimeout(fun, 0); - } catch(e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedSetTimeout.call(null, fun, 0); - } catch(e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error - return cachedSetTimeout.call(this, fun, 0); - } - } - - -} -function runClearTimeout(marker) { - if (cachedClearTimeout === clearTimeout) { - //normal enviroments in sane situations - return clearTimeout(marker); - } - // if clearTimeout wasn't available but was latter defined - if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { - cachedClearTimeout = clearTimeout; - return clearTimeout(marker); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedClearTimeout(marker); - } catch (e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedClearTimeout.call(null, marker); - } catch (e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. - // Some versions of I.E. have different rules for clearTimeout vs setTimeout - return cachedClearTimeout.call(this, marker); - } - } - - - -} -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; - -function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } -} - -function drainQueue() { - if (draining) { - return; - } - var timeout = runTimeout(cleanUpNextTick); - draining = true; - - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - runClearTimeout(timeout); -} - -process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - runTimeout(drainQueue); - } -}; - -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; -} -Item.prototype.run = function () { - this.fun.apply(null, this.array); -}; -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; -process.version = ''; // empty string to avoid regexp issues -process.versions = {}; - -function noop() {} - -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; -process.prependListener = noop; -process.prependOnceListener = noop; - -process.listeners = function (name) { return [] } - -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; - -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; - -},{}],34:[function(require,module,exports){ -var grammar = module.exports = { - v: [{ - name: 'version', - reg: /^(\d*)$/ - }], - o: [{ - // o=- 20518 0 IN IP4 203.0.113.1 - // NB: sessionId will be a String in most cases because it is huge - 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' - }], - // default parsing of these only (though some of these feel outdated) - s: [{ name: 'name' }], - i: [{ name: 'description' }], - u: [{ name: 'uri' }], - e: [{ name: 'email' }], - p: [{ name: 'phone' }], - z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly... - r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly - // k: [{}], // outdated thing ignored - t: [{ - // t=0 0 - name: 'timing', - reg: /^(\d*) (\d*)/, - names: ['start', 'stop'], - format: '%d %d' - }], - c: [{ - // c=IN IP4 10.47.197.26 - name: 'connection', - reg: /^IN IP(\d) (\S*)/, - names: ['version', 'ip'], - format: 'IN IP%d %s' - }], - b: [{ - // b=AS:4000 - push: 'bandwidth', - reg: /^(TIAS|AS|CT|RR|RS):(\d*)/, - names: ['type', 'limit'], - format: '%s:%s' - }], - m: [{ - // m=video 51744 RTP/AVP 126 97 98 34 31 - // NB: special - pushes to session - // TODO: rtp/fmtp should be filtered by the payloads found here? - reg: /^(\w*) (\d*) ([\w/]*)(?: (.*))?/, - names: ['type', 'port', 'protocol', 'payloads'], - format: '%s %d %s %s' - }], - a: [ - { - // a=rtpmap:110 opus/48000/2 - push: 'rtp', - reg: /^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/, - names: ['payload', 'codec', 'rate', 'encoding'], - format: function (o) { - return (o.encoding) - ? 'rtpmap:%d %s/%s/%s' - : o.rate - ? 'rtpmap:%d %s/%s' - : 'rtpmap:%d %s'; - } - }, - { - // a=fmtp:108 profile-level-id=24;object=23;bitrate=64000 - // a=fmtp:111 minptime=10; useinbandfec=1 - push: 'fmtp', - reg: /^fmtp:(\d*) ([\S| ]*)/, - names: ['payload', 'config'], - format: 'fmtp:%d %s' - }, - { - // a=control:streamid=0 - name: 'control', - reg: /^control:(.*)/, - format: 'control:%s' - }, - { - // a=rtcp:65179 IN IP4 193.84.77.194 - name: 'rtcp', - reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/, - names: ['port', 'netType', 'ipVer', 'address'], - format: function (o) { - return (o.address != null) - ? 'rtcp:%d %s IP%d %s' - : 'rtcp:%d'; - } - }, - { - // a=rtcp-fb:98 trr-int 100 - push: 'rtcpFbTrrInt', - reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, - names: ['payload', 'value'], - format: 'rtcp-fb:%s trr-int %d' - }, - { - // a=rtcp-fb:98 nack rpsi - push: 'rtcpFb', - reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/, - names: ['payload', 'type', 'subtype'], - format: function (o) { - return (o.subtype != null) - ? 'rtcp-fb:%s %s %s' - : 'rtcp-fb:%s %s'; - } - }, - { - // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset - // a=extmap:1/recvonly URI-gps-string - // a=extmap:3 urn:ietf:params:rtp-hdrext:encrypt urn:ietf:params:rtp-hdrext:smpte-tc 25@600/24 - push: 'ext', - reg: /^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/, - names: ['value', 'direction', 'encrypt-uri', 'uri', 'config'], - format: function (o) { - return ( - 'extmap:%d' + - (o.direction ? '/%s' : '%v') + - (o['encrypt-uri'] ? ' %s' : '%v') + - ' %s' + - (o.config ? ' %s' : '') - ); - } - }, - { - // a=extmap-allow-mixed - name: 'extmapAllowMixed', - reg: /^(extmap-allow-mixed)/ - }, - { - // a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32 - push: 'crypto', - reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/, - names: ['id', 'suite', 'config', 'sessionConfig'], - format: function (o) { - return (o.sessionConfig != null) - ? 'crypto:%d %s %s %s' - : 'crypto:%d %s %s'; - } - }, - { - // a=setup:actpass - name: 'setup', - reg: /^setup:(\w*)/, - format: 'setup:%s' - }, - { - // a=connection:new - name: 'connectionType', - reg: /^connection:(new|existing)/, - format: 'connection:%s' - }, - { - // a=mid:1 - name: 'mid', - reg: /^mid:([^\s]*)/, - format: 'mid:%s' - }, - { - // a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a - name: 'msid', - reg: /^msid:(.*)/, - format: 'msid:%s' - }, - { - // a=ptime:20 - name: 'ptime', - reg: /^ptime:(\d*(?:\.\d*)*)/, - format: 'ptime:%d' - }, - { - // a=maxptime:60 - name: 'maxptime', - reg: /^maxptime:(\d*(?:\.\d*)*)/, - format: 'maxptime:%d' - }, - { - // a=sendrecv - name: 'direction', - reg: /^(sendrecv|recvonly|sendonly|inactive)/ - }, - { - // a=ice-lite - name: 'icelite', - reg: /^(ice-lite)/ - }, - { - // a=ice-ufrag:F7gI - name: 'iceUfrag', - reg: /^ice-ufrag:(\S*)/, - format: 'ice-ufrag:%s' - }, - { - // a=ice-pwd:x9cml/YzichV2+XlhiMu8g - name: 'icePwd', - reg: /^ice-pwd:(\S*)/, - format: 'ice-pwd:%s' - }, - { - // a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33 - name: 'fingerprint', - reg: /^fingerprint:(\S*) (\S*)/, - names: ['type', 'hash'], - format: 'fingerprint:%s %s' - }, - { - // a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host - // a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10 - // a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0 network-id 3 network-cost 10 - // a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10 - // a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0 network-id 3 network-cost 10 - 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 (o) { - var str = 'candidate:%s %d %s %d %s %d typ %s'; - - str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v'; - - // NB: candidate has three optional chunks, so %void middles one if it's missing - str += (o.tcptype != null) ? ' tcptype %s' : '%v'; - - if (o.generation != null) { - str += ' generation %d'; - } - - str += (o['network-id'] != null) ? ' network-id %d' : '%v'; - str += (o['network-cost'] != null) ? ' network-cost %d' : '%v'; - return str; - } - }, - { - // a=end-of-candidates (keep after the candidates line for readability) - name: 'endOfCandidates', - reg: /^(end-of-candidates)/ - }, - { - // a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ... - name: 'remoteCandidates', - reg: /^remote-candidates:(.*)/, - format: 'remote-candidates:%s' - }, - { - // a=ice-options:google-ice - name: 'iceOptions', - reg: /^ice-options:(\S*)/, - format: 'ice-options:%s' - }, - { - // a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1 - push: 'ssrcs', - reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/, - names: ['id', 'attribute', 'value'], - format: function (o) { - var str = 'ssrc:%d'; - if (o.attribute != null) { - str += ' %s'; - if (o.value != null) { - str += ':%s'; - } - } - return str; - } - }, - { - // a=ssrc-group:FEC 1 2 - // a=ssrc-group:FEC-FR 3004364195 1080772241 - push: 'ssrcGroups', - // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E - reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/, - names: ['semantics', 'ssrcs'], - format: 'ssrc-group:%s %s' - }, - { - // a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV - name: 'msidSemantic', - reg: /^msid-semantic:\s?(\w*) (\S*)/, - names: ['semantic', 'token'], - format: 'msid-semantic: %s %s' // space after ':' is not accidental - }, - { - // a=group:BUNDLE audio video - push: 'groups', - reg: /^group:(\w*) (.*)/, - names: ['type', 'mids'], - format: 'group:%s %s' - }, - { - // a=rtcp-mux - name: 'rtcpMux', - reg: /^(rtcp-mux)/ - }, - { - // a=rtcp-rsize - name: 'rtcpRsize', - reg: /^(rtcp-rsize)/ - }, - { - // a=sctpmap:5000 webrtc-datachannel 1024 - name: 'sctpmap', - reg: /^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/, - names: ['sctpmapNumber', 'app', 'maxMessageSize'], - format: function (o) { - return (o.maxMessageSize != null) - ? 'sctpmap:%s %s %s' - : 'sctpmap:%s %s'; - } - }, - { - // a=x-google-flag:conference - name: 'xGoogleFlag', - reg: /^x-google-flag:([^\s]*)/, - format: 'x-google-flag:%s' - }, - { - // a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0 - push: 'rids', - reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/, - names: ['id', 'direction', 'params'], - format: function (o) { - return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s'; - } - }, - { - // a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250] - // a=imageattr:* send [x=800,y=640] recv * - // a=imageattr:100 recv [x=320,y=240] - push: 'imageattrs', - reg: new RegExp( - // a=imageattr:97 - '^imageattr:(\\d+|\\*)' + - // send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] - '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' + - // recv [x=330,y=250] - '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?' - ), - names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'], - format: function (o) { - return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : ''); - } - }, - { - // a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8 - // a=simulcast:recv 1;4,5 send 6;7 - name: 'simulcast', - reg: new RegExp( - // a=simulcast: - '^simulcast:' + - // send 1,2,3;~4,~5 - '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' + - // space + recv 6;~7,~8 - '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' + - // end - '$' - ), - names: ['dir1', 'list1', 'dir2', 'list2'], - format: function (o) { - return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : ''); - } - }, - { - // old simulcast draft 03 (implemented by Firefox) - // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03 - // a=simulcast: recv pt=97;98 send pt=97 - // a=simulcast: send rid=5;6;7 paused=6,7 - name: 'simulcast_03', - reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/, - names: ['value'], - format: 'simulcast: %s' - }, - { - // a=framerate:25 - // a=framerate:29.97 - name: 'framerate', - reg: /^framerate:(\d+(?:$|\.\d+))/, - format: 'framerate:%s' - }, - { - // RFC4570 - // a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5 - 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' - }, - { - // a=bundle-only - name: 'bundleOnly', - reg: /^(bundle-only)/ - }, - { - // a=label:1 - name: 'label', - reg: /^label:(.+)/, - format: 'label:%s' - }, - { - // RFC version 26 for SCTP over DTLS - // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5 - name: 'sctpPort', - reg: /^sctp-port:(\d+)$/, - format: 'sctp-port:%s' - }, - { - // RFC version 26 for SCTP over DTLS - // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6 - name: 'maxMessageSize', - reg: /^max-message-size:(\d+)$/, - format: 'max-message-size:%s' - }, - { - // RFC7273 - // a=ts-refclk:ptp=IEEE1588-2008:39-A7-94-FF-FE-07-CB-D0:37 - push:'tsRefClocks', - reg: /^ts-refclk:([^\s=]*)(?:=(\S*))?/, - names: ['clksrc', 'clksrcExt'], - format: function (o) { - return 'ts-refclk:%s' + (o.clksrcExt != null ? '=%s' : ''); - } - }, - { - // RFC7273 - // a=mediaclk:direct=963214424 - name:'mediaClk', - reg: /^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/, - names: ['id', 'mediaClockName', 'mediaClockValue', 'rateNumerator', 'rateDenominator'], - format: function (o) { - var str = 'mediaclk:'; - str += (o.id != null ? 'id=%s %s' : '%v%s'); - str += (o.mediaClockValue != null ? '=%s' : ''); - str += (o.rateNumerator != null ? ' rate=%s' : ''); - str += (o.rateDenominator != null ? '/%s' : ''); - return str; - } - }, - { - // a=keywds:keywords - name: 'keywords', - reg: /^keywds:(.+)$/, - format: 'keywds:%s' - }, - { - // a=content:main - name: 'content', - reg: /^content:(.+)/, - format: 'content:%s' - }, - // BFCP https://tools.ietf.org/html/rfc4583 - { - // a=floorctrl:c-s - name: 'bfcpFloorCtrl', - reg: /^floorctrl:(c-only|s-only|c-s)/, - format: 'floorctrl:%s' - }, - { - // a=confid:1 - name: 'bfcpConfId', - reg: /^confid:(\d+)/, - format: 'confid:%s' - }, - { - // a=userid:1 - name: 'bfcpUserId', - reg: /^userid:(\d+)/, - format: 'userid:%s' - }, - { - // a=floorid:1 - name: 'bfcpFloorId', - reg: /^floorid:(.+) (?:m-stream|mstrm):(.+)/, - names: ['id', 'mStream'], - format: 'floorid:%s mstrm:%s' - }, - { - // any a= that we don't understand is kept verbatim on media.invalid - push: 'invalid', - names: ['value'] - } - ] -}; - -// set sensible defaults to avoid polluting the grammar with boring details -Object.keys(grammar).forEach(function (key) { - var objs = grammar[key]; - objs.forEach(function (obj) { - if (!obj.reg) { - obj.reg = /(.*)/; - } - if (!obj.format) { - obj.format = '%s'; - } - }); -}); - -},{}],35:[function(require,module,exports){ -var parser = require('./parser'); -var writer = require('./writer'); - -exports.write = writer; -exports.parse = parser.parse; -exports.parseParams = parser.parseParams; -exports.parseFmtpConfig = parser.parseFmtpConfig; // Alias of parseParams(). -exports.parsePayloads = parser.parsePayloads; -exports.parseRemoteCandidates = parser.parseRemoteCandidates; -exports.parseImageAttributes = parser.parseImageAttributes; -exports.parseSimulcastStreamList = parser.parseSimulcastStreamList; - -},{"./parser":36,"./writer":37}],36:[function(require,module,exports){ -var toIntIfInt = function (v) { - return String(Number(v)) === v ? Number(v) : v; -}; - -var attachProperties = function (match, location, names, rawName) { - if (rawName && !names) { - location[rawName] = toIntIfInt(match[1]); - } - else { - for (var i = 0; i < names.length; i += 1) { - if (match[i+1] != null) { - location[names[i]] = toIntIfInt(match[i+1]); - } - } - } -}; - -var parseReg = function (obj, location, content) { - var needsBlank = obj.name && obj.names; - if (obj.push && !location[obj.push]) { - location[obj.push] = []; - } - else if (needsBlank && !location[obj.name]) { - location[obj.name] = {}; - } - var keyLocation = obj.push ? - {} : // blank object that will be pushed - needsBlank ? location[obj.name] : location; // otherwise, named location or root - - attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name); - - if (obj.push) { - location[obj.push].push(keyLocation); - } -}; - -var grammar = require('./grammar'); -var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/); - -exports.parse = function (sdp) { - var session = {} - , media = [] - , location = session; // points at where properties go under (one of the above) - - // parse lines we understand - sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) { - var type = l[0]; - var content = l.slice(2); - if (type === 'm') { - media.push({rtp: [], fmtp: []}); - location = media[media.length-1]; // point at latest media line - } - - for (var j = 0; j < (grammar[type] || []).length; j += 1) { - var obj = grammar[type][j]; - if (obj.reg.test(content)) { - return parseReg(obj, location, content); - } - } - }); - - session.media = media; // link it up - return session; -}; - -var paramReducer = function (acc, expr) { - var s = expr.split(/=(.+)/, 2); - if (s.length === 2) { - acc[s[0]] = toIntIfInt(s[1]); - } else if (s.length === 1 && expr.length > 1) { - acc[s[0]] = undefined; - } - return acc; -}; - -exports.parseParams = function (str) { - return str.split(/;\s?/).reduce(paramReducer, {}); -}; - -// For backward compatibility - alias will be removed in 3.0.0 -exports.parseFmtpConfig = exports.parseParams; - -exports.parsePayloads = function (str) { - return str.toString().split(' ').map(Number); -}; - -exports.parseRemoteCandidates = function (str) { - var candidates = []; - var parts = str.split(' ').map(toIntIfInt); - for (var i = 0; i < parts.length; i += 3) { - candidates.push({ - component: parts[i], - ip: parts[i + 1], - port: parts[i + 2] - }); - } - return candidates; -}; - -exports.parseImageAttributes = function (str) { - return str.split(' ').map(function (item) { - return item.substring(1, item.length-1).split(',').reduce(paramReducer, {}); - }); -}; - -exports.parseSimulcastStreamList = function (str) { - return str.split(';').map(function (stream) { - return stream.split(',').map(function (format) { - var scid, paused = false; - - if (format[0] !== '~') { - scid = toIntIfInt(format); - } else { - scid = toIntIfInt(format.substring(1, format.length)); - paused = true; - } - - return { - scid: scid, - paused: paused - }; - }); - }); -}; - -},{"./grammar":34}],37:[function(require,module,exports){ -var grammar = require('./grammar'); - -// customized util.format - discards excess arguments and can void middle ones -var formatRegExp = /%[sdv%]/g; -var format = function (formatStr) { - var i = 1; - var args = arguments; - var len = args.length; - return formatStr.replace(formatRegExp, function (x) { - if (i >= len) { - return x; // missing argument - } - var arg = args[i]; - i += 1; - switch (x) { - case '%%': - return '%'; - case '%s': - return String(arg); - case '%d': - return Number(arg); - case '%v': - return ''; - } - }); - // NB: we discard excess arguments - they are typically undefined from makeLine -}; - -var makeLine = function (type, obj, location) { - var str = obj.format instanceof Function ? - (obj.format(obj.push ? location : location[obj.name])) : - obj.format; - - var args = [type + '=' + str]; - if (obj.names) { - for (var i = 0; i < obj.names.length; i += 1) { - var n = obj.names[i]; - if (obj.name) { - args.push(location[obj.name][n]); - } - else { // for mLine and push attributes - args.push(location[obj.names[i]]); - } - } - } - else { - args.push(location[obj.name]); - } - return format.apply(null, args); -}; - -// RFC specified order -// TODO: extend this with all the rest -var defaultOuterOrder = [ - 'v', 'o', 's', 'i', - 'u', 'e', 'p', 'c', - 'b', 't', 'r', 'z', 'a' -]; -var defaultInnerOrder = ['i', 'c', 'b', 'a']; - - -module.exports = function (session, opts) { - opts = opts || {}; - // ensure certain properties exist - if (session.version == null) { - session.version = 0; // 'v=0' must be there (only defined version atm) - } - if (session.name == null) { - session.name = ' '; // 's= ' must be there if no meaningful name set - } - session.media.forEach(function (mLine) { - if (mLine.payloads == null) { - mLine.payloads = ''; - } - }); - - var outerOrder = opts.outerOrder || defaultOuterOrder; - var innerOrder = opts.innerOrder || defaultInnerOrder; - var sdp = []; - - // loop through outerOrder for matching properties on session - outerOrder.forEach(function (type) { - grammar[type].forEach(function (obj) { - if (obj.name in session && session[obj.name] != null) { - sdp.push(makeLine(type, obj, session)); - } - else if (obj.push in session && session[obj.push] != null) { - session[obj.push].forEach(function (el) { - sdp.push(makeLine(type, obj, el)); - }); - } - }); - }); - - // then for each media line, follow the innerOrder - session.media.forEach(function (mLine) { - sdp.push(makeLine('m', grammar.m[0], mLine)); - - innerOrder.forEach(function (type) { - grammar[type].forEach(function (obj) { - if (obj.name in mLine && mLine[obj.name] != null) { - sdp.push(makeLine(type, obj, mLine)); - } - else if (obj.push in mLine && mLine[obj.push] != null) { - mLine[obj.push].forEach(function (el) { - sdp.push(makeLine(type, obj, el)); - }); - } - }); - }); - }); - - return sdp.join('\r\n') + '\r\n'; -}; - -},{"./grammar":34}],38:[function(require,module,exports){ -module.exports={ - "name": "jssip", - "title": "JsSIP", - "description": "the Javascript SIP library", - "version": "3.7.5", - "homepage": "https://jssip.net", - "author": "José Luis Millán (https://github.com/jmillan)", - "contributors": [ - "Iñaki Baz Castillo (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.14.34", - "debug": "^4.3.1", - "events": "^3.3.0", - "sdp-transform": "^2.14.1" - }, - "devDependencies": { - "@babel/core": "^7.13.10", - "@babel/preset-env": "^7.13.10", - "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) -}); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 46ae09bba..6d3fe9ca2 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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=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=n.call(e)},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);n0)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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":38}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),a("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,a("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){a("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=u.cloneArray(n.extraHeaders),s=u.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=u.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),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=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)}}])&&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;n2&&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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:N,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:k,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:x,STAR:D,SLASH:P,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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:z,qdtext:J,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:Ne,headers:ke,header:Ue,hname:xe,hvalue:De,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:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=D()))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;tl&&(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 N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){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 x(){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 D(){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 B(){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 W(){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 V(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 z(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 J(){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=ke())?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=k())))),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=k())),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=k())?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=Ne())&&null===(e=C())&&(e=E()),e}function Ne(){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 ke(){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=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=De())?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 xe(){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 De(){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=Je())?(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=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){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 Ve(){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=ze();null!==t;)e.push(t),t=ze();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=ze();null!==t;)e.push(t),t=ze();return e}function ze(){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 Je(){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=Be();null!==t;)e.push(t),t=Be();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=k()),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=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),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=k())?(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=k())&&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=k())))),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=k())),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=Dt())){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=Nt())&&(e=kt()),e}function Nt(){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 kt(){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=k())&&(e=xt()),e}function xt(){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=k())?e=[e,t]:(e=null,i=r),e}function Dt(){var e;return null===(e=Ut())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(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=k())?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=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(u=Wt())?l=[l,u]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(u=Wt())?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=k()))if(null!==(t=A()))if(null!==(n=Bt())){for(r=[],u=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=j())&&null!==(o=Bt())?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 Bt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=Y()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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=z())&&(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=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?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=zt())?u=[u,c]:(u=null,i=f)}null!==l&&null!==(u=V())?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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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=z())&&(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=z())?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=k())),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=W())){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=V())?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=k())),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=k()))),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=k()))))))),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=k())?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=k())&&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=k()),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=k())))),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=B())&&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=N())&&(t=A());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=A());return e}function Nn(){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=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(f=xn())?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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Dn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=k())?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=k())?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),Bn=Gn2&&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})}}])&&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"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":25}],11:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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=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=n.call(e)},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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;b("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=p.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!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new A("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new A("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,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;b("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||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===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};b('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(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===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};b("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(b("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(b("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(b("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(f.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]:{};b("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(b('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new T(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(b("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};b("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};b("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(b("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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(b("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;b("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;b("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 b("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(b("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};b('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){b("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){b("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||(b("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(b("_isReadyToReOffer() | session not established yet"),!1):(b("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(b("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(b("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(b("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),b('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(b("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 b('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};b('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(b(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(b(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;b("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 b("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;b("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return b("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;b("_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!==I.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};b('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===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(b("receiveRefer()"),!e.refer_to)return b("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return b("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);b('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new a(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(b("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;b("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new a(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){b("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,b('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(b("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void b(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){b("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};b('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};b('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};b('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};b('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),R('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]:{};b("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.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};b('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),R('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)};b('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.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(f.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){b("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){b("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!==I.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){b("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){b("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!==I.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 h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(b("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){b("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){b("session connecting"),b('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){b("session progress"),b('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){b("session accepted"),this._start_time=new Date,b('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){b("session confirmed"),this._is_confirmed=!0,b('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){b("session ended"),this._end_time=new Date,this._close(),b('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){b("session failed"),b('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),b('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){b("session onhold"),this._setLocalMediaStatus(),b('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){b("session onunhold"),this._setLocalMediaStatus(),b('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;b("session onmute"),this._setLocalMediaStatus(),b('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;b("session onunmute"),this._setLocalMediaStatus(),b('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),a}()},{"./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;n1&&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")}}])&&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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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})}}])&&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=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&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;n1&&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})}}])&&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"')}var t,n,a;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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})}}])&&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;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,u)Object.prototype.hasOwnProperty.call(u,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=u[o]));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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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")),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;r1&&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=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)}}}]),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:"C",get:function(){return C}},{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()}}]),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:"C",get:function(){return C}},{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:}}}]),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:"C",get:function(){return C}},{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())}}}]),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){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=u.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),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;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./RequestSender":18,"./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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var u in this._parameters={},this._headers={},this._scheme=t||o.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 l)Object.prototype.hasOwnProperty.call(l,a)&&this.setHeader(a,l[a])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=u.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 u=i.value;e.push("".concat(s,"=").concat(u))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&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=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=n.call(e)},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);n1)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(e0&&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;t1&&(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=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=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){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":31,_process:33}],31:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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=[];++f1)for(var n=1;n1&&(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=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.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.data={},n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n.is_terminated=!1,n.terminated_reason=void 0,n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){"pending"===this._state&&(f('set "active" state'),this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=_,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,f||(f=[]),r.headers=f.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){this._dialogTerminated("send un-subscribe");var e=["Event: ".concat(this.event_name),"Expires: 0"];this._send(null,e)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Constants.js b/lib/Constants.js index 5cb3a88a4..bb10550d3 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -149,7 +149,7 @@ module.exports = { 606 : 'Not Acceptable' }, - ALLOWED_METHODS : 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY', + ALLOWED_METHODS : 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE', ACCEPTED_BODY_TYPES : 'application/sdp, application/dtmf-relay', MAX_FORWARDS : 69, SESSION_EXPIRES : 90, diff --git a/lib/Notifier.js b/lib/Notifier.js new file mode 100644 index 000000000..5b6490dd5 --- /dev/null +++ b/lib/Notifier.js @@ -0,0 +1,224 @@ +const EventEmitter = require('events').EventEmitter; +const JsSIP_C = require('./Constants'); +const Utils = require('./Utils'); +const debug = require('debug')('JsSIP:Notifier'); +const debugerror = require('debug')('JsSIP:ERROR:Notifier'); + +debugerror.log = console.warn.bind(console); + +module.exports = class Notifier extends EventEmitter +{ + constructor(ua, { subscribe, content_type, headers, credential, pending }) + { + super(); + this._ua = ua; + this.expires_timestamp = null; + this.expires_timer = null; + this._state = pending ? 'pending' : 'active'; + this.is_final_notify_sent = false; + this.is_first_notify_response = true; + this.id = null; + this.event_name = subscribe.getHeader('event'); + this.content_type = content_type; + if (!content_type) + throw new TypeError('content_type is undefined'); + this.expires = parseInt(subscribe.getHeader('expires')); + this.credential = credential; + const user = subscribe.to.uri.user; + const domain = subscribe.to.uri.host; + + this.contact = ``; + this.rcseq = subscribe.cseq; + this.data = {}; // Custom session empty object for high level use. + this.headers = headers ? headers : []; + this.target = subscribe.from.uri.user; + subscribe.to_tag = Utils.newTag(); + this.params = { + from : subscribe.to, + from_tag : subscribe.to_tag, + to : subscribe.from, + to_tag : subscribe.from_tag, + call_id : subscribe.call_id, + cseq : Math.floor((Math.random() * 10000) + 1) + }; + this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + debug('add dialog id=', this.id); + this._ua.newDialog(this); + this._setExpiresTimestamp(); + this._setExpiresTimer(); + subscribe.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); + this.is_terminated = false; + this.terminated_reason = undefined; + } + + /** + * Callbacks + */ + onAuthenticated() + { + this.params.cseq++; + } + + onRequestTimeout() + { + this._dialogTerminated('notify response timeout'); + } + + onTransportError() + { + this._dialogTerminated('notify transport error'); + } + + onReceiveResponse(response) + { + if (response.status_code >= 200 && response.status_code < 300) + { + if (this.is_first_notify_response) + { + this.is_first_notify_response = false; + this.route_set = response.getHeaders('record-route').reverse(); + if (this.route_set.length > 0) + this.params.route_set = this.route_set; + } + } + else if (response.status_code >= 300) + { + this._dialogTerminated('receive notify non-OK response'); + } + } + + receiveRequest(request) + { + if (request.method !== JsSIP_C.SUBSCRIBE) + { + request.reply(405); // Method Not Allowed + + return; + } + let h = request.getHeader('expires'); + + if (h === undefined || h === null) + { + h = '900'; // Missed header Expires. RFC 6665 3.1.1. Set default expires value + debug(`Missed expires header. Set by default ${h}`); + } + this.expires = parseInt(h); + request.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); + + const body = request.body; + const content_type = request.getHeader('content-type'); + const is_unsubscribe = this.expires === 0; + + debug('emit "subscribe"'); + this.emit('subscribe', is_unsubscribe, request, body, content_type); + + if (is_unsubscribe) + { + this._dialogTerminated('receive un-subscribe'); + } + else + { + this._setExpiresTimestamp(); + this._setExpiresTimer(); + } + } + + /** + * User API + */ + setActiveState() + { + if (this._state === 'pending') + { + debug('set "active" state'); + this._state = 'active'; + } + } + + sendNotify(body = null) + { + let subs_state = this._state; + + if (this._state !== 'terminated') + { + subs_state += `;expires=${this._getExpiresTimestamp()}`; + } + else if (this.terminated_reason) + { + subs_state += `;reason=${this.terminated_reason}`; + } + + const headers = this.headers.slice(); + + headers.push(`Subscription-State: ${subs_state}`); + headers.push(`Event: ${this.event_name}`); + if (body) + { + headers.push(`Content-Type: ${this.content_type}`); + } + this.params.cseq++; + this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, + this, this.credential); + } + + sendFinalNotify(body = null, reason = null) + { + if (this.is_final_notify_sent) + return; + this.is_final_notify_sent = true; + this._dialogTerminated('send final notify'); + this.terminated_reason = reason; + this.sendNotify(body); + } + + get state() + { + return this._state; + } + + /** + * Private API. + */ + _dialogTerminated(reason) + { + if (this.is_terminated) + return; + this.is_terminated = true; + this._state = 'terminated'; + clearTimeout(this.expires_timer); + // If delay needed ? + setTimeout(() => + { + debug('remove dialog id=', this.id); + this._ua.destroyDialog(this); + }, 32000); + debug(`emit "terminated" ${reason}"`); + this.emit('terminated', reason); + } + + _setExpiresTimestamp() + { + this.expires_timestamp = new Date().getTime() + (this.expires * 1000); + } + + _getExpiresTimestamp() + { + const delta = Math.floor((this.expires_timestamp - new Date().getTime()) / 1000); + + return delta >= 0 ? delta : 0; + } + + _setExpiresTimer() + { + clearTimeout(this.expires_timer); + setTimeout(() => + { + if (this.is_final_notify_sent) + return; + this.terminated_reason = 'timeout'; + this.is_final_notify_sent = true; + this.sendNotify(); + this._dialogTerminated('subscription expired'); + }, this.expires * 1000); + } +}; \ No newline at end of file diff --git a/lib/RequestSender.js b/lib/RequestSender.js index 725ff7d0a..aee9e25bf 100644 --- a/lib/RequestSender.js +++ b/lib/RequestSender.js @@ -93,7 +93,8 @@ module.exports = class RequestSender * Authenticate once. _challenged_ flag used to avoid infinite authentications. */ if ((status_code === 401 || status_code === 407) && - (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) + (this._config2 !== null || this._ua.configuration.password !== null + || this._ua.configuration.ha1 !== null)) { // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. @@ -121,13 +122,14 @@ module.exports = class RequestSender { if (!this._auth) { - let cnf = this._config2 ? this._config2 : this._ua.configuration; - this._auth = new DigestAuthentication({ - username : cnf.authorization_user, - password : cnf.password, - realm : cnf.realm, - ha1 : cnf.ha1 - }); + const cnf = this._config2 ? this._config2 : this._ua.configuration; + + this._auth = new DigestAuthentication({ + username : cnf.authorization_user, + password : cnf.password, + realm : cnf.realm, + ha1 : cnf.ha1 + }); } // Verify that the challenge is really valid. @@ -140,15 +142,15 @@ module.exports = class RequestSender this._challenged = true; // Update ha1 and realm in the UA or in alternative config. - if( !this._config2 ) + if (!this._config2) { - this._ua.set('realm', this._auth.get('realm')); - this._ua.set('ha1', this._auth.get('ha1')); + this._ua.set('realm', this._auth.get('realm')); + this._ua.set('ha1', this._auth.get('ha1')); } else { - this._config2.realm = this._auth.get('realm'); - this._config2.ha1 = this._auth.get('ha1'); + this._config2.realm = this._auth.get('realm'); + this._config2.ha1 = this._auth.get('ha1'); } if (challenge.stale) { diff --git a/lib/Subscriber.js b/lib/Subscriber.js new file mode 100644 index 000000000..c8bb0779a --- /dev/null +++ b/lib/Subscriber.js @@ -0,0 +1,260 @@ +const EventEmitter = require('events').EventEmitter; +const JsSIP_C = require('./Constants'); +const Utils = require('./Utils'); +const debug = require('debug')('JsSIP:Subscriber'); +const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); + +debugerror.log = console.warn.bind(console); + +module.exports = class Subscriber extends EventEmitter +{ + constructor(ua, target, { event_name, accept, expires, content_type, + allow_events, params, headers, credential }) + { + super(); + this._ua = ua; + if (!target) + throw new TypeError('target is undefined'); + this.target = target; + if (!event_name) + throw new TypeError('event_name is undefined'); + this.event_name = event_name; + if (!accept) + throw new TypeError('accept is undefined'); + this.accept = accept; + if (!expires) + expires = 900; + this.expires = expires; + this.allow_events = allow_events; // optional + this.content_type = content_type; // used to subscribe with body + if (!params) + throw new TypeError('params is undefined'); + if (!params.from_uri) + throw new TypeError('params.from_uri is undefined'); + if (!params.to_uri) + throw new TypeError('params.to_uri is undefined'); + this.params = params; + params.from_tag = Utils.newTag(); + params.to_tag = null; + params.call_id = Utils.createRandomToken(20); + params.cseq = Math.floor((Math.random() * 10000) + 1); + this.contact = ``; + // this.contact = ``; + this.credential = credential; // optional + this._state = 'init'; // init, notify_wait, pending, active, terminated + this.id = null; // dialog id + this.expires_timer = null; // to update subscription + this.expires_timestamp = null; + if (!headers) + headers = []; + this.headers = headers.concat([ + `Event: ${this.event_name}`, + `Accept: ${this.accept}`, + `Expires: ${this.expires}`, + `Contact: ${this.contact}` + ]); + if (this.allowEvents) + this.headers.push(`Allow-Events: ${this.allowEvents}`); + this.is_terminated = false; + this.route_set = null; + this.data = {}; // Custom session empty object for high level use. + } + + /** + * Callbacks + */ + onAuthenticated() + { + this.params.cseq++; + } + + onRequestTimeout() + { + this._dialogTerminated('subscribe response timeout'); + } + + onTransportError() + { + this._dialogTerminated('subscribe transport error'); + } + + onReceiveResponse(response) + { + if (response.status_code >= 200 && response.status_code < 300) + { + if (this.params.to_tag === null) + { + this.params.to_tag = response.to_tag; + this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + debug('added dialog id=', this.id); + this._ua.newDialog(this); + this.route_set = response.getHeaders('record-route').reverse(); + if (this.route_set.length > 0) + this.params.route_set = this.route_set; + } + const expires = this._getExpires(response); + + if (expires === -1) + { + debugerror('response without Expires header'); + + return; + } + if (expires > 0) + { + this.expires_timestamp = new Date().getTime() + (expires * 1000); + this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + } + } + else if (response.status_code >= 300) + { + this._dialogTerminated('receive subscribe non-OK response'); + } + } + + receiveRequest(request) + { + if (request.method !== JsSIP_C.NOTIFY) + { + request.reply(405); // Method Not Allowed + + return; + } + const subs_state = request.parseHeader('subscription-state'); + + if (!subs_state) + { + debugerror('missed header Subscription-State'); + request.reply(400); // Bad request + + return; + } + request.reply(200); + + const new_state = subs_state.state.toLowerCase(); + const prev_state = this._state; + + if (prev_state !== 'terminated' && new_state !== 'terminated') + { + this._state = new_state; + if (subs_state.expires !== undefined) + { + const expires = subs_state.expires; + const expires_timestamp = new Date().getTime() + (expires * 1000); + const max_time_deviation = 2000; + + // expiration shorter and the difference is not too small + if (this.expires_timestamp - expires_timestamp > max_time_deviation) + { + debug('update sending re-SUBSCRIBE time'); + clearTimeout(this.expires_timer); + this.expires_timestamp = expires_timestamp; + this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + } + } + } + if (prev_state !== 'active' && new_state === 'active') + { + debug('emit "active"'); + this.emit('active'); + } + + const body = request.body; + const is_final = new_state === 'terminated'; + + // notify event fired for NOTIFY with body + if (body) + { + const content_type = request.getHeader('content-type'); + + debug('emit "notify"'); + this.emit('notify', is_final, request, body, content_type); + } + if (is_final) + this._dialogTerminated('receive final notify'); + } + + /** + * User API + */ + subscribe(body = null) + { + if (this._state === 'init') + this._state = 'notify_wait'; + const headers = this.headers.slice(); + + if (body) + { + if (!this.content_type) + throw new TypeError('content_type is undefined'); + headers.push(`Content-Type: ${this.content_type}`); + } + this._send(body, headers); + } + + unsubscribe() + { + this._dialogTerminated('send un-subscribe'); + const headers = [ + `Event: ${this.event_name}`, + 'Expires: 0' + ]; + + this._send(null, headers); + } + + get state() + { + return this._state; + } + + /** + * Private API. + */ + _dialogTerminated(reason) + { + if (this.is_terminated) // to prevent duplicate call + return; + this.is_terminated = true; + this._state = 'terminated'; + clearTimeout(this.expires_timer); + // remove dialog from dialogs table with some delay, to allow receive end NOTIFY + setTimeout(() => + { + debug('removed dialog id=', this.id); + this._ua.destroyDialog(this); + }, 32000); + debug(`emit "terminated" ${reason}"`); + this.emit('terminated', reason); + } + + _send(body, headers) + { + this.params.cseq++; + this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this.target, this.params, headers, + body, this, this.credential); + } + + _getExpires(r) + { + const e = r.getHeader('expires'); + + return e ? parseInt(e) : -1; + } + + _calculateTimeoutMs(expires) + { + return expires >= 140 ? (expires * 1000 / 2) + + Math.floor(((expires / 2) - 70) * 1000 * Math.random()) : (expires * 1000) - 5000; + } + + _scheduleSubscribe(timeout) + { + debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); + this.expires_timer = setTimeout(() => + { + this.expires_timer = undefined; + this._send(null, this.headers); + }, timeout); + } +}; \ No newline at end of file diff --git a/lib/UA.js b/lib/UA.js index e9e6e0391..5e0aafdcb 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -2,6 +2,8 @@ const EventEmitter = require('events').EventEmitter; const JsSIP_C = require('./Constants'); const Registrator = require('./Registrator'); const RTCSession = require('./RTCSession'); +const Subscriber = require('./Subscriber'); +const Notifier = require('./Notifier'); const Message = require('./Message'); const Transactions = require('./Transactions'); const Transport = require('./Transport'); @@ -258,16 +260,39 @@ module.exports = class UA extends EventEmitter return message; } - - /* arbitrary client transaction */ + /** + * Arbitrary client transaction + */ sendRequest(method, target, params, headers, body, handlers, credential) { debug('sendRequest()'); - const request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); + const request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), + this, params, headers, body); const requestSender = new RequestSender(this, request, handlers, credential); + requestSender.send(); } - + + /** + * Create subscriber + */ + subscriber(target, options) + { + debug('subscriber()'); + + return new Subscriber(this, target, options); + } + + /** + * Create notifier + */ + notifier(options) + { + debug('notifier()'); + + return new Notifier(this, options); + } + /** * Terminate ongoing sessions. */ @@ -612,6 +637,7 @@ module.exports = class UA extends EventEmitter if (this.listeners('newSubscribe').length === 0) { request.reply(405); + return; } } From 1220e96c0f534e78a9dffa473183e28e7aad6eb5 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 20 May 2021 17:35:24 +0300 Subject: [PATCH 04/70] Added Subscriber.js Notifier.js --- dist/jssip.js | 27937 ----------------------------------------- dist/jssip.min.js | 2 +- lib/Constants.js | 2 +- lib/Notifier.js | 224 + lib/RequestSender.js | 28 +- lib/Subscriber.js | 260 + lib/UA.js | 34 +- 7 files changed, 531 insertions(+), 27956 deletions(-) delete mode 100644 dist/jssip.js create mode 100644 lib/Notifier.js create mode 100644 lib/Subscriber.js diff --git a/dist/jssip.js b/dist/jssip.js deleted file mode 100644 index ef5bed700..000000000 --- a/dist/jssip.js +++ /dev/null @@ -1,27937 +0,0 @@ -/* - * JsSIP v3.7.5 - * the Javascript SIP library - * Copyright: 2012-2021 José Luis Millán (https://github.com/jmillan) - * Homepage: https://jssip.net - * License: MIT - */ - -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var Utils = require('./Utils'); - -var JsSIP_C = require('./Constants'); - -var Grammar = require('./Grammar'); - -var URI = require('./URI'); - -var Socket = require('./Socket'); - -var Exceptions = require('./Exceptions'); // Default settings. - - -exports.settings = { - // SIP authentication. - authorization_user: null, - password: null, - realm: null, - ha1: null, - authorization_jwt: null, - // SIP account. - display_name: null, - uri: null, - contact_uri: null, - // SIP instance id (GRUU). - instance_id: null, - // Preloaded SIP Route header field. - use_preloaded_route: false, - // Session parameters. - session_timers: true, - session_timers_refresh_method: JsSIP_C.UPDATE, - session_timers_force_refresher: false, - no_answer_timeout: 60, - // Registration parameters. - register: true, - register_expires: 600, - registrar_server: null, - // Connection options. - sockets: null, - connection_recovery_max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL, - connection_recovery_min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL, - - /* - * Host address. - * Value to be set in Via sent_by and host part of Contact FQDN. - */ - via_host: "".concat(Utils.createRandomToken(12), ".invalid") -}; // Configuration checks. - -var checks = { - mandatory: { - sockets: function sockets(_sockets2) { - /* Allow defining sockets parameter as: - * Socket: socket - * Array of Socket: [socket1, socket2] - * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}] - * Array of Objects and Socket: [{socket: socket1}, socket2] - */ - var _sockets = []; - - if (Socket.isSocket(_sockets2)) { - _sockets.push({ - socket: _sockets2 - }); - } else if (Array.isArray(_sockets2) && _sockets2.length) { - var _iterator = _createForOfIteratorHelper(_sockets2), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var socket = _step.value; - - if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) { - _sockets.push(socket); - } else if (Socket.isSocket(socket)) { - _sockets.push({ - socket: socket - }); - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } else { - return; - } - - return _sockets; - }, - uri: function uri(_uri) { - if (!/^sip:/i.test(_uri)) { - _uri = "".concat(JsSIP_C.SIP, ":").concat(_uri); - } - - var parsed = URI.parse(_uri); - - if (!parsed) { - return; - } else if (!parsed.user) { - return; - } else { - return parsed; - } - } - }, - optional: { - authorization_user: function authorization_user(_authorization_user) { - if (Grammar.parse("\"".concat(_authorization_user, "\""), 'quoted_string') === -1) { - return; - } else { - return _authorization_user; - } - }, - authorization_jwt: function authorization_jwt(_authorization_jwt) { - if (typeof _authorization_jwt === 'string') { - return _authorization_jwt; - } - }, - user_agent: function user_agent(_user_agent) { - if (typeof _user_agent === 'string') { - return _user_agent; - } - }, - connection_recovery_max_interval: function connection_recovery_max_interval(_connection_recovery_max_interval) { - if (Utils.isDecimal(_connection_recovery_max_interval)) { - var value = Number(_connection_recovery_max_interval); - - if (value > 0) { - return value; - } - } - }, - connection_recovery_min_interval: function connection_recovery_min_interval(_connection_recovery_min_interval) { - if (Utils.isDecimal(_connection_recovery_min_interval)) { - var value = Number(_connection_recovery_min_interval); - - if (value > 0) { - return value; - } - } - }, - contact_uri: function contact_uri(_contact_uri) { - if (typeof _contact_uri === 'string') { - var uri = Grammar.parse(_contact_uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } - } - }, - display_name: function display_name(_display_name) { - return _display_name; - }, - instance_id: function instance_id(_instance_id) { - if (/^uuid:/i.test(_instance_id)) { - _instance_id = _instance_id.substr(5); - } - - if (Grammar.parse(_instance_id, 'uuid') === -1) { - return; - } else { - return _instance_id; - } - }, - no_answer_timeout: function no_answer_timeout(_no_answer_timeout) { - if (Utils.isDecimal(_no_answer_timeout)) { - var value = Number(_no_answer_timeout); - - if (value > 0) { - return value; - } - } - }, - session_timers: function session_timers(_session_timers) { - if (typeof _session_timers === 'boolean') { - return _session_timers; - } - }, - session_timers_refresh_method: function session_timers_refresh_method(method) { - if (typeof method === 'string') { - method = method.toUpperCase(); - - if (method === JsSIP_C.INVITE || method === JsSIP_C.UPDATE) { - return method; - } - } - }, - session_timers_force_refresher: function session_timers_force_refresher(_session_timers_force_refresher) { - if (typeof _session_timers_force_refresher === 'boolean') { - return _session_timers_force_refresher; - } - }, - password: function password(_password) { - return String(_password); - }, - realm: function realm(_realm) { - return String(_realm); - }, - ha1: function ha1(_ha) { - return String(_ha); - }, - register: function register(_register) { - if (typeof _register === 'boolean') { - return _register; - } - }, - register_expires: function register_expires(_register_expires) { - if (Utils.isDecimal(_register_expires)) { - var value = Number(_register_expires); - - if (value > 0) { - return value; - } - } - }, - registrar_server: function registrar_server(_registrar_server) { - if (!/^sip:/i.test(_registrar_server)) { - _registrar_server = "".concat(JsSIP_C.SIP, ":").concat(_registrar_server); - } - - var parsed = URI.parse(_registrar_server); - - if (!parsed) { - return; - } else if (parsed.user) { - return; - } else { - return parsed; - } - }, - use_preloaded_route: function use_preloaded_route(_use_preloaded_route) { - if (typeof _use_preloaded_route === 'boolean') { - return _use_preloaded_route; - } - } - } -}; - -exports.load = function (dst, src) { - // Check Mandatory parameters. - for (var parameter in checks.mandatory) { - if (!src.hasOwnProperty(parameter)) { - throw new Exceptions.ConfigurationError(parameter); - } else { - var value = src[parameter]; - var checked_value = checks.mandatory[parameter](value); - - if (checked_value !== undefined) { - dst[parameter] = checked_value; - } else { - throw new Exceptions.ConfigurationError(parameter, value); - } - } - } // Check Optional parameters. - - - for (var _parameter in checks.optional) { - if (src.hasOwnProperty(_parameter)) { - var _value = src[_parameter]; - /* If the parameter value is null, empty string, undefined, empty array - * or it's a number with NaN value, then apply its default value. - */ - - if (Utils.isEmpty(_value)) { - continue; - } - - var _checked_value = checks.optional[_parameter](_value); - - if (_checked_value !== undefined) { - dst[_parameter] = _checked_value; - } else { - throw new Exceptions.ConfigurationError(_parameter, _value); - } - } - } -}; -},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":20,"./URI":25,"./Utils":26}],2:[function(require,module,exports){ -"use strict"; - -var pkg = require('../package.json'); - -module.exports = { - USER_AGENT: "".concat(pkg.title, " ").concat(pkg.version), - // SIP scheme. - SIP: 'sip', - SIPS: 'sips', - // End and Failure causes. - causes: { - // Generic error causes. - CONNECTION_ERROR: 'Connection Error', - REQUEST_TIMEOUT: 'Request Timeout', - SIP_FAILURE_CODE: 'SIP Failure Code', - INTERNAL_ERROR: 'Internal Error', - // SIP error causes. - BUSY: 'Busy', - REJECTED: 'Rejected', - REDIRECTED: 'Redirected', - UNAVAILABLE: 'Unavailable', - NOT_FOUND: 'Not Found', - ADDRESS_INCOMPLETE: 'Address Incomplete', - INCOMPATIBLE_SDP: 'Incompatible SDP', - MISSING_SDP: 'Missing SDP', - AUTHENTICATION_ERROR: 'Authentication Error', - // Session error causes. - BYE: 'Terminated', - WEBRTC_ERROR: 'WebRTC Error', - CANCELED: 'Canceled', - NO_ANSWER: 'No Answer', - EXPIRES: 'Expires', - NO_ACK: 'No ACK', - DIALOG_ERROR: 'Dialog Error', - USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access', - BAD_MEDIA_DESCRIPTION: 'Bad Media Description', - RTP_TIMEOUT: 'RTP Timeout' - }, - SIP_ERROR_CAUSES: { - REDIRECTED: [300, 301, 302, 305, 380], - BUSY: [486, 600], - REJECTED: [403, 603], - NOT_FOUND: [404, 604], - UNAVAILABLE: [480, 410, 408, 430], - ADDRESS_INCOMPLETE: [484, 424], - INCOMPATIBLE_SDP: [488, 606], - AUTHENTICATION_ERROR: [401, 407] - }, - // SIP Methods. - 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 methods. - DTMF_TRANSPORT: { - INFO: 'INFO', - RFC2833: 'RFC2833' - }, - - /* SIP Response Reasons - * DOC: https://www.iana.org/assignments/sip-parameters - * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7 - */ - REASON_PHRASE: { - 100: 'Trying', - 180: 'Ringing', - 181: 'Call Is Being Forwarded', - 182: 'Queued', - 183: 'Session Progress', - 199: 'Early Dialog Terminated', - // draft-ietf-sipcore-199 - 200: 'OK', - 202: 'Accepted', - // RFC 3265 - 204: 'No Notification', - // RFC 5839 - 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', - // RFC 3903 - 413: 'Request Entity Too Large', - 414: 'Request-URI Too Long', - 415: 'Unsupported Media Type', - 416: 'Unsupported URI Scheme', - 417: 'Unknown Resource-Priority', - // RFC 4412 - 420: 'Bad Extension', - 421: 'Extension Required', - 422: 'Session Interval Too Small', - // RFC 4028 - 423: 'Interval Too Brief', - 424: 'Bad Location Information', - // RFC 6442 - 428: 'Use Identity Header', - // RFC 4474 - 429: 'Provide Referrer Identity', - // RFC 3892 - 430: 'Flow Failed', - // RFC 5626 - 433: 'Anonymity Disallowed', - // RFC 5079 - 436: 'Bad Identity-Info', - // RFC 4474 - 437: 'Unsupported Certificate', - // RFC 4744 - 438: 'Invalid Identity Header', - // RFC 4744 - 439: 'First Hop Lacks Outbound Support', - // RFC 5626 - 440: 'Max-Breadth Exceeded', - // RFC 5393 - 469: 'Bad Info Package', - // draft-ietf-sipcore-info-events - 470: 'Consent Needed', - // RFC 5360 - 478: 'Unresolvable Destination', - // Custom code copied from Kamailio. - 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', - // RFC 3265 - 491: 'Request Pending', - 493: 'Undecipherable', - 494: 'Security Agreement Required', - // RFC 3329 - 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', - // RFC 3312 - 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(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var SIPMessage = require('./SIPMessage'); - -var JsSIP_C = require('./Constants'); - -var Transactions = require('./Transactions'); - -var Dialog_RequestSender = require('./Dialog/RequestSender'); - -var Utils = require('./Utils'); - -var debug = require('debug')('JsSIP:Dialog'); - -var C = { - // Dialog states. - STATUS_EARLY: 1, - STATUS_CONFIRMED: 2 -}; // RFC 3261 12.1. - -module.exports = /*#__PURE__*/function () { - function Dialog(owner, message, type) { - var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; - - _classCallCheck(this, Dialog); - - this._owner = owner; - this._ua = owner._ua; - this._uac_pending_reply = false; - this._uas_pending_reply = false; - - if (!message.hasHeader('contact')) { - return { - error: 'unable to create a Dialog without Contact header field' - }; - } - - if (message instanceof SIPMessage.IncomingResponse) { - state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED; - } - - var contact = message.parseHeader('contact'); // RFC 3261 12.1.1. - - if (type === 'UAS') { - this._id = { - call_id: message.call_id, - local_tag: message.to_tag, - remote_tag: message.from_tag, - toString: function toString() { - return this.call_id + this.local_tag + this.remote_tag; - } - }; - this._state = state; - this._remote_seqnum = message.cseq; - this._local_uri = message.parseHeader('to').uri; - this._remote_uri = message.parseHeader('from').uri; - this._remote_target = contact.uri; - this._route_set = message.getHeaders('record-route'); - this._ack_seqnum = this._remote_seqnum; - } // RFC 3261 12.1.2. - else if (type === 'UAC') { - this._id = { - call_id: message.call_id, - local_tag: message.from_tag, - remote_tag: message.to_tag, - toString: function toString() { - return this.call_id + this.local_tag + this.remote_tag; - } - }; - this._state = state; - this._local_seqnum = message.cseq; - this._local_uri = message.parseHeader('from').uri; - this._remote_uri = message.parseHeader('to').uri; - this._remote_target = contact.uri; - this._route_set = message.getHeaders('record-route').reverse(); - this._ack_seqnum = null; - } - - this._ua.newDialog(this); - - debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); - } - - _createClass(Dialog, [{ - key: "id", - get: function get() { - return this._id; - } - }, { - key: "local_seqnum", - get: function get() { - return this._local_seqnum; - }, - set: function set(num) { - this._local_seqnum = num; - } - }, { - key: "owner", - get: function get() { - return this._owner; - } - }, { - key: "uac_pending_reply", - get: function get() { - return this._uac_pending_reply; - }, - set: function set(pending) { - this._uac_pending_reply = pending; - } - }, { - key: "uas_pending_reply", - get: function get() { - return this._uas_pending_reply; - } - }, { - key: "update", - value: function update(message, type) { - this._state = C.STATUS_CONFIRMED; - debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); - - if (type === 'UAC') { - // RFC 3261 13.2.2.4. - this._route_set = message.getHeaders('record-route').reverse(); - } - } - }, { - key: "terminate", - value: function terminate() { - debug("dialog ".concat(this._id.toString(), " deleted")); - - this._ua.destroyDialog(this); - } - }, { - key: "sendRequest", - value: function sendRequest(method) { - var _this = this; - - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var body = options.body || null; - - var request = this._createRequest(method, extraHeaders, body); // Increase the local CSeq on authentication. - - - eventHandlers.onAuthenticated = function () { - _this._local_seqnum += 1; - }; - - var request_sender = new Dialog_RequestSender(this, request, eventHandlers); - request_sender.send(); // Return the instance of OutgoingRequest. - - return request; - } - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - // Check in-dialog request. - if (!this._checkInDialogRequest(request)) { - return; - } // ACK received. Cleanup this._ack_seqnum. - - - if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) { - this._ack_seqnum = null; - } // INVITE received. Set this._ack_seqnum. - else if (request.method === JsSIP_C.INVITE) { - this._ack_seqnum = request.cseq; - } - - this._owner.receiveRequest(request); - } // RFC 3261 12.2.1.1. - - }, { - key: "_createRequest", - value: function _createRequest(method, extraHeaders, body) { - extraHeaders = Utils.cloneArray(extraHeaders); - - if (!this._local_seqnum) { - this._local_seqnum = Math.floor(Math.random() * 10000); - } - - var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1; - var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, { - 'cseq': cseq, - '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 - }, extraHeaders, body); - return request; - } // RFC 3261 12.2.2. - - }, { - key: "_checkInDialogRequest", - value: function _checkInDialogRequest(request) { - var _this2 = this; - - if (!this._remote_seqnum) { - this._remote_seqnum = request.cseq; - } else if (request.cseq < this._remote_seqnum) { - if (request.method === JsSIP_C.ACK) { - // We are not expecting any ACK with lower seqnum than the current one. - // Or this is not the ACK we are waiting for. - if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) { - return false; - } - } else { - request.reply(500); - return false; - } - } else if (request.cseq > this._remote_seqnum) { - this._remote_seqnum = request.cseq; - } // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-. - - - if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) { - if (this._uac_pending_reply === true) { - request.reply(491); - } else if (this._uas_pending_reply === true) { - var retryAfter = (Math.random() * 10 | 0) + 1; - request.reply(500, null, ["Retry-After:".concat(retryAfter)]); - return false; - } else { - this._uas_pending_reply = true; - - var stateChanged = function stateChanged() { - if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED || request.server_transaction.state === Transactions.C.STATUS_COMPLETED || request.server_transaction.state === Transactions.C.STATUS_TERMINATED) { - request.server_transaction.removeListener('stateChanged', stateChanged); - _this2._uas_pending_reply = false; - } - }; - - request.server_transaction.on('stateChanged', stateChanged); - } // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted. - - - if (request.hasHeader('contact')) { - request.server_transaction.on('stateChanged', function () { - if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED) { - _this2._remote_target = request.parseHeader('contact').uri; - } - }); - } - } else if (request.method === JsSIP_C.NOTIFY) { - // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted. - if (request.hasHeader('contact')) { - request.server_transaction.on('stateChanged', function () { - if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) { - _this2._remote_target = request.parseHeader('contact').uri; - } - }); - } - } - - return true; - } - }], [{ - key: "C", - get: // Expose C object. - function get() { - return C; - } - }]); - - return Dialog; -}(); -},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":19,"./Transactions":22,"./Utils":26,"debug":30}],4:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var JsSIP_C = require('../Constants'); - -var Transactions = require('../Transactions'); - -var RTCSession = require('../RTCSession'); - -var RequestSender = require('../RequestSender'); // Default event handlers. - - -var EventHandlers = { - onRequestTimeout: function onRequestTimeout() {}, - onTransportError: function onTransportError() {}, - onSuccessResponse: function onSuccessResponse() {}, - onErrorResponse: function onErrorResponse() {}, - onAuthenticated: function onAuthenticated() {}, - onDialogError: function onDialogError() {} -}; - -module.exports = /*#__PURE__*/function () { - function DialogRequestSender(dialog, request, eventHandlers) { - _classCallCheck(this, DialogRequestSender); - - this._dialog = dialog; - this._ua = dialog._ua; - this._request = request; - this._eventHandlers = eventHandlers; // RFC3261 14.1 Modifying an Existing Session. UAC Behavior. - - this._reattempt = false; - this._reattemptTimer = null; // Define the undefined handlers. - - for (var handler in EventHandlers) { - if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { - if (!this._eventHandlers[handler]) { - this._eventHandlers[handler] = EventHandlers[handler]; - } - } - } - } - - _createClass(DialogRequestSender, [{ - key: "request", - get: function get() { - return this._request; - } - }, { - key: "send", - value: function send() { - var _this = this; - - var request_sender = new RequestSender(this._ua, this._request, { - onRequestTimeout: function onRequestTimeout() { - _this._eventHandlers.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this._eventHandlers.onTransportError(); - }, - onAuthenticated: function onAuthenticated(request) { - _this._eventHandlers.onAuthenticated(request); - }, - onReceiveResponse: function onReceiveResponse(response) { - _this._receiveResponse(response); - } - }); - request_sender.send(); // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-. - - if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) { - this._dialog.uac_pending_reply = true; - - var stateChanged = function stateChanged() { - if (request_sender.clientTransaction.state === Transactions.C.STATUS_ACCEPTED || request_sender.clientTransaction.state === Transactions.C.STATUS_COMPLETED || request_sender.clientTransaction.state === Transactions.C.STATUS_TERMINATED) { - request_sender.clientTransaction.removeListener('stateChanged', stateChanged); - _this._dialog.uac_pending_reply = false; - } - }; - - request_sender.clientTransaction.on('stateChanged', stateChanged); - } - } - }, { - key: "_receiveResponse", - value: function _receiveResponse(response) { - var _this2 = this; - - // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog. - if (response.status_code === 408 || response.status_code === 481) { - this._eventHandlers.onDialogError(response); - } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) { - if (this._reattempt) { - if (response.status_code >= 200 && response.status_code < 300) { - this._eventHandlers.onSuccessResponse(response); - } else if (response.status_code >= 300) { - this._eventHandlers.onErrorResponse(response); - } - } else { - this._request.cseq = this._dialog.local_seqnum += 1; - this._reattemptTimer = setTimeout(function () { - // TODO: look at dialog state instead. - if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) { - _this2._reattempt = true; - - _this2._request_sender.send(); - } - }, 1000); - } - } else if (response.status_code >= 200 && response.status_code < 300) { - this._eventHandlers.onSuccessResponse(response); - } else if (response.status_code >= 300) { - this._eventHandlers.onErrorResponse(response); - } - } - }]); - - return DialogRequestSender; -}(); -},{"../Constants":2,"../RTCSession":12,"../RequestSender":18,"../Transactions":22}],5:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Utils = require('./Utils'); - -var debug = require('debug')('JsSIP:DigestAuthentication'); - -var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); - -debugerror.log = console.warn.bind(console); - -module.exports = /*#__PURE__*/function () { - function DigestAuthentication(credentials) { - _classCallCheck(this, DigestAuthentication); - - this._credentials = credentials; - 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; - } - - _createClass(DigestAuthentication, [{ - key: "get", - value: function get(parameter) { - switch (parameter) { - case 'realm': - return this._realm; - - case 'ha1': - return this._ha1; - - default: - debugerror('get() | cannot get "%s" parameter', parameter); - return undefined; - } - } - /** - * Performs Digest authentication given a SIP request and the challenge - * received in a response to that request. - * Returns true if auth was successfully generated, false otherwise. - */ - - }, { - key: "authenticate", - value: function authenticate(_ref, challenge) - /* test interface */ - { - var method = _ref.method, - ruri = _ref.ruri, - body = _ref.body; - var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - this._algorithm = challenge.algorithm; - this._realm = challenge.realm; - this._nonce = challenge.nonce; - this._opaque = challenge.opaque; - this._stale = challenge.stale; - - if (this._algorithm) { - if (this._algorithm !== 'MD5') { - debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); - return false; - } - } else { - this._algorithm = 'MD5'; - } - - if (!this._nonce) { - debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); - return false; - } - - if (!this._realm) { - debugerror('authenticate() | challenge without Digest realm, authentication aborted'); - return false; - } // If no plain SIP password is provided. - - - if (!this._credentials.password) { - // If ha1 is not provided we cannot authenticate. - if (!this._credentials.ha1) { - debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); - return false; - } // If the realm does not match the stored realm we cannot authenticate. - - - if (this._credentials.realm !== this._realm) { - debugerror('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); - return false; - } - } // 'qop' can contain a list of values (Array). Let's choose just one. - - - if (challenge.qop) { - if (challenge.qop.indexOf('auth-int') > -1) { - this._qop = 'auth-int'; - } else if (challenge.qop.indexOf('auth') > -1) { - this._qop = 'auth'; - } else { - // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. - debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); - return false; - } - } else { - this._qop = null; - } // Fill other attributes. - - - this._method = method; - this._uri = ruri; - this._cnonce = cnonce || Utils.createRandomToken(12); - this._nc += 1; - var hex = Number(this._nc).toString(16); - this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex; // Nc-value = 8LHEX. Max value = 'FFFFFFFF'. - - if (this._nc === 4294967296) { - this._nc = 1; - this._ncHex = '00000001'; - } // Calculate the Digest "response" value. - // If we have plain SIP password then regenerate ha1. - - - if (this._credentials.password) { - // HA1 = MD5(A1) = MD5(username:realm:password). - this._ha1 = Utils.calculateMD5("".concat(this._credentials.username, ":").concat(this._realm, ":").concat(this._credentials.password)); - } // Otherwise reuse the stored ha1. - else { - this._ha1 = this._credentials.ha1; - } - - var a2; - var ha2; - - if (this._qop === 'auth') { - // HA2 = MD5(A2) = MD5(method:digestURI). - a2 = "".concat(this._method, ":").concat(this._uri); - ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). - - this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2)); - } else if (this._qop === 'auth-int') { - // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)). - a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : '')); - ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). - - this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2)); - } else if (this._qop === null) { - // HA2 = MD5(A2) = MD5(method:digestURI). - a2 = "".concat(this._method, ":").concat(this._uri); - ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). - - this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2)); - } - - debug('authenticate() | response generated'); - return true; - } - /** - * Return the Proxy-Authorization or WWW-Authorization header value. - */ - - }, { - key: "toString", - value: function toString() { - var auth_params = []; - - if (!this._response) { - throw new Error('response field does not exist, cannot generate Authorization header'); - } - - auth_params.push("algorithm=".concat(this._algorithm)); - auth_params.push("username=\"".concat(this._credentials.username, "\"")); - auth_params.push("realm=\"".concat(this._realm, "\"")); - auth_params.push("nonce=\"".concat(this._nonce, "\"")); - auth_params.push("uri=\"".concat(this._uri, "\"")); - auth_params.push("response=\"".concat(this._response, "\"")); - - if (this._opaque) { - auth_params.push("opaque=\"".concat(this._opaque, "\"")); - } - - if (this._qop) { - auth_params.push("qop=".concat(this._qop)); - auth_params.push("cnonce=\"".concat(this._cnonce, "\"")); - auth_params.push("nc=".concat(this._ncHex)); - } - - return "Digest ".concat(auth_params.join(', ')); - } - }]); - - return DigestAuthentication; -}(); -},{"./Utils":26,"debug":30}],6:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } - -function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var ConfigurationError = /*#__PURE__*/function (_Error) { - _inherits(ConfigurationError, _Error); - - var _super = _createSuper(ConfigurationError); - - function ConfigurationError(parameter, value) { - var _this; - - _classCallCheck(this, ConfigurationError); - - _this = _super.call(this); - _this.code = 1; - _this.name = 'CONFIGURATION_ERROR'; - _this.parameter = parameter; - _this.value = value; - _this.message = !_this.value ? "Missing parameter: ".concat(_this.parameter) : "Invalid value ".concat(JSON.stringify(_this.value), " for parameter \"").concat(_this.parameter, "\""); - return _this; - } - - return ConfigurationError; -}( /*#__PURE__*/_wrapNativeSuper(Error)); - -var InvalidStateError = /*#__PURE__*/function (_Error2) { - _inherits(InvalidStateError, _Error2); - - var _super2 = _createSuper(InvalidStateError); - - function InvalidStateError(status) { - var _this2; - - _classCallCheck(this, InvalidStateError); - - _this2 = _super2.call(this); - _this2.code = 2; - _this2.name = 'INVALID_STATE_ERROR'; - _this2.status = status; - _this2.message = "Invalid status: ".concat(status); - return _this2; - } - - return InvalidStateError; -}( /*#__PURE__*/_wrapNativeSuper(Error)); - -var NotSupportedError = /*#__PURE__*/function (_Error3) { - _inherits(NotSupportedError, _Error3); - - var _super3 = _createSuper(NotSupportedError); - - function NotSupportedError(message) { - var _this3; - - _classCallCheck(this, NotSupportedError); - - _this3 = _super3.call(this); - _this3.code = 3; - _this3.name = 'NOT_SUPPORTED_ERROR'; - _this3.message = message; - return _this3; - } - - return NotSupportedError; -}( /*#__PURE__*/_wrapNativeSuper(Error)); - -var NotReadyError = /*#__PURE__*/function (_Error4) { - _inherits(NotReadyError, _Error4); - - var _super4 = _createSuper(NotReadyError); - - function NotReadyError(message) { - var _this4; - - _classCallCheck(this, NotReadyError); - - _this4 = _super4.call(this); - _this4.code = 4; - _this4.name = 'NOT_READY_ERROR'; - _this4.message = message; - return _this4; - } - - return NotReadyError; -}( /*#__PURE__*/_wrapNativeSuper(Error)); - -module.exports = { - ConfigurationError: ConfigurationError, - InvalidStateError: InvalidStateError, - NotSupportedError: NotSupportedError, - NotReadyError: NotReadyError -}; -},{}],7:[function(require,module,exports){ -"use strict"; - -module.exports = function () { - /* - * Generated by PEG.js 0.7.0. - * - * http://pegjs.majda.cz/ - */ - function quote(s) { - /* - * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a - * string literal except for the closing quote character, backslash, - * carriage return, line separator, paragraph separator, and line feed. - * Any character may appear in the form of an escape sequence. - * - * For portability, we also escape escape all control and non-ASCII - * characters. Note that "\0" and "\v" escape sequences are not used - * because JSHint does not like the first and IE the second. - */ - return '"' + s.replace(/\\/g, '\\\\') // backslash - .replace(/"/g, '\\"') // closing quote character - .replace(/\x08/g, '\\b') // backspace - .replace(/\t/g, '\\t') // horizontal tab - .replace(/\n/g, '\\n') // line feed - .replace(/\f/g, '\\f') // form feed - .replace(/\r/g, '\\r') // carriage return - .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"'; - } - - var result = { - /* - * Parses the input with a generated parser. If the parsing is successfull, - * returns a value explicitly or implicitly specified by the grammar from - * which the parser was generated (see |PEG.buildParser|). If the parsing is - * unsuccessful, throws |PEG.parser.SyntaxError| describing the error. - */ - parse: function parse(input, startRule) { - var parseFunctions = { - "CRLF": parse_CRLF, - "DIGIT": parse_DIGIT, - "ALPHA": parse_ALPHA, - "HEXDIG": parse_HEXDIG, - "WSP": parse_WSP, - "OCTET": parse_OCTET, - "DQUOTE": parse_DQUOTE, - "SP": parse_SP, - "HTAB": parse_HTAB, - "alphanum": parse_alphanum, - "reserved": parse_reserved, - "unreserved": parse_unreserved, - "mark": parse_mark, - "escaped": parse_escaped, - "LWS": parse_LWS, - "SWS": parse_SWS, - "HCOLON": parse_HCOLON, - "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM, - "TEXT_UTF8char": parse_TEXT_UTF8char, - "UTF8_NONASCII": parse_UTF8_NONASCII, - "UTF8_CONT": parse_UTF8_CONT, - "LHEX": parse_LHEX, - "token": parse_token, - "token_nodot": parse_token_nodot, - "separators": parse_separators, - "word": parse_word, - "STAR": parse_STAR, - "SLASH": parse_SLASH, - "EQUAL": parse_EQUAL, - "LPAREN": parse_LPAREN, - "RPAREN": parse_RPAREN, - "RAQUOT": parse_RAQUOT, - "LAQUOT": parse_LAQUOT, - "COMMA": parse_COMMA, - "SEMI": parse_SEMI, - "COLON": parse_COLON, - "LDQUOT": parse_LDQUOT, - "RDQUOT": parse_RDQUOT, - "comment": parse_comment, - "ctext": parse_ctext, - "quoted_string": parse_quoted_string, - "quoted_string_clean": parse_quoted_string_clean, - "qdtext": parse_qdtext, - "quoted_pair": parse_quoted_pair, - "SIP_URI_noparams": parse_SIP_URI_noparams, - "SIP_URI": parse_SIP_URI, - "uri_scheme": parse_uri_scheme, - "uri_scheme_sips": parse_uri_scheme_sips, - "uri_scheme_sip": parse_uri_scheme_sip, - "userinfo": parse_userinfo, - "user": parse_user, - "user_unreserved": parse_user_unreserved, - "password": parse_password, - "hostport": parse_hostport, - "host": parse_host, - "hostname": parse_hostname, - "domainlabel": parse_domainlabel, - "toplabel": parse_toplabel, - "IPv6reference": parse_IPv6reference, - "IPv6address": parse_IPv6address, - "h16": parse_h16, - "ls32": parse_ls32, - "IPv4address": parse_IPv4address, - "dec_octet": parse_dec_octet, - "port": parse_port, - "uri_parameters": parse_uri_parameters, - "uri_parameter": parse_uri_parameter, - "transport_param": parse_transport_param, - "user_param": parse_user_param, - "method_param": parse_method_param, - "ttl_param": parse_ttl_param, - "maddr_param": parse_maddr_param, - "lr_param": parse_lr_param, - "other_param": parse_other_param, - "pname": parse_pname, - "pvalue": parse_pvalue, - "paramchar": parse_paramchar, - "param_unreserved": parse_param_unreserved, - "headers": parse_headers, - "header": parse_header, - "hname": parse_hname, - "hvalue": parse_hvalue, - "hnv_unreserved": parse_hnv_unreserved, - "Request_Response": parse_Request_Response, - "Request_Line": parse_Request_Line, - "Request_URI": parse_Request_URI, - "absoluteURI": parse_absoluteURI, - "hier_part": parse_hier_part, - "net_path": parse_net_path, - "abs_path": parse_abs_path, - "opaque_part": parse_opaque_part, - "uric": parse_uric, - "uric_no_slash": parse_uric_no_slash, - "path_segments": parse_path_segments, - "segment": parse_segment, - "param": parse_param, - "pchar": parse_pchar, - "scheme": parse_scheme, - "authority": parse_authority, - "srvr": parse_srvr, - "reg_name": parse_reg_name, - "query": parse_query, - "SIP_Version": parse_SIP_Version, - "INVITEm": parse_INVITEm, - "ACKm": parse_ACKm, - "OPTIONSm": parse_OPTIONSm, - "BYEm": parse_BYEm, - "CANCELm": parse_CANCELm, - "REGISTERm": parse_REGISTERm, - "SUBSCRIBEm": parse_SUBSCRIBEm, - "NOTIFYm": parse_NOTIFYm, - "REFERm": parse_REFERm, - "Method": parse_Method, - "Status_Line": parse_Status_Line, - "Status_Code": parse_Status_Code, - "extension_code": parse_extension_code, - "Reason_Phrase": parse_Reason_Phrase, - "Allow_Events": parse_Allow_Events, - "Call_ID": parse_Call_ID, - "Contact": parse_Contact, - "contact_param": parse_contact_param, - "name_addr": parse_name_addr, - "display_name": parse_display_name, - "contact_params": parse_contact_params, - "c_p_q": parse_c_p_q, - "c_p_expires": parse_c_p_expires, - "delta_seconds": parse_delta_seconds, - "qvalue": parse_qvalue, - "generic_param": parse_generic_param, - "gen_value": parse_gen_value, - "Content_Disposition": parse_Content_Disposition, - "disp_type": parse_disp_type, - "disp_param": parse_disp_param, - "handling_param": parse_handling_param, - "Content_Encoding": parse_Content_Encoding, - "Content_Length": parse_Content_Length, - "Content_Type": parse_Content_Type, - "media_type": parse_media_type, - "m_type": parse_m_type, - "discrete_type": parse_discrete_type, - "composite_type": parse_composite_type, - "extension_token": parse_extension_token, - "x_token": parse_x_token, - "m_subtype": parse_m_subtype, - "m_parameter": parse_m_parameter, - "m_value": parse_m_value, - "CSeq": parse_CSeq, - "CSeq_value": parse_CSeq_value, - "Expires": parse_Expires, - "Event": parse_Event, - "event_type": parse_event_type, - "From": parse_From, - "from_param": parse_from_param, - "tag_param": parse_tag_param, - "Max_Forwards": parse_Max_Forwards, - "Min_Expires": parse_Min_Expires, - "Name_Addr_Header": parse_Name_Addr_Header, - "Proxy_Authenticate": parse_Proxy_Authenticate, - "challenge": parse_challenge, - "other_challenge": parse_other_challenge, - "auth_param": parse_auth_param, - "digest_cln": parse_digest_cln, - "realm": parse_realm, - "realm_value": parse_realm_value, - "domain": parse_domain, - "URI": parse_URI, - "nonce": parse_nonce, - "nonce_value": parse_nonce_value, - "opaque": parse_opaque, - "stale": parse_stale, - "algorithm": parse_algorithm, - "qop_options": parse_qop_options, - "qop_value": parse_qop_value, - "Proxy_Require": parse_Proxy_Require, - "Record_Route": parse_Record_Route, - "rec_route": parse_rec_route, - "Reason": parse_Reason, - "reason_param": parse_reason_param, - "reason_cause": parse_reason_cause, - "Require": parse_Require, - "Route": parse_Route, - "route_param": parse_route_param, - "Subscription_State": parse_Subscription_State, - "substate_value": parse_substate_value, - "subexp_params": parse_subexp_params, - "event_reason_value": parse_event_reason_value, - "Subject": parse_Subject, - "Supported": parse_Supported, - "To": parse_To, - "to_param": parse_to_param, - "Via": parse_Via, - "via_param": parse_via_param, - "via_params": parse_via_params, - "via_ttl": parse_via_ttl, - "via_maddr": parse_via_maddr, - "via_received": parse_via_received, - "via_branch": parse_via_branch, - "response_port": parse_response_port, - "rport": parse_rport, - "sent_protocol": parse_sent_protocol, - "protocol_name": parse_protocol_name, - "transport": parse_transport, - "sent_by": parse_sent_by, - "via_host": parse_via_host, - "via_port": parse_via_port, - "ttl": parse_ttl, - "WWW_Authenticate": parse_WWW_Authenticate, - "Session_Expires": parse_Session_Expires, - "s_e_expires": parse_s_e_expires, - "s_e_params": parse_s_e_params, - "s_e_refresher": parse_s_e_refresher, - "extension_header": parse_extension_header, - "header_value": parse_header_value, - "message_body": parse_message_body, - "uuid_URI": parse_uuid_URI, - "uuid": parse_uuid, - "hex4": parse_hex4, - "hex8": parse_hex8, - "hex12": parse_hex12, - "Refer_To": parse_Refer_To, - "Replaces": parse_Replaces, - "call_id": parse_call_id, - "replaces_param": parse_replaces_param, - "to_tag": parse_to_tag, - "from_tag": parse_from_tag, - "early_flag": parse_early_flag - }; - - if (startRule !== undefined) { - if (parseFunctions[startRule] === undefined) { - throw new Error("Invalid rule name: " + quote(startRule) + "."); - } - } else { - startRule = "CRLF"; - } - - var pos = 0; - var reportFailures = 0; - var rightmostFailuresPos = 0; - var rightmostFailuresExpected = []; - - function padLeft(input, padding, length) { - var result = input; - var padLength = length - input.length; - - for (var i = 0; i < padLength; i++) { - result = padding + result; - } - - return result; - } - - function escape(ch) { - var charCode = ch.charCodeAt(0); - var escapeChar; - var length; - - if (charCode <= 0xFF) { - escapeChar = 'x'; - length = 2; - } else { - escapeChar = 'u'; - length = 4; - } - - return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); - } - - function matchFailed(failure) { - if (pos < rightmostFailuresPos) { - return; - } - - if (pos > rightmostFailuresPos) { - rightmostFailuresPos = pos; - rightmostFailuresExpected = []; - } - - rightmostFailuresExpected.push(failure); - } - - function parse_CRLF() { - var result0; - - if (input.substr(pos, 2) === "\r\n") { - result0 = "\r\n"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"\\r\\n\""); - } - } - - return result0; - } - - function parse_DIGIT() { - var result0; - - if (/^[0-9]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[0-9]"); - } - } - - return result0; - } - - function parse_ALPHA() { - var result0; - - if (/^[a-zA-Z]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[a-zA-Z]"); - } - } - - return result0; - } - - function parse_HEXDIG() { - var result0; - - if (/^[0-9a-fA-F]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[0-9a-fA-F]"); - } - } - - return result0; - } - - function parse_WSP() { - var result0; - result0 = parse_SP(); - - if (result0 === null) { - result0 = parse_HTAB(); - } - - return result0; - } - - function parse_OCTET() { - var result0; - - if (/^[\0-\xFF]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\0-\\xFF]"); - } - } - - return result0; - } - - function parse_DQUOTE() { - var result0; - - if (/^["]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\"]"); - } - } - - return result0; - } - - function parse_SP() { - var result0; - - if (input.charCodeAt(pos) === 32) { - result0 = " "; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\" \""); - } - } - - return result0; - } - - function parse_HTAB() { - var result0; - - if (input.charCodeAt(pos) === 9) { - result0 = "\t"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"\\t\""); - } - } - - return result0; - } - - function parse_alphanum() { - var result0; - - if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[a-zA-Z0-9]"); - } - } - - return result0; - } - - function parse_reserved() { - var result0; - - if (input.charCodeAt(pos) === 59) { - result0 = ";"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 64) { - result0 = "@"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_unreserved() { - var result0; - result0 = parse_alphanum(); - - if (result0 === null) { - result0 = parse_mark(); - } - - return result0; - } - - function parse_mark() { - var result0; - - if (input.charCodeAt(pos) === 45) { - result0 = "-"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 95) { - result0 = "_"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 46) { - result0 = "."; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 33) { - result0 = "!"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 126) { - result0 = "~"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 42) { - result0 = "*"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 39) { - result0 = "'"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 40) { - result0 = "("; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 41) { - result0 = ")"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_escaped() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.charCodeAt(pos) === 37) { - result0 = "%"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result0 !== null) { - result1 = parse_HEXDIG(); - - if (result1 !== null) { - result2 = parse_HEXDIG(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, escaped) { - return escaped.join(''); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_LWS() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - pos2 = pos; - result0 = []; - result1 = parse_WSP(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_WSP(); - } - - if (result0 !== null) { - result1 = parse_CRLF(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos2; - } - } else { - result0 = null; - pos = pos2; - } - - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result2 = parse_WSP(); - - if (result2 !== null) { - result1 = []; - - while (result2 !== null) { - result1.push(result2); - result2 = parse_WSP(); - } - } else { - result1 = null; - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return " "; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_SWS() { - var result0; - result0 = parse_LWS(); - result0 = result0 !== null ? result0 : ""; - return result0; - } - - function parse_HCOLON() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = []; - result1 = parse_SP(); - - if (result1 === null) { - result1 = parse_HTAB(); - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_SP(); - - if (result1 === null) { - result1 = parse_HTAB(); - } - } - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ':'; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_TEXT_UTF8_TRIM() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result1 = parse_TEXT_UTF8char(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_TEXT_UTF8char(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = []; - result3 = parse_LWS(); - - while (result3 !== null) { - result2.push(result3); - result3 = parse_LWS(); - } - - if (result2 !== null) { - result3 = parse_TEXT_UTF8char(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = []; - result3 = parse_LWS(); - - while (result3 !== null) { - result2.push(result3); - result3 = parse_LWS(); - } - - if (result2 !== null) { - result3 = parse_TEXT_UTF8char(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_TEXT_UTF8char() { - var result0; - - if (/^[!-~]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[!-~]"); - } - } - - if (result0 === null) { - result0 = parse_UTF8_NONASCII(); - } - - return result0; - } - - function parse_UTF8_NONASCII() { - var result0; - - if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\x80-\\uFFFF]"); - } - } - - return result0; - } - - function parse_UTF8_CONT() { - var result0; - - if (/^[\x80-\xBF]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\x80-\\xBF]"); - } - } - - return result0; - } - - function parse_LHEX() { - var result0; - result0 = parse_DIGIT(); - - if (result0 === null) { - if (/^[a-f]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[a-f]"); - } - } - } - - return result0; - } - - function parse_token() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - } - } - } - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - } - } - } - } - } - } - } - } - } - } - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_token_nodot() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - } - } - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - } - } - } - } - } - } - } - } - } - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_separators() { - var result0; - - if (input.charCodeAt(pos) === 40) { - result0 = "("; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 41) { - result0 = ")"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 60) { - result0 = "<"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"<\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 62) { - result0 = ">"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\">\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 64) { - result0 = "@"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 59) { - result0 = ";"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 92) { - result0 = "\\"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"\\\\\""); - } - } - - if (result0 === null) { - result0 = parse_DQUOTE(); - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 91) { - result0 = "["; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 93) { - result0 = "]"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 123) { - result0 = "{"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"{\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 125) { - result0 = "}"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"}\""); - } - } - - if (result0 === null) { - result0 = parse_SP(); - - if (result0 === null) { - result0 = parse_HTAB(); - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_word() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 40) { - result1 = "("; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 41) { - result1 = ")"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 60) { - result1 = "<"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"<\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 62) { - result1 = ">"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\">\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 92) { - result1 = "\\"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"\\\\\""); - } - } - - if (result1 === null) { - result1 = parse_DQUOTE(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 47) { - result1 = "/"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 91) { - result1 = "["; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 93) { - result1 = "]"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 63) { - result1 = "?"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 123) { - result1 = "{"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"{\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 125) { - result1 = "}"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"}\""); - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_alphanum(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 33) { - result1 = "!"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 37) { - result1 = "%"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"%\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 95) { - result1 = "_"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 96) { - result1 = "`"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"`\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 39) { - result1 = "'"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"'\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 126) { - result1 = "~"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"~\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 40) { - result1 = "("; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 41) { - result1 = ")"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 60) { - result1 = "<"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"<\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 62) { - result1 = ">"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\">\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 92) { - result1 = "\\"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"\\\\\""); - } - } - - if (result1 === null) { - result1 = parse_DQUOTE(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 47) { - result1 = "/"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 91) { - result1 = "["; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 93) { - result1 = "]"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 63) { - result1 = "?"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 123) { - result1 = "{"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"{\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 125) { - result1 = "}"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"}\""); - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_STAR() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 42) { - result1 = "*"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"*\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "*"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_SLASH() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 47) { - result1 = "/"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "/"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_EQUAL() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "="; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_LPAREN() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 40) { - result1 = "("; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"(\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "("; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_RPAREN() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 41) { - result1 = ")"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\")\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ")"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_RAQUOT() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.charCodeAt(pos) === 62) { - result0 = ">"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\">\""); - } - } - - if (result0 !== null) { - result1 = parse_SWS(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ">"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_LAQUOT() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 60) { - result1 = "<"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"<\""); - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "<"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_COMMA() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ","; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_SEMI() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ";"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_COLON() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_SWS(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return ":"; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_LDQUOT() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - result1 = parse_DQUOTE(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "\""; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_RDQUOT() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DQUOTE(); - - if (result0 !== null) { - result1 = parse_SWS(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return "\""; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_comment() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_LPAREN(); - - if (result0 !== null) { - result1 = []; - result2 = parse_ctext(); - - if (result2 === null) { - result2 = parse_quoted_pair(); - - if (result2 === null) { - result2 = parse_comment(); - } - } - - while (result2 !== null) { - result1.push(result2); - result2 = parse_ctext(); - - if (result2 === null) { - result2 = parse_quoted_pair(); - - if (result2 === null) { - result2 = parse_comment(); - } - } - } - - if (result1 !== null) { - result2 = parse_RPAREN(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_ctext() { - var result0; - - if (/^[!-']/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[!-']"); - } - } - - if (result0 === null) { - if (/^[*-[]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[*-[]"); - } - } - - if (result0 === null) { - if (/^[\]-~]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\]-~]"); - } - } - - if (result0 === null) { - result0 = parse_UTF8_NONASCII(); - - if (result0 === null) { - result0 = parse_LWS(); - } - } - } - } - - return result0; - } - - function parse_quoted_string() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - result1 = parse_DQUOTE(); - - if (result1 !== null) { - result2 = []; - result3 = parse_qdtext(); - - if (result3 === null) { - result3 = parse_quoted_pair(); - } - - while (result3 !== null) { - result2.push(result3); - result3 = parse_qdtext(); - - if (result3 === null) { - result3 = parse_quoted_pair(); - } - } - - if (result2 !== null) { - result3 = parse_DQUOTE(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_quoted_string_clean() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_SWS(); - - if (result0 !== null) { - result1 = parse_DQUOTE(); - - if (result1 !== null) { - result2 = []; - result3 = parse_qdtext(); - - if (result3 === null) { - result3 = parse_quoted_pair(); - } - - while (result3 !== null) { - result2.push(result3); - result3 = parse_qdtext(); - - if (result3 === null) { - result3 = parse_quoted_pair(); - } - } - - if (result2 !== null) { - result3 = parse_DQUOTE(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var trimmed = input.substring(pos, offset).trim(); - return trimmed.substring(1, trimmed.length - 1) // remove outer quotes - .replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g, '$1'); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_qdtext() { - var result0; - result0 = parse_LWS(); - - if (result0 === null) { - if (input.charCodeAt(pos) === 33) { - result0 = "!"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"!\""); - } - } - - if (result0 === null) { - if (/^[#-[]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[#-[]"); - } - } - - if (result0 === null) { - if (/^[\]-~]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[\\]-~]"); - } - } - - if (result0 === null) { - result0 = parse_UTF8_NONASCII(); - } - } - } - } - - return result0; - } - - function parse_quoted_pair() { - var result0, result1; - var pos0; - pos0 = pos; - - if (input.charCodeAt(pos) === 92) { - result0 = "\\"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"\\\\\""); - } - } - - if (result0 !== null) { - if (/^[\0-\t]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[\\0-\\t]"); - } - } - - if (result1 === null) { - if (/^[\x0B-\f]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[\\x0B-\\f]"); - } - } - - if (result1 === null) { - if (/^[\x0E-]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[\\x0E-]"); - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_SIP_URI_noparams() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_uri_scheme(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_userinfo(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_hostport(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - try { - data.uri = new URI(data.scheme, data.user, data.host, data.port); - delete data.scheme; - delete data.user; - delete data.host; - delete data.host_type; - delete data.port; - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_SIP_URI() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_uri_scheme(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_userinfo(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_hostport(); - - if (result3 !== null) { - result4 = parse_uri_parameters(); - - if (result4 !== null) { - result5 = parse_headers(); - result5 = result5 !== null ? result5 : ""; - - if (result5 !== null) { - result0 = [result0, result1, result2, result3, result4, result5]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var header; - - try { - data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers); - delete data.scheme; - delete data.user; - delete data.host; - delete data.host_type; - delete data.port; - delete data.uri_params; - - if (startRule === 'SIP_URI') { - data = data.uri; - } - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_uri_scheme() { - var result0; - result0 = parse_uri_scheme_sips(); - - if (result0 === null) { - result0 = parse_uri_scheme_sip(); - } - - return result0; - } - - function parse_uri_scheme_sips() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 4).toLowerCase() === "sips") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"sips\""); - } - } - - if (result0 !== null) { - result0 = function (offset, scheme) { - data.scheme = scheme.toLowerCase(); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_uri_scheme_sip() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 3).toLowerCase() === "sip") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"sip\""); - } - } - - if (result0 !== null) { - result0 = function (offset, scheme) { - data.scheme = scheme.toLowerCase(); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_userinfo() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_user(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_password(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - if (input.charCodeAt(pos) === 64) { - result2 = "@"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.user = decodeURIComponent(input.substring(pos - 1, offset)); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_user() { - var result0, result1; - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - result1 = parse_user_unreserved(); - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - result1 = parse_user_unreserved(); - } - } - } - } else { - result0 = null; - } - - return result0; - } - - function parse_user_unreserved() { - var result0; - - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 59) { - result0 = ";"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_password() { - var result0, result1; - var pos0; - pos0 = pos; - result0 = []; - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 38) { - result1 = "&"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 36) { - result1 = "$"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 38) { - result1 = "&"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 36) { - result1 = "$"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.password = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_hostport() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - result0 = parse_host(); - - if (result0 !== null) { - pos1 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_port(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos1; - } - } else { - result1 = null; - pos = pos1; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_host() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_hostname(); - - if (result0 === null) { - result0 = parse_IPv4address(); - - if (result0 === null) { - result0 = parse_IPv6reference(); - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.host = input.substring(pos, offset).toLowerCase(); - return data.host; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_hostname() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = []; - pos2 = pos; - result1 = parse_domainlabel(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - while (result1 !== null) { - result0.push(result1); - pos2 = pos; - result1 = parse_domainlabel(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - } - - if (result0 !== null) { - result1 = parse_toplabel(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.host_type = 'domain'; - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_domainlabel() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_alphanum(); - - if (result0 !== null) { - result1 = []; - result2 = parse_alphanum(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - } - } - - while (result2 !== null) { - result1.push(result2); - result2 = parse_alphanum(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_toplabel() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_ALPHA(); - - if (result0 !== null) { - result1 = []; - result2 = parse_alphanum(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - } - } - - while (result2 !== null) { - result1.push(result2); - result2 = parse_alphanum(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 95) { - result2 = "_"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"_\""); - } - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_IPv6reference() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.charCodeAt(pos) === 91) { - result0 = "["; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result0 !== null) { - result1 = parse_IPv6address(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 93) { - result2 = "]"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.host_type = 'IPv6'; - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_IPv6address() { - var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - if (input.charCodeAt(pos) === 58) { - result7 = ":"; - pos++; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result7 !== null) { - result8 = parse_h16(); - - if (result8 !== null) { - if (input.charCodeAt(pos) === 58) { - result9 = ":"; - pos++; - } else { - result9 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result9 !== null) { - result10 = parse_h16(); - - if (result10 !== null) { - if (input.charCodeAt(pos) === 58) { - result11 = ":"; - pos++; - } else { - result11 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result11 !== null) { - result12 = parse_ls32(); - - if (result12 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - if (input.charCodeAt(pos) === 58) { - result8 = ":"; - pos++; - } else { - result8 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result8 !== null) { - result9 = parse_h16(); - - if (result9 !== null) { - if (input.charCodeAt(pos) === 58) { - result10 = ":"; - pos++; - } else { - result10 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result10 !== null) { - result11 = parse_ls32(); - - if (result11 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - if (input.charCodeAt(pos) === 58) { - result8 = ":"; - pos++; - } else { - result8 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result8 !== null) { - result9 = parse_ls32(); - - if (result9 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_ls32(); - - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_ls32(); - - if (result5 !== null) { - result0 = [result0, result1, result2, result3, result4, result5]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_ls32(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_ls32(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - - if (input.substr(pos, 2) === "::") { - result0 = "::"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result0 !== null) { - result1 = parse_h16(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - if (input.substr(pos, 2) === "::") { - result1 = "::"; - pos += 2; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - if (input.charCodeAt(pos) === 58) { - result7 = ":"; - pos++; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result7 !== null) { - result8 = parse_h16(); - - if (result8 !== null) { - if (input.charCodeAt(pos) === 58) { - result9 = ":"; - pos++; - } else { - result9 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result9 !== null) { - result10 = parse_ls32(); - - if (result10 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - if (input.substr(pos, 2) === "::") { - result2 = "::"; - pos += 2; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - if (input.charCodeAt(pos) === 58) { - result8 = ":"; - pos++; - } else { - result8 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result8 !== null) { - result9 = parse_ls32(); - - if (result9 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - if (input.substr(pos, 2) === "::") { - result3 = "::"; - pos += 2; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - if (input.charCodeAt(pos) === 58) { - result7 = ":"; - pos++; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result7 !== null) { - result8 = parse_ls32(); - - if (result8 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } - - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - if (input.substr(pos, 2) === "::") { - result4 = "::"; - pos += 2; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_ls32(); - - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } - - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos2; - } - } else { - result4 = null; - pos = pos2; - } - - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - if (input.substr(pos, 2) === "::") { - result5 = "::"; - pos += 2; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result5 !== null) { - result6 = parse_ls32(); - - if (result6 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } - - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos2; - } - } else { - result4 = null; - pos = pos2; - } - - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - - result5 = result5 !== null ? result5 : ""; - - if (result5 !== null) { - if (input.substr(pos, 2) === "::") { - result6 = "::"; - pos += 2; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - pos1 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result2 = ":"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result2 !== null) { - result3 = parse_h16(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result3 = ":"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result3 !== null) { - result4 = parse_h16(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos2; - } - } else { - result3 = null; - pos = pos2; - } - - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result4 = ":"; - pos++; - } else { - result4 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result4 !== null) { - result5 = parse_h16(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos2; - } - } else { - result4 = null; - pos = pos2; - } - - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result5 = ":"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result5 !== null) { - result6 = parse_h16(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - - result5 = result5 !== null ? result5 : ""; - - if (result5 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 58) { - result6 = ":"; - pos++; - } else { - result6 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result6 !== null) { - result7 = parse_h16(); - - if (result7 !== null) { - result6 = [result6, result7]; - } else { - result6 = null; - pos = pos2; - } - } else { - result6 = null; - pos = pos2; - } - - result6 = result6 !== null ? result6 : ""; - - if (result6 !== null) { - if (input.substr(pos, 2) === "::") { - result7 = "::"; - pos += 2; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\"::\""); - } - } - - if (result7 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.host_type = 'IPv6'; - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_h16() { - var result0, result1, result2, result3; - var pos0; - pos0 = pos; - result0 = parse_HEXDIG(); - - if (result0 !== null) { - result1 = parse_HEXDIG(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_HEXDIG(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_HEXDIG(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_ls32() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_h16(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_h16(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - result0 = parse_IPv4address(); - } - - return result0; - } - - function parse_IPv4address() { - var result0, result1, result2, result3, result4, result5, result6; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_dec_octet(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 !== null) { - result2 = parse_dec_octet(); - - if (result2 !== null) { - if (input.charCodeAt(pos) === 46) { - result3 = "."; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result3 !== null) { - result4 = parse_dec_octet(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 46) { - result5 = "."; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result5 !== null) { - result6 = parse_dec_octet(); - - if (result6 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.host_type = 'IPv4'; - return input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_dec_octet() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 2) === "25") { - result0 = "25"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"25\""); - } - } - - if (result0 !== null) { - if (/^[0-5]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[0-5]"); - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - - if (input.charCodeAt(pos) === 50) { - result0 = "2"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"2\""); - } - } - - if (result0 !== null) { - if (/^[0-4]/.test(input.charAt(pos))) { - result1 = input.charAt(pos); - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("[0-4]"); - } - } - - if (result1 !== null) { - result2 = parse_DIGIT(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - - if (input.charCodeAt(pos) === 49) { - result0 = "1"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"1\""); - } - } - - if (result0 !== null) { - result1 = parse_DIGIT(); - - if (result1 !== null) { - result2 = parse_DIGIT(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - - if (/^[1-9]/.test(input.charAt(pos))) { - result0 = input.charAt(pos); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("[1-9]"); - } - } - - if (result0 !== null) { - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - result0 = parse_DIGIT(); - } - } - } - } - - return result0; - } - - function parse_port() { - var result0, result1, result2, result3, result4; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DIGIT(); - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_DIGIT(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_DIGIT(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result4 = parse_DIGIT(); - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, port) { - port = parseInt(port.join('')); - data.port = port; - return port; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_uri_parameters() { - var result0, result1, result2; - var pos0; - result0 = []; - pos0 = pos; - - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 !== null) { - result2 = parse_uri_parameter(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos0; - } - } else { - result1 = null; - pos = pos0; - } - - while (result1 !== null) { - result0.push(result1); - pos0 = pos; - - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 !== null) { - result2 = parse_uri_parameter(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos0; - } - } else { - result1 = null; - pos = pos0; - } - } - - return result0; - } - - function parse_uri_parameter() { - var result0; - result0 = parse_transport_param(); - - if (result0 === null) { - result0 = parse_user_param(); - - if (result0 === null) { - result0 = parse_method_param(); - - if (result0 === null) { - result0 = parse_ttl_param(); - - if (result0 === null) { - result0 = parse_maddr_param(); - - if (result0 === null) { - result0 = parse_lr_param(); - - if (result0 === null) { - result0 = parse_other_param(); - } - } - } - } - } - } - - return result0; - } - - function parse_transport_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 10).toLowerCase() === "transport=") { - result0 = input.substr(pos, 10); - pos += 10; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"transport=\""); - } - } - - if (result0 !== null) { - if (input.substr(pos, 3).toLowerCase() === "udp") { - result1 = input.substr(pos, 3); - pos += 3; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"udp\""); - } - } - - if (result1 === null) { - if (input.substr(pos, 3).toLowerCase() === "tcp") { - result1 = input.substr(pos, 3); - pos += 3; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"tcp\""); - } - } - - if (result1 === null) { - if (input.substr(pos, 4).toLowerCase() === "sctp") { - result1 = input.substr(pos, 4); - pos += 4; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"sctp\""); - } - } - - if (result1 === null) { - if (input.substr(pos, 3).toLowerCase() === "tls") { - result1 = input.substr(pos, 3); - pos += 3; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"tls\""); - } - } - - if (result1 === null) { - result1 = parse_token(); - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, transport) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['transport'] = transport.toLowerCase(); - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_user_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 5).toLowerCase() === "user=") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"user=\""); - } - } - - if (result0 !== null) { - if (input.substr(pos, 5).toLowerCase() === "phone") { - result1 = input.substr(pos, 5); - pos += 5; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"phone\""); - } - } - - if (result1 === null) { - if (input.substr(pos, 2).toLowerCase() === "ip") { - result1 = input.substr(pos, 2); - pos += 2; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"ip\""); - } - } - - if (result1 === null) { - result1 = parse_token(); - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, user) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['user'] = user.toLowerCase(); - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_method_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 7).toLowerCase() === "method=") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"method=\""); - } - } - - if (result0 !== null) { - result1 = parse_Method(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, method) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['method'] = method; - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_ttl_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 4).toLowerCase() === "ttl=") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"ttl=\""); - } - } - - if (result0 !== null) { - result1 = parse_ttl(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, ttl) { - if (!data.params) data.params = {}; - data.params['ttl'] = ttl; - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_maddr_param() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6).toLowerCase() === "maddr=") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"maddr=\""); - } - } - - if (result0 !== null) { - result1 = parse_host(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, maddr) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['maddr'] = maddr; - }(pos0, result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_lr_param() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 2).toLowerCase() === "lr") { - result0 = input.substr(pos, 2); - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"lr\""); - } - } - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - if (!data.uri_params) data.uri_params = {}; - data.uri_params['lr'] = undefined; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_other_param() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_pname(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 !== null) { - result2 = parse_pvalue(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, param, value) { - if (!data.uri_params) data.uri_params = {}; - - if (typeof value === 'undefined') { - value = undefined; - } else { - value = value[1]; - } - - data.uri_params[param.toLowerCase()] = value; - }(pos0, result0[0], result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_pname() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_paramchar(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_paramchar(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, pname) { - return pname.join(''); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_pvalue() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_paramchar(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_paramchar(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, pvalue) { - return pvalue.join(''); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_paramchar() { - var result0; - result0 = parse_param_unreserved(); - - if (result0 === null) { - result0 = parse_unreserved(); - - if (result0 === null) { - result0 = parse_escaped(); - } - } - - return result0; - } - - function parse_param_unreserved() { - var result0; - - if (input.charCodeAt(pos) === 91) { - result0 = "["; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 93) { - result0 = "]"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_headers() { - var result0, result1, result2, result3, result4; - var pos0, pos1; - pos0 = pos; - - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 !== null) { - result1 = parse_header(); - - if (result1 !== null) { - result2 = []; - pos1 = pos; - - if (input.charCodeAt(pos) === 38) { - result3 = "&"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result3 !== null) { - result4 = parse_header(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos1; - } - } else { - result3 = null; - pos = pos1; - } - - while (result3 !== null) { - result2.push(result3); - pos1 = pos; - - if (input.charCodeAt(pos) === 38) { - result3 = "&"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result3 !== null) { - result4 = parse_header(); - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos1; - } - } else { - result3 = null; - pos = pos1; - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_header() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_hname(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 !== null) { - result2 = parse_hvalue(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, hname, hvalue) { - hname = hname.join('').toLowerCase(); - hvalue = hvalue.join(''); - if (!data.uri_headers) data.uri_headers = {}; - - if (!data.uri_headers[hname]) { - data.uri_headers[hname] = [hvalue]; - } else { - data.uri_headers[hname].push(hvalue); - } - }(pos0, result0[0], result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_hname() { - var result0, result1; - result1 = parse_hnv_unreserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_hnv_unreserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - } - } - } - } else { - result0 = null; - } - - return result0; - } - - function parse_hvalue() { - var result0, result1; - result0 = []; - result1 = parse_hnv_unreserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - } - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_hnv_unreserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - } - } - } - - return result0; - } - - function parse_hnv_unreserved() { - var result0; - - if (input.charCodeAt(pos) === 91) { - result0 = "["; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"[\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 93) { - result0 = "]"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"]\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_Request_Response() { - var result0; - result0 = parse_Status_Line(); - - if (result0 === null) { - result0 = parse_Request_Line(); - } - - return result0; - } - - function parse_Request_Line() { - var result0, result1, result2, result3, result4; - var pos0; - pos0 = pos; - result0 = parse_Method(); - - if (result0 !== null) { - result1 = parse_SP(); - - if (result1 !== null) { - result2 = parse_Request_URI(); - - if (result2 !== null) { - result3 = parse_SP(); - - if (result3 !== null) { - result4 = parse_SIP_Version(); - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Request_URI() { - var result0; - result0 = parse_SIP_URI(); - - if (result0 === null) { - result0 = parse_absoluteURI(); - } - - return result0; - } - - function parse_absoluteURI() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_scheme(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 !== null) { - result2 = parse_hier_part(); - - if (result2 === null) { - result2 = parse_opaque_part(); - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_hier_part() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - result0 = parse_net_path(); - - if (result0 === null) { - result0 = parse_abs_path(); - } - - if (result0 !== null) { - pos1 = pos; - - if (input.charCodeAt(pos) === 63) { - result1 = "?"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result1 !== null) { - result2 = parse_query(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos1; - } - } else { - result1 = null; - pos = pos1; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_net_path() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 2) === "//") { - result0 = "//"; - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"//\""); - } - } - - if (result0 !== null) { - result1 = parse_authority(); - - if (result1 !== null) { - result2 = parse_abs_path(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_abs_path() { - var result0, result1; - var pos0; - pos0 = pos; - - if (input.charCodeAt(pos) === 47) { - result0 = "/"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result0 !== null) { - result1 = parse_path_segments(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_opaque_part() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_uric_no_slash(); - - if (result0 !== null) { - result1 = []; - result2 = parse_uric(); - - while (result2 !== null) { - result1.push(result2); - result2 = parse_uric(); - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_uric() { - var result0; - result0 = parse_reserved(); - - if (result0 === null) { - result0 = parse_unreserved(); - - if (result0 === null) { - result0 = parse_escaped(); - } - } - - return result0; - } - - function parse_uric_no_slash() { - var result0; - result0 = parse_unreserved(); - - if (result0 === null) { - result0 = parse_escaped(); - - if (result0 === null) { - if (input.charCodeAt(pos) === 59) { - result0 = ";"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 63) { - result0 = "?"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"?\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 64) { - result0 = "@"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_path_segments() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_segment(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - - if (input.charCodeAt(pos) === 47) { - result2 = "/"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result2 !== null) { - result3 = parse_segment(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - - if (input.charCodeAt(pos) === 47) { - result2 = "/"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result2 !== null) { - result3 = parse_segment(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_segment() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = []; - result1 = parse_pchar(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_pchar(); - } - - if (result0 !== null) { - result1 = []; - pos1 = pos; - - if (input.charCodeAt(pos) === 59) { - result2 = ";"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result2 !== null) { - result3 = parse_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - - if (input.charCodeAt(pos) === 59) { - result2 = ";"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result2 !== null) { - result3 = parse_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_param() { - var result0, result1; - result0 = []; - result1 = parse_pchar(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_pchar(); - } - - return result0; - } - - function parse_pchar() { - var result0; - result0 = parse_unreserved(); - - if (result0 === null) { - result0 = parse_escaped(); - - if (result0 === null) { - if (input.charCodeAt(pos) === 58) { - result0 = ":"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 64) { - result0 = "@"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 38) { - result0 = "&"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 61) { - result0 = "="; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 43) { - result0 = "+"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 36) { - result0 = "$"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result0 === null) { - if (input.charCodeAt(pos) === 44) { - result0 = ","; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - } - } - } - } - } - } - } - } - - return result0; - } - - function parse_scheme() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_ALPHA(); - - if (result0 !== null) { - result1 = []; - result2 = parse_ALPHA(); - - if (result2 === null) { - result2 = parse_DIGIT(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 43) { - result2 = "+"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - } - } - } - } - - while (result2 !== null) { - result1.push(result2); - result2 = parse_ALPHA(); - - if (result2 === null) { - result2 = parse_DIGIT(); - - if (result2 === null) { - if (input.charCodeAt(pos) === 43) { - result2 = "+"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 45) { - result2 = "-"; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result2 === null) { - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.scheme = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_authority() { - var result0; - result0 = parse_srvr(); - - if (result0 === null) { - result0 = parse_reg_name(); - } - - return result0; - } - - function parse_srvr() { - var result0, result1; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_userinfo(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_hostport(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - result0 = result0 !== null ? result0 : ""; - return result0; - } - - function parse_reg_name() { - var result0, result1; - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 36) { - result1 = "$"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 38) { - result1 = "&"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - } - } - } - } - } - } - } - } - } - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - if (input.charCodeAt(pos) === 36) { - result1 = "$"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 44) { - result1 = ","; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 59) { - result1 = ";"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\";\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 58) { - result1 = ":"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\":\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 38) { - result1 = "&"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"&\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 61) { - result1 = "="; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"=\""); - } - } - - if (result1 === null) { - if (input.charCodeAt(pos) === 43) { - result1 = "+"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"+\""); - } - } - } - } - } - } - } - } - } - } - } - } - } else { - result0 = null; - } - - return result0; - } - - function parse_query() { - var result0, result1; - result0 = []; - result1 = parse_uric(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_uric(); - } - - return result0; - } - - function parse_SIP_Version() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 3).toLowerCase() === "sip") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SIP\""); - } - } - - if (result0 !== null) { - if (input.charCodeAt(pos) === 47) { - result1 = "/"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"/\""); - } - } - - if (result1 !== null) { - result3 = parse_DIGIT(); - - if (result3 !== null) { - result2 = []; - - while (result3 !== null) { - result2.push(result3); - result3 = parse_DIGIT(); - } - } else { - result2 = null; - } - - if (result2 !== null) { - if (input.charCodeAt(pos) === 46) { - result3 = "."; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result3 !== null) { - result5 = parse_DIGIT(); - - if (result5 !== null) { - result4 = []; - - while (result5 !== null) { - result4.push(result5); - result5 = parse_DIGIT(); - } - } else { - result4 = null; - } - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.sip_version = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_INVITEm() { - var result0; - - if (input.substr(pos, 6) === "INVITE") { - result0 = "INVITE"; - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"INVITE\""); - } - } - - return result0; - } - - function parse_ACKm() { - var result0; - - if (input.substr(pos, 3) === "ACK") { - result0 = "ACK"; - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"ACK\""); - } - } - - return result0; - } - - function parse_OPTIONSm() { - var result0; - - if (input.substr(pos, 7) === "OPTIONS") { - result0 = "OPTIONS"; - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"OPTIONS\""); - } - } - - return result0; - } - - function parse_BYEm() { - var result0; - - if (input.substr(pos, 3) === "BYE") { - result0 = "BYE"; - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"BYE\""); - } - } - - return result0; - } - - function parse_CANCELm() { - var result0; - - if (input.substr(pos, 6) === "CANCEL") { - result0 = "CANCEL"; - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"CANCEL\""); - } - } - - return result0; - } - - function parse_REGISTERm() { - var result0; - - if (input.substr(pos, 8) === "REGISTER") { - result0 = "REGISTER"; - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"REGISTER\""); - } - } - - return result0; - } - - function parse_SUBSCRIBEm() { - var result0; - - if (input.substr(pos, 9) === "SUBSCRIBE") { - result0 = "SUBSCRIBE"; - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SUBSCRIBE\""); - } - } - - return result0; - } - - function parse_NOTIFYm() { - var result0; - - if (input.substr(pos, 6) === "NOTIFY") { - result0 = "NOTIFY"; - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"NOTIFY\""); - } - } - - return result0; - } - - function parse_REFERm() { - var result0; - - if (input.substr(pos, 5) === "REFER") { - result0 = "REFER"; - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"REFER\""); - } - } - - return result0; - } - - function parse_Method() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_INVITEm(); - - if (result0 === null) { - result0 = parse_ACKm(); - - if (result0 === null) { - result0 = parse_OPTIONSm(); - - if (result0 === null) { - result0 = parse_BYEm(); - - if (result0 === null) { - result0 = parse_CANCELm(); - - if (result0 === null) { - result0 = parse_REGISTERm(); - - if (result0 === null) { - result0 = parse_SUBSCRIBEm(); - - if (result0 === null) { - result0 = parse_NOTIFYm(); - - if (result0 === null) { - result0 = parse_REFERm(); - - if (result0 === null) { - result0 = parse_token(); - } - } - } - } - } - } - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.method = input.substring(pos, offset); - return data.method; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Status_Line() { - var result0, result1, result2, result3, result4; - var pos0; - pos0 = pos; - result0 = parse_SIP_Version(); - - if (result0 !== null) { - result1 = parse_SP(); - - if (result1 !== null) { - result2 = parse_Status_Code(); - - if (result2 !== null) { - result3 = parse_SP(); - - if (result3 !== null) { - result4 = parse_Reason_Phrase(); - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Status_Code() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_extension_code(); - - if (result0 !== null) { - result0 = function (offset, status_code) { - data.status_code = parseInt(status_code.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_extension_code() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_DIGIT(); - - if (result0 !== null) { - result1 = parse_DIGIT(); - - if (result1 !== null) { - result2 = parse_DIGIT(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Reason_Phrase() { - var result0, result1; - var pos0; - pos0 = pos; - result0 = []; - result1 = parse_reserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - result1 = parse_UTF8_NONASCII(); - - if (result1 === null) { - result1 = parse_UTF8_CONT(); - - if (result1 === null) { - result1 = parse_SP(); - - if (result1 === null) { - result1 = parse_HTAB(); - } - } - } - } - } - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_reserved(); - - if (result1 === null) { - result1 = parse_unreserved(); - - if (result1 === null) { - result1 = parse_escaped(); - - if (result1 === null) { - result1 = parse_UTF8_NONASCII(); - - if (result1 === null) { - result1 = parse_UTF8_CONT(); - - if (result1 === null) { - result1 = parse_SP(); - - if (result1 === null) { - result1 = parse_HTAB(); - } - } - } - } - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.reason_phrase = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Allow_Events() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_event_type(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_event_type(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_event_type(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Call_ID() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_word(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 !== null) { - result2 = parse_word(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Contact() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - result0 = parse_STAR(); - - if (result0 === null) { - pos1 = pos; - result0 = parse_contact_param(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_contact_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_contact_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } - - if (result0 !== null) { - result0 = function (offset) { - var idx, length; - length = data.multi_header.length; - - for (idx = 0; idx < length; idx++) { - if (data.multi_header[idx].parsed === null) { - data = null; - break; - } - } - - if (data !== null) { - data = data.multi_header; - } else { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_contact_param() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_SIP_URI_noparams(); - - if (result0 === null) { - result0 = parse_name_addr(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_contact_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_contact_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var header; - if (!data.multi_header) data.multi_header = []; - - try { - header = new NameAddrHeader(data.uri, data.display_name, data.params); - delete data.uri; - delete data.display_name; - delete data.params; - } catch (e) { - header = null; - } - - data.multi_header.push({ - 'possition': pos, - 'offset': offset, - 'parsed': header - }); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_name_addr() { - var result0, result1, result2, result3; - var pos0; - pos0 = pos; - result0 = parse_display_name(); - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_LAQUOT(); - - if (result1 !== null) { - result2 = parse_SIP_URI(); - - if (result2 !== null) { - result3 = parse_RAQUOT(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_display_name() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_LWS(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_LWS(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 === null) { - result0 = parse_quoted_string_clean(); - } - - if (result0 !== null) { - result0 = function (offset, display_name) { - if (typeof display_name === 'string') { - // quoted_string_clean - data.display_name = display_name; - } else { - // token ( LWS token )* - data.display_name = display_name[1].reduce(function (acc, cur) { - return acc + cur[0] + cur[1]; - }, display_name[0]); - } - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_contact_params() { - var result0; - result0 = parse_c_p_q(); - - if (result0 === null) { - result0 = parse_c_p_expires(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - } - - return result0; - } - - function parse_c_p_q() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 1).toLowerCase() === "q") { - result0 = input.substr(pos, 1); - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"q\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_qvalue(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, q) { - if (!data.params) data.params = {}; - data.params['q'] = q; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_c_p_expires() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 7).toLowerCase() === "expires") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"expires\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_delta_seconds(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, expires) { - if (!data.params) data.params = {}; - data.params['expires'] = expires; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_delta_seconds() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_DIGIT(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, delta_seconds) { - return parseInt(delta_seconds.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_qvalue() { - var result0, result1, result2, result3, result4; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - - if (input.charCodeAt(pos) === 48) { - result0 = "0"; - pos++; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"0\""); - } - } - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 46) { - result1 = "."; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_DIGIT(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result4 = parse_DIGIT(); - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - result1 = [result1, result2, result3, result4]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - return parseFloat(input.substring(pos, offset)); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_generic_param() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_token(); - - if (result0 !== null) { - pos2 = pos; - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_gen_value(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, param, value) { - if (!data.params) data.params = {}; - - if (typeof value === 'undefined') { - value = undefined; - } else { - value = value[1]; - } - - data.params[param.toLowerCase()] = value; - }(pos0, result0[0], result0[1]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_gen_value() { - var result0; - result0 = parse_token(); - - if (result0 === null) { - result0 = parse_host(); - - if (result0 === null) { - result0 = parse_quoted_string(); - } - } - - return result0; - } - - function parse_Content_Disposition() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_disp_type(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_disp_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_disp_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_disp_type() { - var result0; - - if (input.substr(pos, 6).toLowerCase() === "render") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"render\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 7).toLowerCase() === "session") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"session\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 4).toLowerCase() === "icon") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"icon\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 5).toLowerCase() === "alert") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"alert\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - } - } - - return result0; - } - - function parse_disp_param() { - var result0; - result0 = parse_handling_param(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_handling_param() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 8).toLowerCase() === "handling") { - result0 = input.substr(pos, 8); - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"handling\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - if (input.substr(pos, 8).toLowerCase() === "optional") { - result2 = input.substr(pos, 8); - pos += 8; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"optional\""); - } - } - - if (result2 === null) { - if (input.substr(pos, 8).toLowerCase() === "required") { - result2 = input.substr(pos, 8); - pos += 8; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"required\""); - } - } - - if (result2 === null) { - result2 = parse_token(); - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Content_Encoding() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Content_Length() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_DIGIT(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, length) { - data = parseInt(length.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Content_Type() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_media_type(); - - if (result0 !== null) { - result0 = function (offset) { - data = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_media_type() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - result0 = parse_m_type(); - - if (result0 !== null) { - result1 = parse_SLASH(); - - if (result1 !== null) { - result2 = parse_m_subtype(); - - if (result2 !== null) { - result3 = []; - pos1 = pos; - result4 = parse_SEMI(); - - if (result4 !== null) { - result5 = parse_m_parameter(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - - while (result4 !== null) { - result3.push(result4); - pos1 = pos; - result4 = parse_SEMI(); - - if (result4 !== null) { - result5 = parse_m_parameter(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - } - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_m_type() { - var result0; - result0 = parse_discrete_type(); - - if (result0 === null) { - result0 = parse_composite_type(); - } - - return result0; - } - - function parse_discrete_type() { - var result0; - - if (input.substr(pos, 4).toLowerCase() === "text") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"text\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 5).toLowerCase() === "image") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"image\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 5).toLowerCase() === "audio") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"audio\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 5).toLowerCase() === "video") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"video\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 11).toLowerCase() === "application") { - result0 = input.substr(pos, 11); - pos += 11; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"application\""); - } - } - - if (result0 === null) { - result0 = parse_extension_token(); - } - } - } - } - } - - return result0; - } - - function parse_composite_type() { - var result0; - - if (input.substr(pos, 7).toLowerCase() === "message") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"message\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 9).toLowerCase() === "multipart") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"multipart\""); - } - } - - if (result0 === null) { - result0 = parse_extension_token(); - } - } - - return result0; - } - - function parse_extension_token() { - var result0; - result0 = parse_token(); - - if (result0 === null) { - result0 = parse_x_token(); - } - - return result0; - } - - function parse_x_token() { - var result0, result1; - var pos0; - pos0 = pos; - - if (input.substr(pos, 2).toLowerCase() === "x-") { - result0 = input.substr(pos, 2); - pos += 2; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"x-\""); - } - } - - if (result0 !== null) { - result1 = parse_token(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_m_subtype() { - var result0; - result0 = parse_extension_token(); - - if (result0 === null) { - result0 = parse_token(); - } - - return result0; - } - - function parse_m_parameter() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_m_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_m_value() { - var result0; - result0 = parse_token(); - - if (result0 === null) { - result0 = parse_quoted_string(); - } - - return result0; - } - - function parse_CSeq() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_CSeq_value(); - - if (result0 !== null) { - result1 = parse_LWS(); - - if (result1 !== null) { - result2 = parse_Method(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_CSeq_value() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_DIGIT(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, cseq_value) { - data.value = parseInt(cseq_value.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Expires() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_delta_seconds(); - - if (result0 !== null) { - result0 = function (offset, expires) { - data = expires; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Event() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_event_type(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, event_type) { - data.event = event_type.join('').toLowerCase(); - }(pos0, result0[0]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_event_type() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token_nodot(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result2 !== null) { - result3 = parse_token_nodot(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - - if (input.charCodeAt(pos) === 46) { - result2 = "."; - pos++; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\".\""); - } - } - - if (result2 !== null) { - result3 = parse_token_nodot(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_From() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_SIP_URI_noparams(); - - if (result0 === null) { - result0 = parse_name_addr(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_from_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_from_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var tag = data.tag; - - try { - data = new NameAddrHeader(data.uri, data.display_name, data.params); - - if (tag) { - data.setParam('tag', tag); - } - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_from_param() { - var result0; - result0 = parse_tag_param(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_tag_param() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 3).toLowerCase() === "tag") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"tag\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, tag) { - data.tag = tag; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Max_Forwards() { - var result0, result1; - var pos0; - pos0 = pos; - result1 = parse_DIGIT(); - - if (result1 !== null) { - result0 = []; - - while (result1 !== null) { - result0.push(result1); - result1 = parse_DIGIT(); - } - } else { - result0 = null; - } - - if (result0 !== null) { - result0 = function (offset, forwards) { - data = parseInt(forwards.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Min_Expires() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_delta_seconds(); - - if (result0 !== null) { - result0 = function (offset, min_expires) { - data = min_expires; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Name_Addr_Header() { - var result0, result1, result2, result3, result4, result5, result6; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = []; - result1 = parse_display_name(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_display_name(); - } - - if (result0 !== null) { - result1 = parse_LAQUOT(); - - if (result1 !== null) { - result2 = parse_SIP_URI(); - - if (result2 !== null) { - result3 = parse_RAQUOT(); - - if (result3 !== null) { - result4 = []; - pos2 = pos; - result5 = parse_SEMI(); - - if (result5 !== null) { - result6 = parse_generic_param(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - - while (result5 !== null) { - result4.push(result5); - pos2 = pos; - result5 = parse_SEMI(); - - if (result5 !== null) { - result6 = parse_generic_param(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - } - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - try { - data = new NameAddrHeader(data.uri, data.display_name, data.params); - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Proxy_Authenticate() { - var result0; - result0 = parse_challenge(); - return result0; - } - - function parse_challenge() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - - if (input.substr(pos, 6).toLowerCase() === "digest") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"Digest\""); - } - } - - if (result0 !== null) { - result1 = parse_LWS(); - - if (result1 !== null) { - result2 = parse_digest_cln(); - - if (result2 !== null) { - result3 = []; - pos1 = pos; - result4 = parse_COMMA(); - - if (result4 !== null) { - result5 = parse_digest_cln(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - - while (result4 !== null) { - result3.push(result4); - pos1 = pos; - result4 = parse_COMMA(); - - if (result4 !== null) { - result5 = parse_digest_cln(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - } - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - if (result0 === null) { - result0 = parse_other_challenge(); - } - - return result0; - } - - function parse_other_challenge() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = parse_LWS(); - - if (result1 !== null) { - result2 = parse_auth_param(); - - if (result2 !== null) { - result3 = []; - pos1 = pos; - result4 = parse_COMMA(); - - if (result4 !== null) { - result5 = parse_auth_param(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - - while (result4 !== null) { - result3.push(result4); - pos1 = pos; - result4 = parse_COMMA(); - - if (result4 !== null) { - result5 = parse_auth_param(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - } - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_auth_param() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 === null) { - result2 = parse_quoted_string(); - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_digest_cln() { - var result0; - result0 = parse_realm(); - - if (result0 === null) { - result0 = parse_domain(); - - if (result0 === null) { - result0 = parse_nonce(); - - if (result0 === null) { - result0 = parse_opaque(); - - if (result0 === null) { - result0 = parse_stale(); - - if (result0 === null) { - result0 = parse_algorithm(); - - if (result0 === null) { - result0 = parse_qop_options(); - - if (result0 === null) { - result0 = parse_auth_param(); - } - } - } - } - } - } - } - - return result0; - } - - function parse_realm() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 5).toLowerCase() === "realm") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"realm\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_realm_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_realm_value() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_quoted_string_clean(); - - if (result0 !== null) { - result0 = function (offset, realm) { - data.realm = realm; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_domain() { - var result0, result1, result2, result3, result4, result5, result6; - var pos0, pos1; - pos0 = pos; - - if (input.substr(pos, 6).toLowerCase() === "domain") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"domain\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_LDQUOT(); - - if (result2 !== null) { - result3 = parse_URI(); - - if (result3 !== null) { - result4 = []; - pos1 = pos; - result6 = parse_SP(); - - if (result6 !== null) { - result5 = []; - - while (result6 !== null) { - result5.push(result6); - result6 = parse_SP(); - } - } else { - result5 = null; - } - - if (result5 !== null) { - result6 = parse_URI(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos1; - } - } else { - result5 = null; - pos = pos1; - } - - while (result5 !== null) { - result4.push(result5); - pos1 = pos; - result6 = parse_SP(); - - if (result6 !== null) { - result5 = []; - - while (result6 !== null) { - result5.push(result6); - result6 = parse_SP(); - } - } else { - result5 = null; - } - - if (result5 !== null) { - result6 = parse_URI(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos1; - } - } else { - result5 = null; - pos = pos1; - } - } - - if (result4 !== null) { - result5 = parse_RDQUOT(); - - if (result5 !== null) { - result0 = [result0, result1, result2, result3, result4, result5]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_URI() { - var result0; - result0 = parse_absoluteURI(); - - if (result0 === null) { - result0 = parse_abs_path(); - } - - return result0; - } - - function parse_nonce() { - var result0, result1, result2; - var pos0; - pos0 = pos; - - if (input.substr(pos, 5).toLowerCase() === "nonce") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"nonce\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_nonce_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_nonce_value() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_quoted_string_clean(); - - if (result0 !== null) { - result0 = function (offset, nonce) { - data.nonce = nonce; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_opaque() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6).toLowerCase() === "opaque") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"opaque\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_quoted_string_clean(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, opaque) { - data.opaque = opaque; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_stale() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - - if (input.substr(pos, 5).toLowerCase() === "stale") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"stale\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - pos1 = pos; - - if (input.substr(pos, 4).toLowerCase() === "true") { - result2 = input.substr(pos, 4); - pos += 4; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"true\""); - } - } - - if (result2 !== null) { - result2 = function (offset) { - data.stale = true; - }(pos1); - } - - if (result2 === null) { - pos = pos1; - } - - if (result2 === null) { - pos1 = pos; - - if (input.substr(pos, 5).toLowerCase() === "false") { - result2 = input.substr(pos, 5); - pos += 5; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"false\""); - } - } - - if (result2 !== null) { - result2 = function (offset) { - data.stale = false; - }(pos1); - } - - if (result2 === null) { - pos = pos1; - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_algorithm() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 9).toLowerCase() === "algorithm") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"algorithm\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - if (input.substr(pos, 3).toLowerCase() === "md5") { - result2 = input.substr(pos, 3); - pos += 3; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"MD5\""); - } - } - - if (result2 === null) { - if (input.substr(pos, 8).toLowerCase() === "md5-sess") { - result2 = input.substr(pos, 8); - pos += 8; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"MD5-sess\""); - } - } - - if (result2 === null) { - result2 = parse_token(); - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, algorithm) { - data.algorithm = algorithm.toUpperCase(); - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_qop_options() { - var result0, result1, result2, result3, result4, result5, result6; - var pos0, pos1, pos2; - pos0 = pos; - - if (input.substr(pos, 3).toLowerCase() === "qop") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"qop\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_LDQUOT(); - - if (result2 !== null) { - pos1 = pos; - result3 = parse_qop_value(); - - if (result3 !== null) { - result4 = []; - pos2 = pos; - - if (input.charCodeAt(pos) === 44) { - result5 = ","; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result5 !== null) { - result6 = parse_qop_value(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - - while (result5 !== null) { - result4.push(result5); - pos2 = pos; - - if (input.charCodeAt(pos) === 44) { - result5 = ","; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\",\""); - } - } - - if (result5 !== null) { - result6 = parse_qop_value(); - - if (result6 !== null) { - result5 = [result5, result6]; - } else { - result5 = null; - pos = pos2; - } - } else { - result5 = null; - pos = pos2; - } - } - - if (result4 !== null) { - result3 = [result3, result4]; - } else { - result3 = null; - pos = pos1; - } - } else { - result3 = null; - pos = pos1; - } - - if (result3 !== null) { - result4 = parse_RDQUOT(); - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_qop_value() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 8).toLowerCase() === "auth-int") { - result0 = input.substr(pos, 8); - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"auth-int\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 4).toLowerCase() === "auth") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"auth\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - - if (result0 !== null) { - result0 = function (offset, qop_value) { - data.qop || (data.qop = []); - data.qop.push(qop_value.toLowerCase()); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Proxy_Require() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Record_Route() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_rec_route(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_rec_route(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_rec_route(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var idx, length; - length = data.multi_header.length; - - for (idx = 0; idx < length; idx++) { - if (data.multi_header[idx].parsed === null) { - data = null; - break; - } - } - - if (data !== null) { - data = data.multi_header; - } else { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_rec_route() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_name_addr(); - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var header; - if (!data.multi_header) data.multi_header = []; - - try { - header = new NameAddrHeader(data.uri, data.display_name, data.params); - delete data.uri; - delete data.display_name; - delete data.params; - } catch (e) { - header = null; - } - - data.multi_header.push({ - 'possition': pos, - 'offset': offset, - 'parsed': header - }); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Reason() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 3).toLowerCase() === "sip") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SIP\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_reason_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_reason_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, protocol) { - data.protocol = protocol.toLowerCase(); - if (!data.params) data.params = {}; - - if (data.params.text && data.params.text[0] === '"') { - var text = data.params.text; - data.text = text.substring(1, text.length - 1); - delete data.params.text; - } - }(pos0, result0[0]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_reason_param() { - var result0; - result0 = parse_reason_cause(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_reason_cause() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 5).toLowerCase() === "cause") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"cause\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result3 = parse_DIGIT(); - - if (result3 !== null) { - result2 = []; - - while (result3 !== null) { - result2.push(result3); - result3 = parse_DIGIT(); - } - } else { - result2 = null; - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, cause) { - data.cause = parseInt(cause.join('')); - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Require() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Route() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_route_param(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_route_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_route_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_route_param() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_name_addr(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Subscription_State() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_substate_value(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_subexp_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_subexp_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_substate_value() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 6).toLowerCase() === "active") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"active\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 7).toLowerCase() === "pending") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"pending\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 10).toLowerCase() === "terminated") { - result0 = input.substr(pos, 10); - pos += 10; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"terminated\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.state = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_subexp_params() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6).toLowerCase() === "reason") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"reason\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_event_reason_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, reason) { - if (typeof reason !== 'undefined') data.reason = reason; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 7).toLowerCase() === "expires") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"expires\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_delta_seconds(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, expires) { - if (typeof expires !== 'undefined') data.expires = expires; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - if (result0 === null) { - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 11).toLowerCase() === "retry_after") { - result0 = input.substr(pos, 11); - pos += 11; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"retry_after\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_delta_seconds(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, retry_after) { - if (typeof retry_after !== 'undefined') data.retry_after = retry_after; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - if (result0 === null) { - result0 = parse_generic_param(); - } - } - } - - return result0; - } - - function parse_event_reason_value() { - var result0; - - if (input.substr(pos, 11).toLowerCase() === "deactivated") { - result0 = input.substr(pos, 11); - pos += 11; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"deactivated\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 9).toLowerCase() === "probation") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"probation\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 8).toLowerCase() === "rejected") { - result0 = input.substr(pos, 8); - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"rejected\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 7).toLowerCase() === "timeout") { - result0 = input.substr(pos, 7); - pos += 7; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"timeout\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 6).toLowerCase() === "giveup") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"giveup\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 10).toLowerCase() === "noresource") { - result0 = input.substr(pos, 10); - pos += 10; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"noresource\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 9).toLowerCase() === "invariant") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"invariant\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - } - } - } - } - } - - return result0; - } - - function parse_Subject() { - var result0; - result0 = parse_TEXT_UTF8_TRIM(); - result0 = result0 !== null ? result0 : ""; - return result0; - } - - function parse_Supported() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_token(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - result0 = result0 !== null ? result0 : ""; - return result0; - } - - function parse_To() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_SIP_URI_noparams(); - - if (result0 === null) { - result0 = parse_name_addr(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_to_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_to_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - var tag = data.tag; - - try { - data = new NameAddrHeader(data.uri, data.display_name, data.params); - - if (tag) { - data.setParam('tag', tag); - } - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_to_param() { - var result0; - result0 = parse_tag_param(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_Via() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_via_param(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_via_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_COMMA(); - - if (result2 !== null) { - result3 = parse_via_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_via_param() { - var result0, result1, result2, result3, result4, result5; - var pos0, pos1; - pos0 = pos; - result0 = parse_sent_protocol(); - - if (result0 !== null) { - result1 = parse_LWS(); - - if (result1 !== null) { - result2 = parse_sent_by(); - - if (result2 !== null) { - result3 = []; - pos1 = pos; - result4 = parse_SEMI(); - - if (result4 !== null) { - result5 = parse_via_params(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - - while (result4 !== null) { - result3.push(result4); - pos1 = pos; - result4 = parse_SEMI(); - - if (result4 !== null) { - result5 = parse_via_params(); - - if (result5 !== null) { - result4 = [result4, result5]; - } else { - result4 = null; - pos = pos1; - } - } else { - result4 = null; - pos = pos1; - } - } - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_via_params() { - var result0; - result0 = parse_via_ttl(); - - if (result0 === null) { - result0 = parse_via_maddr(); - - if (result0 === null) { - result0 = parse_via_received(); - - if (result0 === null) { - result0 = parse_via_branch(); - - if (result0 === null) { - result0 = parse_response_port(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - } - } - } - } - - return result0; - } - - function parse_via_ttl() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 3).toLowerCase() === "ttl") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"ttl\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_ttl(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_ttl_value) { - data.ttl = via_ttl_value; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_via_maddr() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 5).toLowerCase() === "maddr") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"maddr\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_host(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_maddr) { - data.maddr = via_maddr; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_via_received() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 8).toLowerCase() === "received") { - result0 = input.substr(pos, 8); - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"received\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_IPv4address(); - - if (result2 === null) { - result2 = parse_IPv6address(); - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_received) { - data.received = via_received; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_via_branch() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6).toLowerCase() === "branch") { - result0 = input.substr(pos, 6); - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"branch\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_branch) { - data.branch = via_branch; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_response_port() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - - if (input.substr(pos, 5).toLowerCase() === "rport") { - result0 = input.substr(pos, 5); - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"rport\""); - } - } - - if (result0 !== null) { - pos1 = pos; - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_rport(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos1; - } - } else { - result1 = null; - pos = pos1; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_rport() { - var result0, result1, result2, result3, result4; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DIGIT(); - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_DIGIT(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_DIGIT(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result4 = parse_DIGIT(); - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, rport) { - data.rport = parseInt(rport.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_sent_protocol() { - var result0, result1, result2, result3, result4; - var pos0; - pos0 = pos; - result0 = parse_protocol_name(); - - if (result0 !== null) { - result1 = parse_SLASH(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result3 = parse_SLASH(); - - if (result3 !== null) { - result4 = parse_transport(); - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_protocol_name() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 3).toLowerCase() === "sip") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SIP\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - - if (result0 !== null) { - result0 = function (offset, via_protocol) { - data.protocol = via_protocol; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_transport() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 3).toLowerCase() === "udp") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"UDP\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 3).toLowerCase() === "tcp") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"TCP\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 3).toLowerCase() === "tls") { - result0 = input.substr(pos, 3); - pos += 3; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"TLS\""); - } - } - - if (result0 === null) { - if (input.substr(pos, 4).toLowerCase() === "sctp") { - result0 = input.substr(pos, 4); - pos += 4; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"SCTP\""); - } - } - - if (result0 === null) { - result0 = parse_token(); - } - } - } - } - - if (result0 !== null) { - result0 = function (offset, via_transport) { - data.transport = via_transport; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_sent_by() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - result0 = parse_via_host(); - - if (result0 !== null) { - pos1 = pos; - result1 = parse_COLON(); - - if (result1 !== null) { - result2 = parse_via_port(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos1; - } - } else { - result1 = null; - pos = pos1; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_via_host() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_IPv4address(); - - if (result0 === null) { - result0 = parse_IPv6reference(); - - if (result0 === null) { - result0 = parse_hostname(); - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.host = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_via_port() { - var result0, result1, result2, result3, result4; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DIGIT(); - result0 = result0 !== null ? result0 : ""; - - if (result0 !== null) { - result1 = parse_DIGIT(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result3 = parse_DIGIT(); - result3 = result3 !== null ? result3 : ""; - - if (result3 !== null) { - result4 = parse_DIGIT(); - result4 = result4 !== null ? result4 : ""; - - if (result4 !== null) { - result0 = [result0, result1, result2, result3, result4]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, via_sent_by_port) { - data.port = parseInt(via_sent_by_port.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_ttl() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_DIGIT(); - - if (result0 !== null) { - result1 = parse_DIGIT(); - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result2 = parse_DIGIT(); - result2 = result2 !== null ? result2 : ""; - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, ttl) { - return parseInt(ttl.join('')); - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_WWW_Authenticate() { - var result0; - result0 = parse_challenge(); - return result0; - } - - function parse_Session_Expires() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_s_e_expires(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_s_e_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_s_e_params(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_s_e_expires() { - var result0; - var pos0; - pos0 = pos; - result0 = parse_delta_seconds(); - - if (result0 !== null) { - result0 = function (offset, expires) { - data.expires = expires; - }(pos0, result0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_s_e_params() { - var result0; - result0 = parse_s_e_refresher(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - - return result0; - } - - function parse_s_e_refresher() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 9).toLowerCase() === "refresher") { - result0 = input.substr(pos, 9); - pos += 9; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"refresher\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - if (input.substr(pos, 3).toLowerCase() === "uac") { - result2 = input.substr(pos, 3); - pos += 3; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"uac\""); - } - } - - if (result2 === null) { - if (input.substr(pos, 3).toLowerCase() === "uas") { - result2 = input.substr(pos, 3); - pos += 3; - } else { - result2 = null; - - if (reportFailures === 0) { - matchFailed("\"uas\""); - } - } - } - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, s_e_refresher_value) { - data.refresher = s_e_refresher_value.toLowerCase(); - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_extension_header() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_token(); - - if (result0 !== null) { - result1 = parse_HCOLON(); - - if (result1 !== null) { - result2 = parse_header_value(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_header_value() { - var result0, result1; - result0 = []; - result1 = parse_TEXT_UTF8char(); - - if (result1 === null) { - result1 = parse_UTF8_CONT(); - - if (result1 === null) { - result1 = parse_LWS(); - } - } - - while (result1 !== null) { - result0.push(result1); - result1 = parse_TEXT_UTF8char(); - - if (result1 === null) { - result1 = parse_UTF8_CONT(); - - if (result1 === null) { - result1 = parse_LWS(); - } - } - } - - return result0; - } - - function parse_message_body() { - var result0, result1; - result0 = []; - result1 = parse_OCTET(); - - while (result1 !== null) { - result0.push(result1); - result1 = parse_OCTET(); - } - - return result0; - } - - function parse_uuid_URI() { - var result0, result1; - var pos0; - pos0 = pos; - - if (input.substr(pos, 5) === "uuid:") { - result0 = "uuid:"; - pos += 5; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"uuid:\""); - } - } - - if (result0 !== null) { - result1 = parse_uuid(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_uuid() { - var result0, result1, result2, result3, result4, result5, result6, result7, result8; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - result0 = parse_hex8(); - - if (result0 !== null) { - if (input.charCodeAt(pos) === 45) { - result1 = "-"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result1 !== null) { - result2 = parse_hex4(); - - if (result2 !== null) { - if (input.charCodeAt(pos) === 45) { - result3 = "-"; - pos++; - } else { - result3 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result3 !== null) { - result4 = parse_hex4(); - - if (result4 !== null) { - if (input.charCodeAt(pos) === 45) { - result5 = "-"; - pos++; - } else { - result5 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result5 !== null) { - result6 = parse_hex4(); - - if (result6 !== null) { - if (input.charCodeAt(pos) === 45) { - result7 = "-"; - pos++; - } else { - result7 = null; - - if (reportFailures === 0) { - matchFailed("\"-\""); - } - } - - if (result7 !== null) { - result8 = parse_hex12(); - - if (result8 !== null) { - result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, uuid) { - data = input.substring(pos + 5, offset); - }(pos0, result0[0]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_hex4() { - var result0, result1, result2, result3; - var pos0; - pos0 = pos; - result0 = parse_HEXDIG(); - - if (result0 !== null) { - result1 = parse_HEXDIG(); - - if (result1 !== null) { - result2 = parse_HEXDIG(); - - if (result2 !== null) { - result3 = parse_HEXDIG(); - - if (result3 !== null) { - result0 = [result0, result1, result2, result3]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_hex8() { - var result0, result1; - var pos0; - pos0 = pos; - result0 = parse_hex4(); - - if (result0 !== null) { - result1 = parse_hex4(); - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_hex12() { - var result0, result1, result2; - var pos0; - pos0 = pos; - result0 = parse_hex4(); - - if (result0 !== null) { - result1 = parse_hex4(); - - if (result1 !== null) { - result2 = parse_hex4(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_Refer_To() { - var result0, result1, result2, result3; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_SIP_URI_noparams(); - - if (result0 === null) { - result0 = parse_name_addr(); - } - - if (result0 !== null) { - result1 = []; - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - - while (result2 !== null) { - result1.push(result2); - pos2 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_generic_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos2; - } - } else { - result2 = null; - pos = pos2; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - try { - data = new NameAddrHeader(data.uri, data.display_name, data.params); - } catch (e) { - data = -1; - } - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_Replaces() { - var result0, result1, result2, result3; - var pos0, pos1; - pos0 = pos; - result0 = parse_call_id(); - - if (result0 !== null) { - result1 = []; - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_replaces_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - - while (result2 !== null) { - result1.push(result2); - pos1 = pos; - result2 = parse_SEMI(); - - if (result2 !== null) { - result3 = parse_replaces_param(); - - if (result3 !== null) { - result2 = [result2, result3]; - } else { - result2 = null; - pos = pos1; - } - } else { - result2 = null; - pos = pos1; - } - } - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos0; - } - } else { - result0 = null; - pos = pos0; - } - - return result0; - } - - function parse_call_id() { - var result0, result1, result2; - var pos0, pos1, pos2; - pos0 = pos; - pos1 = pos; - result0 = parse_word(); - - if (result0 !== null) { - pos2 = pos; - - if (input.charCodeAt(pos) === 64) { - result1 = "@"; - pos++; - } else { - result1 = null; - - if (reportFailures === 0) { - matchFailed("\"@\""); - } - } - - if (result1 !== null) { - result2 = parse_word(); - - if (result2 !== null) { - result1 = [result1, result2]; - } else { - result1 = null; - pos = pos2; - } - } else { - result1 = null; - pos = pos2; - } - - result1 = result1 !== null ? result1 : ""; - - if (result1 !== null) { - result0 = [result0, result1]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset) { - data.call_id = input.substring(pos, offset); - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_replaces_param() { - var result0; - result0 = parse_to_tag(); - - if (result0 === null) { - result0 = parse_from_tag(); - - if (result0 === null) { - result0 = parse_early_flag(); - - if (result0 === null) { - result0 = parse_generic_param(); - } - } - } - - return result0; - } - - function parse_to_tag() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 6) === "to-tag") { - result0 = "to-tag"; - pos += 6; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"to-tag\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, to_tag) { - data.to_tag = to_tag; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_from_tag() { - var result0, result1, result2; - var pos0, pos1; - pos0 = pos; - pos1 = pos; - - if (input.substr(pos, 8) === "from-tag") { - result0 = "from-tag"; - pos += 8; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"from-tag\""); - } - } - - if (result0 !== null) { - result1 = parse_EQUAL(); - - if (result1 !== null) { - result2 = parse_token(); - - if (result2 !== null) { - result0 = [result0, result1, result2]; - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - } else { - result0 = null; - pos = pos1; - } - - if (result0 !== null) { - result0 = function (offset, from_tag) { - data.from_tag = from_tag; - }(pos0, result0[2]); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function parse_early_flag() { - var result0; - var pos0; - pos0 = pos; - - if (input.substr(pos, 10) === "early-only") { - result0 = "early-only"; - pos += 10; - } else { - result0 = null; - - if (reportFailures === 0) { - matchFailed("\"early-only\""); - } - } - - if (result0 !== null) { - result0 = function (offset) { - data.early_only = true; - }(pos0); - } - - if (result0 === null) { - pos = pos0; - } - - return result0; - } - - function cleanupExpected(expected) { - expected.sort(); - var lastExpected = null; - var cleanExpected = []; - - for (var i = 0; i < expected.length; i++) { - if (expected[i] !== lastExpected) { - cleanExpected.push(expected[i]); - lastExpected = expected[i]; - } - } - - return cleanExpected; - } - - function computeErrorPosition() { - /* - * The first idea was to use |String.split| to break the input up to the - * error position along newlines and derive the line and column from - * there. However IE's |split| implementation is so broken that it was - * enough to prevent it. - */ - var line = 1; - var column = 1; - var seenCR = false; - - for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) { - var ch = input.charAt(i); - - if (ch === "\n") { - if (!seenCR) { - line++; - } - - column = 1; - seenCR = false; - } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { - line++; - column = 1; - seenCR = true; - } else { - column++; - seenCR = false; - } - } - - return { - line: line, - column: column - }; - } - - var URI = require('./URI'); - - var NameAddrHeader = require('./NameAddrHeader'); - - var data = {}; - var result = parseFunctions[startRule](); - /* - * The parser is now in one of the following three states: - * - * 1. The parser successfully parsed the whole input. - * - * - |result !== null| - * - |pos === input.length| - * - |rightmostFailuresExpected| may or may not contain something - * - * 2. The parser successfully parsed only a part of the input. - * - * - |result !== null| - * - |pos < input.length| - * - |rightmostFailuresExpected| may or may not contain something - * - * 3. The parser did not successfully parse any part of the input. - * - * - |result === null| - * - |pos === 0| - * - |rightmostFailuresExpected| contains at least one failure - * - * All code following this comment (including called functions) must - * handle these states. - */ - - if (result === null || pos !== input.length) { - var offset = Math.max(pos, rightmostFailuresPos); - var found = offset < input.length ? input.charAt(offset) : null; - var errorPosition = computeErrorPosition(); - new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column); - return -1; - } - - return data; - }, - - /* Returns the parser source code. */ - toSource: function toSource() { - return this._source; - } - }; - /* Thrown when a parser encounters a syntax error. */ - - result.SyntaxError = function (expected, found, offset, line, column) { - function buildMessage(expected, found) { - var expectedHumanized, foundHumanized; - - switch (expected.length) { - case 0: - expectedHumanized = "end of input"; - break; - - case 1: - expectedHumanized = expected[0]; - break; - - default: - expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1]; - } - - foundHumanized = found ? quote(found) : "end of input"; - return "Expected " + expectedHumanized + " but " + foundHumanized + " found."; - } - - this.name = "SyntaxError"; - this.expected = expected; - this.found = found; - this.message = buildMessage(expected, found); - this.offset = offset; - this.line = line; - this.column = column; - }; - - result.SyntaxError.prototype = Error.prototype; - return result; -}(); -},{"./NameAddrHeader":10,"./URI":25}],8:[function(require,module,exports){ -"use strict"; - -var pkg = require('../package.json'); - -var C = require('./Constants'); - -var Exceptions = require('./Exceptions'); - -var Utils = require('./Utils'); - -var UA = require('./UA'); - -var URI = require('./URI'); - -var NameAddrHeader = require('./NameAddrHeader'); - -var Grammar = require('./Grammar'); - -var WebSocketInterface = require('./WebSocketInterface'); - -var debug = require('debug')('JsSIP'); - -debug('version %s', pkg.version); -/** - * Expose the JsSIP module. - */ - -module.exports = { - C: C, - Exceptions: Exceptions, - Utils: Utils, - UA: UA, - URI: URI, - NameAddrHeader: NameAddrHeader, - WebSocketInterface: WebSocketInterface, - Grammar: Grammar, - // Expose the debug module. - debug: require('debug'), - - get name() { - return pkg.title; - }, - - get version() { - return pkg.version; - } - -}; -},{"../package.json":38,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":24,"./URI":25,"./Utils":26,"./WebSocketInterface":27,"debug":30}],9:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('./Constants'); - -var SIPMessage = require('./SIPMessage'); - -var Utils = require('./Utils'); - -var RequestSender = require('./RequestSender'); - -var Exceptions = require('./Exceptions'); - -var debug = require('debug')('JsSIP:Message'); - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(Message, _EventEmitter); - - var _super = _createSuper(Message); - - function Message(ua) { - var _this; - - _classCallCheck(this, Message); - - _this = _super.call(this); - _this._ua = ua; - _this._request = null; - _this._closed = false; - _this._direction = null; - _this._local_identity = null; - _this._remote_identity = null; // Whether an incoming message has been replied. - - _this._is_replied = false; // Custom message empty object for high level use. - - _this._data = {}; - return _this; - } - - _createClass(Message, [{ - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "send", - value: function send(target, body) { - var _this2 = this; - - var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - var originalTarget = target; - - if (target === undefined || body === undefined) { - throw new TypeError('Not enough arguments'); - } // Check target validity. - - - target = this._ua.normalizeTarget(target); - - if (!target) { - throw new TypeError("Invalid target: ".concat(originalTarget)); - } // Get call options. - - - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var contentType = options.contentType || 'text/plain'; // Set event handlers. - - for (var event in eventHandlers) { - if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { - this.on(event, eventHandlers[event]); - } - } - - extraHeaders.push("Content-Type: ".concat(contentType)); - this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, null, extraHeaders); - - if (body) { - this._request.body = body; - } - - var request_sender = new RequestSender(this._ua, this._request, { - onRequestTimeout: function onRequestTimeout() { - _this2._onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this2._onTransportError(); - }, - onReceiveResponse: function onReceiveResponse(response) { - _this2._receiveResponse(response); - } - }); - - this._newMessage('local', this._request); - - request_sender.send(); - } - }, { - key: "init_incoming", - value: function init_incoming(request) { - this._request = request; - - this._newMessage('remote', request); // Reply with a 200 OK if the user didn't reply. - - - if (!this._is_replied) { - this._is_replied = true; - request.reply(200); - } - - this._close(); - } - /** - * Accept the incoming Message - * Only valid for incoming Messages - */ - - }, { - key: "accept", - value: function accept() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var body = options.body; - - if (this._direction !== 'incoming') { - throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message'); - } - - if (this._is_replied) { - throw new Error('incoming Message already replied'); - } - - this._is_replied = true; - - this._request.reply(200, null, extraHeaders, body); - } - /** - * Reject the incoming Message - * Only valid for incoming Messages - */ - - }, { - key: "reject", - value: function reject() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var status_code = options.status_code || 480; - var reason_phrase = options.reason_phrase; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var body = options.body; - - if (this._direction !== 'incoming') { - throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message'); - } - - if (this._is_replied) { - throw new Error('incoming Message already replied'); - } - - if (status_code < 300 || status_code >= 700) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } - - this._is_replied = true; - - this._request.reply(status_code, reason_phrase, extraHeaders, body); - } - }, { - key: "_receiveResponse", - value: function _receiveResponse(response) { - if (this._closed) { - return; - } - - switch (true) { - case /^1[0-9]{2}$/.test(response.status_code): - // Ignore provisional responses. - break; - - case /^2[0-9]{2}$/.test(response.status_code): - this._succeeded('remote', response); - - break; - - default: - { - var cause = Utils.sipErrorCause(response.status_code); - - this._failed('remote', response, cause); - - break; - } - } - } - }, { - key: "_onRequestTimeout", - value: function _onRequestTimeout() { - if (this._closed) { - return; - } - - this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT); - } - }, { - key: "_onTransportError", - value: function _onTransportError() { - if (this._closed) { - return; - } - - this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); - } - }, { - key: "_close", - value: function _close() { - this._closed = true; - - this._ua.destroyMessage(this); - } - /** - * Internal Callbacks - */ - - }, { - key: "_newMessage", - value: function _newMessage(originator, request) { - if (originator === 'remote') { - this._direction = 'incoming'; - this._local_identity = request.to; - this._remote_identity = request.from; - } else if (originator === 'local') { - this._direction = 'outgoing'; - this._local_identity = request.from; - this._remote_identity = request.to; - } - - this._ua.newMessage(this, { - originator: originator, - message: this, - request: request - }); - } - }, { - key: "_failed", - value: function _failed(originator, response, cause) { - debug('MESSAGE failed'); - - this._close(); - - debug('emit "failed"'); - this.emit('failed', { - originator: originator, - response: response || null, - cause: cause - }); - } - }, { - key: "_succeeded", - value: function _succeeded(originator, response) { - debug('MESSAGE succeeded'); - - this._close(); - - debug('emit "succeeded"'); - this.emit('succeeded', { - originator: originator, - response: response - }); - } - }]); - - return Message; -}(EventEmitter); -},{"./Constants":2,"./Exceptions":6,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30,"events":29}],10:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var URI = require('./URI'); - -var Grammar = require('./Grammar'); - -module.exports = /*#__PURE__*/function () { - function NameAddrHeader(uri, display_name, parameters) { - _classCallCheck(this, NameAddrHeader); - - // Checks. - if (!uri || !(uri instanceof URI)) { - throw new TypeError('missing or invalid "uri" parameter'); - } // Initialize parameters. - - - this._uri = uri; - this._parameters = {}; - this.display_name = display_name; - - for (var param in parameters) { - if (Object.prototype.hasOwnProperty.call(parameters, param)) { - this.setParam(param, parameters[param]); - } - } - } - - _createClass(NameAddrHeader, [{ - key: "uri", - get: function get() { - return this._uri; - } - }, { - key: "display_name", - get: function get() { - return this._display_name; - }, - set: function set(value) { - this._display_name = value === 0 ? '0' : value; - } - }, { - key: "setParam", - value: function setParam(key, value) { - if (key) { - this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString(); - } - } - }, { - key: "getParam", - value: function getParam(key) { - if (key) { - return this._parameters[key.toLowerCase()]; - } - } - }, { - key: "hasParam", - value: function hasParam(key) { - if (key) { - return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false; - } - } - }, { - key: "deleteParam", - value: function deleteParam(parameter) { - parameter = parameter.toLowerCase(); - - if (this._parameters.hasOwnProperty(parameter)) { - var value = this._parameters[parameter]; - delete this._parameters[parameter]; - return value; - } - } - }, { - key: "clearParams", - value: function clearParams() { - this._parameters = {}; - } - }, { - key: "clone", - value: function clone() { - return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters))); - } - }, { - key: "_quote", - value: function _quote(str) { - return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); - } - }, { - key: "toString", - value: function toString() { - var body = this._display_name ? "\"".concat(this._quote(this._display_name), "\" ") : ''; - body += "<".concat(this._uri.toString(), ">"); - - for (var parameter in this._parameters) { - if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) { - body += ";".concat(parameter); - - if (this._parameters[parameter] !== null) { - body += "=".concat(this._parameters[parameter]); - } - } - } - - return body; - } - }], [{ - key: "parse", - value: - /** - * Parse the given string and returns a NameAddrHeader instance or undefined if - * it is an invalid NameAddrHeader. - */ - function parse(name_addr_header) { - name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); - - if (name_addr_header !== -1) { - return name_addr_header; - } else { - return undefined; - } - } - }]); - - return NameAddrHeader; -}(); -},{"./Grammar":7,"./URI":25}],11:[function(require,module,exports){ -"use strict"; - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var Grammar = require('./Grammar'); - -var SIPMessage = require('./SIPMessage'); - -var debugerror = require('debug')('JsSIP:ERROR:Parser'); - -debugerror.log = console.warn.bind(console); -/** - * Parse SIP Message - */ - -exports.parseMessage = function (data, ua) { - var message; - var bodyStart; - var headerEnd = data.indexOf('\r\n'); - - if (headerEnd === -1) { - debugerror('parseMessage() | no CRLF found, not a SIP message'); - return; - } // Parse first line. Check if it is a Request or a Reply. - - - var firstLine = data.substring(0, headerEnd); - var parsed = Grammar.parse(firstLine, 'Request_Response'); - - if (parsed === -1) { - debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); - return; - } else if (!parsed.status_code) { - message = new SIPMessage.IncomingRequest(ua); - message.method = parsed.method; - message.ruri = parsed.uri; - } else { - message = new SIPMessage.IncomingResponse(); - message.status_code = parsed.status_code; - message.reason_phrase = parsed.reason_phrase; - } - - message.data = data; - var headerStart = headerEnd + 2; - /* Loop over every line in data. Detect the end of each header and parse - * it or simply add to the headers collection. - */ - - while (true) { - headerEnd = getHeader(data, headerStart); // The SIP message has normally finished. - - if (headerEnd === -2) { - bodyStart = headerStart + 2; - break; - } // Data.indexOf returned -1 due to a malformed message. - else if (headerEnd === -1) { - debugerror('parseMessage() | malformed message'); - return; - } - - parsed = parseHeader(message, data, headerStart, headerEnd); - - if (parsed !== true) { - debugerror('parseMessage() |', parsed.error); - return; - } - - headerStart = headerEnd + 2; - } - /* RFC3261 18.3. - * If there are additional bytes in the transport packet - * beyond the end of the body, they MUST be discarded. - */ - - - if (message.hasHeader('content-length')) { - var contentLength = message.getHeader('content-length'); - message.body = data.substr(bodyStart, contentLength); - } else { - message.body = data.substring(bodyStart); - } - - return message; -}; -/** - * Extract and parse every header of a SIP message. - */ - - -function getHeader(data, headerStart) { - // 'start' position of the header. - var start = headerStart; // 'end' position of the header. - - var end = 0; // 'partial end' position of the header. - - var partialEnd = 0; // End of message. - - if (data.substring(start, start + 2).match(/(^\r\n)/)) { - return -2; - } - - while (end === 0) { - // Partial End of Header. - partialEnd = data.indexOf('\r\n', start); // 'indexOf' returns -1 if the value to be found never occurs. - - if (partialEnd === -1) { - return partialEnd; - } - - if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) { - // Not the end of the message. Continue from the next position. - start = partialEnd + 2; - } else { - end = partialEnd; - } - } - - return end; -} - -function parseHeader(message, data, headerStart, headerEnd) { - var parsed; - var hcolonIndex = data.indexOf(':', headerStart); - var headerName = data.substring(headerStart, hcolonIndex).trim(); - var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim(); // If header-field is well-known, parse it. - - switch (headerName.toLowerCase()) { - case 'via': - case 'v': - message.addHeader('via', headerValue); - - if (message.getHeaders('via').length === 1) { - parsed = message.parseHeader('Via'); - - if (parsed) { - message.via = parsed; - message.via_branch = parsed.branch; - } - } else { - parsed = 0; - } - - break; - - case 'from': - case 'f': - message.setHeader('from', headerValue); - parsed = message.parseHeader('from'); - - if (parsed) { - message.from = parsed; - message.from_tag = parsed.getParam('tag'); - } - - break; - - case 'to': - case 't': - message.setHeader('to', headerValue); - parsed = message.parseHeader('to'); - - if (parsed) { - message.to = parsed; - message.to_tag = parsed.getParam('tag'); - } - - break; - - case 'record-route': - parsed = Grammar.parse(headerValue, 'Record_Route'); - - if (parsed === -1) { - parsed = undefined; - } else { - var _iterator = _createForOfIteratorHelper(parsed), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var header = _step.value; - message.addHeader('record-route', headerValue.substring(header.possition, header.offset)); - message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed; - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } - - break; - - case 'call-id': - case 'i': - message.setHeader('call-id', headerValue); - parsed = message.parseHeader('call-id'); - - if (parsed) { - message.call_id = headerValue; - } - - break; - - case 'contact': - case 'm': - parsed = Grammar.parse(headerValue, 'Contact'); - - if (parsed === -1) { - parsed = undefined; - } else { - var _iterator2 = _createForOfIteratorHelper(parsed), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var _header = _step2.value; - message.addHeader('contact', headerValue.substring(_header.possition, _header.offset)); - message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed; - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - } - - break; - - case 'content-length': - case 'l': - message.setHeader('content-length', headerValue); - parsed = message.parseHeader('content-length'); - break; - - case 'content-type': - case 'c': - message.setHeader('content-type', headerValue); - parsed = message.parseHeader('content-type'); - break; - - case 'cseq': - message.setHeader('cseq', headerValue); - parsed = message.parseHeader('cseq'); - - if (parsed) { - message.cseq = parsed.value; - } - - if (message instanceof SIPMessage.IncomingResponse) { - message.method = parsed.method; - } - - break; - - case 'max-forwards': - message.setHeader('max-forwards', headerValue); - parsed = message.parseHeader('max-forwards'); - break; - - case 'www-authenticate': - message.setHeader('www-authenticate', headerValue); - parsed = message.parseHeader('www-authenticate'); - break; - - case 'proxy-authenticate': - message.setHeader('proxy-authenticate', headerValue); - parsed = message.parseHeader('proxy-authenticate'); - break; - - case 'session-expires': - case 'x': - message.setHeader('session-expires', headerValue); - parsed = message.parseHeader('session-expires'); - - if (parsed) { - message.session_expires = parsed.expires; - message.session_expires_refresher = parsed.refresher; - } - - break; - - case 'refer-to': - case 'r': - message.setHeader('refer-to', headerValue); - parsed = message.parseHeader('refer-to'); - - if (parsed) { - message.refer_to = parsed; - } - - break; - - case 'replaces': - message.setHeader('replaces', headerValue); - parsed = message.parseHeader('replaces'); - - if (parsed) { - message.replaces = parsed; - } - - break; - - case 'event': - case 'o': - message.setHeader('event', headerValue); - parsed = message.parseHeader('event'); - - if (parsed) { - message.event = parsed; - } - - break; - - default: - // Do not parse this header. - message.addHeader(headerName, headerValue); - parsed = 0; - } - - if (parsed === undefined) { - return { - error: "error parsing header \"".concat(headerName, "\"") - }; - } else { - return true; - } -} -},{"./Grammar":7,"./SIPMessage":19,"debug":30}],12:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -/* globals RTCPeerConnection: false, RTCSessionDescription: false */ -var EventEmitter = require('events').EventEmitter; - -var sdp_transform = require('sdp-transform'); - -var JsSIP_C = require('./Constants'); - -var Exceptions = require('./Exceptions'); - -var Transactions = require('./Transactions'); - -var Utils = require('./Utils'); - -var Timers = require('./Timers'); - -var SIPMessage = require('./SIPMessage'); - -var Dialog = require('./Dialog'); - -var RequestSender = require('./RequestSender'); - -var RTCSession_DTMF = require('./RTCSession/DTMF'); - -var RTCSession_Info = require('./RTCSession/Info'); - -var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier'); - -var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); - -var URI = require('./URI'); - -var debug = require('debug')('JsSIP:RTCSession'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession'); - -debugerror.log = console.warn.bind(console); -var C = { - // RTCSession states. - 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 -}; -/** - * Local variables. - */ - -var holdMediaTypes = ['audio', 'video']; - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(RTCSession, _EventEmitter); - - var _super = _createSuper(RTCSession); - - function RTCSession(ua) { - var _this; - - _classCallCheck(this, RTCSession); - - debug('new'); - _this = _super.call(this); - _this._id = null; - _this._ua = ua; - _this._status = C.STATUS_NULL; - _this._dialog = null; - _this._earlyDialogs = {}; - _this._contact = null; - _this._from_tag = null; - _this._to_tag = null; // The RTCPeerConnection instance (public attribute). - - _this._connection = null; // Prevent races on serial PeerConnction operations. - - _this._connectionPromiseQueue = Promise.resolve(); // Incoming/Outgoing request being currently processed. - - _this._request = null; // Cancel state for initial outgoing request. - - _this._is_canceled = false; - _this._cancel_reason = ''; // RTCSession confirmation flag. - - _this._is_confirmed = false; // Is late SDP being negotiated. - - _this._late_sdp = false; // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()). - - _this._rtcOfferConstraints = null; - _this._rtcAnswerConstraints = null; // Local MediaStream. - - _this._localMediaStream = null; - _this._localMediaStreamLocallyGenerated = false; // Flag to indicate PeerConnection ready for new actions. - - _this._rtcReady = true; // SIP Timers. - - _this._timers = { - ackTimer: null, - expiresTimer: null, - invite2xxTimer: null, - userNoAnswerTimer: null - }; // Session info. - - _this._direction = null; - _this._local_identity = null; - _this._remote_identity = null; - _this._start_time = null; - _this._end_time = null; - _this._tones = null; // Mute/Hold state. - - _this._audioMuted = false; - _this._videoMuted = false; - _this._localHold = false; - _this._remoteHold = false; // Session Timers (RFC 4028). - - _this._sessionTimers = { - enabled: _this._ua.configuration.session_timers, - refreshMethod: _this._ua.configuration.session_timers_refresh_method, - defaultExpires: JsSIP_C.SESSION_EXPIRES, - currentExpires: null, - running: false, - refresher: false, - timer: null // A setTimeout. - - }; // Map of ReferSubscriber instances indexed by the REFER's CSeq number. - - _this._referSubscribers = {}; // Custom session empty object for high level use. - - _this._data = {}; - return _this; - } - /** - * User API - */ - // Expose RTCSession constants as a property of the RTCSession instance. - - - _createClass(RTCSession, [{ - key: "C", - get: function get() { - return C; - } // Expose session failed/ended causes as a property of the RTCSession instance. - - }, { - key: "causes", - get: function get() { - return JsSIP_C.causes; - } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "connection", - get: function get() { - return this._connection; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "start_time", - get: function get() { - return this._start_time; - } - }, { - key: "end_time", - get: function get() { - return this._end_time; - } - }, { - key: "data", - get: function get() { - return this._data; - }, - set: function set(_data) { - this._data = _data; - } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "isInProgress", - value: function isInProgress() { - switch (this._status) { - case C.STATUS_NULL: - case C.STATUS_INVITE_SENT: - case C.STATUS_1XX_RECEIVED: - case C.STATUS_INVITE_RECEIVED: - case C.STATUS_WAITING_FOR_ANSWER: - return true; - - default: - return false; - } - } - }, { - key: "isEstablished", - value: function isEstablished() { - switch (this._status) { - case C.STATUS_ANSWERED: - case C.STATUS_WAITING_FOR_ACK: - case C.STATUS_CONFIRMED: - return true; - - default: - return false; - } - } - }, { - key: "isEnded", - value: function isEnded() { - switch (this._status) { - case C.STATUS_CANCELED: - case C.STATUS_TERMINATED: - return true; - - default: - return false; - } - } - }, { - key: "isMuted", - value: function isMuted() { - return { - audio: this._audioMuted, - video: this._videoMuted - }; - } - }, { - key: "isOnHold", - value: function isOnHold() { - return { - local: this._localHold, - remote: this._remoteHold - }; - } - }, { - key: "connect", - value: function connect(target) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var initCallback = arguments.length > 2 ? arguments[2] : undefined; - debug('connect()'); - var originalTarget = target; - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var mediaConstraints = Utils.cloneObject(options.mediaConstraints, { - audio: true, - video: true - }); - var mediaStream = options.mediaStream || null; - var pcConfig = Utils.cloneObject(options.pcConfig, { - iceServers: [] - }); - var rtcConstraints = options.rtcConstraints || null; - var rtcOfferConstraints = options.rtcOfferConstraints || null; - this._rtcOfferConstraints = rtcOfferConstraints; - this._rtcAnswerConstraints = options.rtcAnswerConstraints || null; - this._data = options.data || this._data; // Check target. - - if (target === undefined) { - throw new TypeError('Not enough arguments'); - } // Check Session Status. - - - if (this._status !== C.STATUS_NULL) { - throw new Exceptions.InvalidStateError(this._status); - } // Check WebRTC support. - - - if (!window.RTCPeerConnection) { - throw new Exceptions.NotSupportedError('WebRTC not supported'); - } // Check target validity. - - - target = this._ua.normalizeTarget(target); - - if (!target) { - throw new TypeError("Invalid target: ".concat(originalTarget)); - } // Session Timers. - - - if (this._sessionTimers.enabled) { - if (Utils.isDecimal(options.sessionTimersExpires)) { - if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) { - this._sessionTimers.defaultExpires = options.sessionTimersExpires; - } else { - this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES; - } - } - } // Set event handlers. - - - for (var event in eventHandlers) { - if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { - this.on(event, eventHandlers[event]); - } - } // Session parameter initialization. - - - this._from_tag = Utils.newTag(); // Set anonymous property. - - var anonymous = options.anonymous || false; - var requestParams = { - from_tag: this._from_tag - }; - this._contact = this._ua.contact.toString({ - anonymous: anonymous, - outbound: true - }); - - if (anonymous) { - requestParams.from_display_name = 'Anonymous'; - requestParams.from_uri = new URI('sip', 'anonymous', 'anonymous.invalid'); - extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())); - extraHeaders.push('Privacy: id'); - } else if (options.fromUserName) { - requestParams.from_uri = new URI('sip', options.fromUserName, this._ua.configuration.uri.host); - extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())); - } - - if (options.fromDisplayName) { - requestParams.from_display_name = options.fromDisplayName; - } - - extraHeaders.push("Contact: ".concat(this._contact)); - extraHeaders.push('Content-Type: application/sdp'); - - if (this._sessionTimers.enabled) { - extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher ? ';refresher=uac' : '')); - } - - this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders); - this._id = this._request.call_id + this._from_tag; // Create a new RTCPeerConnection instance. - - this._createRTCConnection(pcConfig, rtcConstraints); // Set internal properties. - - - this._direction = 'outgoing'; - this._local_identity = this._request.from; - this._remote_identity = this._request.to; // User explicitly provided a newRTCSession callback for this session. - - if (initCallback) { - initCallback(this); - } - - this._newRTCSession('local', this._request); - - this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream); - } - }, { - key: "init_incoming", - value: function init_incoming(request, initCallback) { - var _this2 = this; - - debug('init_incoming()'); - var expires; - var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type. - - if (request.body && contentType !== 'application/sdp') { - request.reply(415); - return; - } // Session parameter initialization. - - - this._status = C.STATUS_INVITE_RECEIVED; - this._from_tag = request.from_tag; - this._id = request.call_id + this._from_tag; - this._request = request; - this._contact = this._ua.contact.toString(); // Get the Expires header value if exists. - - if (request.hasHeader('expires')) { - expires = request.getHeader('expires') * 1000; - } - /* Set the to_tag before - * replying a response code that will create a dialog. - */ - - - request.to_tag = Utils.newTag(); // An error on dialog creation will fire 'failed' event. - - if (!this._createDialog(request, 'UAS', true)) { - request.reply(500, 'Missing Contact header field'); - return; - } - - if (request.body) { - this._late_sdp = false; - } else { - this._late_sdp = true; - } - - this._status = C.STATUS_WAITING_FOR_ANSWER; // Set userNoAnswerTimer. - - this._timers.userNoAnswerTimer = setTimeout(function () { - request.reply(408); - - _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER); - }, this._ua.configuration.no_answer_timeout); - /* Set expiresTimer - * RFC3261 13.3.1 - */ - - if (expires) { - this._timers.expiresTimer = setTimeout(function () { - if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) { - request.reply(487); - - _this2._failed('system', null, JsSIP_C.causes.EXPIRES); - } - }, expires); - } // Set internal properties. - - - this._direction = 'incoming'; - this._local_identity = request.to; - this._remote_identity = request.from; // A init callback was specifically defined. - - if (initCallback) { - initCallback(this); - } // Fire 'newRTCSession' event. - - - this._newRTCSession('remote', request); // The user may have rejected the call in the 'newRTCSession' event. - - - if (this._status === C.STATUS_TERMINATED) { - return; - } // Reply 180. - - - request.reply(180, null, ["Contact: ".concat(this._contact)]); // Fire 'progress' event. - // TODO: Document that 'response' field in 'progress' event is null for incoming calls. - - this._progress('local', null); - } - /** - * Answer the call. - */ - - }, { - key: "answer", - value: function answer() { - var _this3 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('answer()'); - var request = this._request; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var mediaConstraints = Utils.cloneObject(options.mediaConstraints); - var mediaStream = options.mediaStream || null; - var pcConfig = Utils.cloneObject(options.pcConfig, { - iceServers: [] - }); - var rtcConstraints = options.rtcConstraints || null; - var rtcAnswerConstraints = options.rtcAnswerConstraints || null; - var rtcOfferConstraints = Utils.cloneObject(options.rtcOfferConstraints); - var tracks; - var peerHasAudioLine = false; - var peerHasVideoLine = false; - var peerOffersFullAudio = false; - var peerOffersFullVideo = false; - this._rtcAnswerConstraints = rtcAnswerConstraints; - this._rtcOfferConstraints = options.rtcOfferConstraints || null; - this._data = options.data || this._data; // Check Session Direction and Status. - - if (this._direction !== 'incoming') { - throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession'); - } // Check Session status. - - - if (this._status !== C.STATUS_WAITING_FOR_ANSWER) { - throw new Exceptions.InvalidStateError(this._status); - } // Session Timers. - - - if (this._sessionTimers.enabled) { - if (Utils.isDecimal(options.sessionTimersExpires)) { - if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) { - this._sessionTimers.defaultExpires = options.sessionTimersExpires; - } else { - this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES; - } - } - } - - this._status = C.STATUS_ANSWERED; // An error on dialog creation will fire 'failed' event. - - if (!this._createDialog(request, 'UAS')) { - request.reply(500, 'Error creating dialog'); - return; - } - - clearTimeout(this._timers.userNoAnswerTimer); - extraHeaders.unshift("Contact: ".concat(this._contact)); // Determine incoming media from incoming SDP offer (if any). - - var sdp = request.parseSDP(); // Make sure sdp.media is an array, not the case if there is only one media. - - if (!Array.isArray(sdp.media)) { - sdp.media = [sdp.media]; - } // Go through all medias in SDP to find offered capabilities to answer with. - - - var _iterator = _createForOfIteratorHelper(sdp.media), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var m = _step.value; - - if (m.type === 'audio') { - peerHasAudioLine = true; - - if (!m.direction || m.direction === 'sendrecv') { - peerOffersFullAudio = true; - } - } - - if (m.type === 'video') { - peerHasVideoLine = true; - - if (!m.direction || m.direction === 'sendrecv') { - peerOffersFullVideo = true; - } - } - } // Remove audio from mediaStream if suggested by mediaConstraints. - - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - - if (mediaStream && mediaConstraints.audio === false) { - tracks = mediaStream.getAudioTracks(); - - var _iterator2 = _createForOfIteratorHelper(tracks), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var track = _step2.value; - mediaStream.removeTrack(track); - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - } // Remove video from mediaStream if suggested by mediaConstraints. - - - if (mediaStream && mediaConstraints.video === false) { - tracks = mediaStream.getVideoTracks(); - - var _iterator3 = _createForOfIteratorHelper(tracks), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var _track = _step3.value; - mediaStream.removeTrack(_track); - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } - } // Set audio constraints based on incoming stream if not supplied. - - - if (!mediaStream && mediaConstraints.audio === undefined) { - mediaConstraints.audio = peerOffersFullAudio; - } // Set video constraints based on incoming stream if not supplied. - - - if (!mediaStream && mediaConstraints.video === undefined) { - mediaConstraints.video = peerOffersFullVideo; - } // Don't ask for audio if the incoming offer has no audio section. - - - if (!mediaStream && !peerHasAudioLine && !rtcOfferConstraints.offerToReceiveAudio) { - mediaConstraints.audio = false; - } // Don't ask for video if the incoming offer has no video section. - - - if (!mediaStream && !peerHasVideoLine && !rtcOfferConstraints.offerToReceiveVideo) { - mediaConstraints.video = false; - } // Create a new RTCPeerConnection instance. - // TODO: This may throw an error, should react. - - - this._createRTCConnection(pcConfig, rtcConstraints); - - Promise.resolve() // Handle local MediaStream. - .then(function () { - // A local MediaStream is given, use it. - if (mediaStream) { - return mediaStream; - } // Audio and/or video requested, prompt getUserMedia. - else if (mediaConstraints.audio || mediaConstraints.video) { - _this3._localMediaStreamLocallyGenerated = true; - return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) { - if (_this3._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - request.reply(480); - - _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - - debugerror('emit "getusermediafailed" [error:%o]', error); - - _this3.emit('getusermediafailed', error); - - throw new Error('getUserMedia() failed'); - }); - } - }) // Attach MediaStream to RTCPeerconnection. - .then(function (stream) { - if (_this3._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this3._localMediaStream = stream; - - if (stream) { - stream.getTracks().forEach(function (track) { - _this3._connection.addTrack(track, stream); - }); - } - }) // Set remote description. - .then(function () { - if (_this3._late_sdp) { - return; - } - - var e = { - originator: 'remote', - type: 'offer', - sdp: request.body - }; - debug('emit "sdp"'); - - _this3.emit('sdp', e); - - var offer = new RTCSessionDescription({ - type: 'offer', - sdp: e.sdp - }); - _this3._connectionPromiseQueue = _this3._connectionPromiseQueue.then(function () { - return _this3._connection.setRemoteDescription(offer); - })["catch"](function (error) { - request.reply(488); - - _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); - - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this3.emit('peerconnection:setremotedescriptionfailed', error); - - throw new Error('peerconnection.setRemoteDescription() failed'); - }); - return _this3._connectionPromiseQueue; - }) // Create local description. - .then(function () { - if (_this3._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } // TODO: Is this event already useful? - - - _this3._connecting(request); - - if (!_this3._late_sdp) { - return _this3._createLocalDescription('answer', rtcAnswerConstraints)["catch"](function () { - request.reply(500); - throw new Error('_createLocalDescription() failed'); - }); - } else { - return _this3._createLocalDescription('offer', _this3._rtcOfferConstraints)["catch"](function () { - request.reply(500); - throw new Error('_createLocalDescription() failed'); - }); - } - }) // Send reply. - .then(function (desc) { - if (_this3._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this3._handleSessionTimersInIncomingRequest(request, extraHeaders); - - request.reply(200, null, extraHeaders, desc, function () { - _this3._status = C.STATUS_WAITING_FOR_ACK; - - _this3._setInvite2xxTimer(request, desc); - - _this3._setACKTimer(); - - _this3._accepted('local'); - }, function () { - _this3._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); - }); - })["catch"](function (error) { - if (_this3._status === C.STATUS_TERMINATED) { - return; - } - - debugerror(error); - }); - } - /** - * Terminate the call. - */ - - }, { - key: "terminate", - value: function terminate() { - var _this4 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('terminate()'); - var cause = options.cause || JsSIP_C.causes.BYE; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var body = options.body; - var cancel_reason; - var status_code = options.status_code; - var reason_phrase = options.reason_phrase; // Check Session Status. - - if (this._status === C.STATUS_TERMINATED) { - throw new Exceptions.InvalidStateError(this._status); - } - - switch (this._status) { - // - UAC - - case C.STATUS_NULL: - case C.STATUS_INVITE_SENT: - case C.STATUS_1XX_RECEIVED: - debug('canceling session'); - - if (status_code && (status_code < 200 || status_code >= 700)) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } else if (status_code) { - reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; - cancel_reason = "SIP ;cause=".concat(status_code, " ;text=\"").concat(reason_phrase, "\""); - } // Check Session Status. - - - if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) { - this._is_canceled = true; - this._cancel_reason = cancel_reason; - } else if (this._status === C.STATUS_1XX_RECEIVED) { - this._request.cancel(cancel_reason); - } - - this._status = C.STATUS_CANCELED; - - this._failed('local', null, JsSIP_C.causes.CANCELED); - - break; - // - UAS - - - case C.STATUS_WAITING_FOR_ANSWER: - case C.STATUS_ANSWERED: - debug('rejecting session'); - status_code = status_code || 480; - - if (status_code < 300 || status_code >= 700) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } - - this._request.reply(status_code, reason_phrase, extraHeaders, body); - - this._failed('local', null, JsSIP_C.causes.REJECTED); - - break; - - case C.STATUS_WAITING_FOR_ACK: - case C.STATUS_CONFIRMED: - debug('terminating session'); - reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; - - if (status_code && (status_code < 200 || status_code >= 700)) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } else if (status_code) { - extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\"")); - } - /* RFC 3261 section 15 (Terminating a session): - * - * "...the callee's UA MUST NOT send a BYE on a confirmed dialog - * until it has received an ACK for its 2xx response or until the server - * transaction times out." - */ - - - if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) { - // Save the dialog for later restoration. - var dialog = this._dialog; // Send the BYE as soon as the ACK is received... - - this.receiveRequest = function (_ref) { - var method = _ref.method; - - if (method === JsSIP_C.ACK) { - _this4.sendRequest(JsSIP_C.BYE, { - extraHeaders: extraHeaders, - body: body - }); - - dialog.terminate(); - } - }; // .., or when the INVITE transaction times out - - - this._request.server_transaction.on('stateChanged', function () { - if (_this4._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) { - _this4.sendRequest(JsSIP_C.BYE, { - extraHeaders: extraHeaders, - body: body - }); - - dialog.terminate(); - } - }); - - this._ended('local', null, cause); // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-). - - - this._dialog = dialog; // Restore the dialog into 'ua' so the ACK can reach 'this' session. - - this._ua.newDialog(dialog); - } else { - this.sendRequest(JsSIP_C.BYE, { - extraHeaders: extraHeaders, - body: body - }); - - this._ended('local', null, cause); - } - - } - } - }, { - key: "sendDTMF", - value: function sendDTMF(tones) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendDTMF() | tones: %s', tones); - var position = 0; - var duration = options.duration || null; - var interToneGap = options.interToneGap || null; - var transportType = options.transportType || JsSIP_C.DTMF_TRANSPORT.INFO; - - if (tones === undefined) { - throw new TypeError('Not enough arguments'); - } // Check Session Status. - - - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { - throw new Exceptions.InvalidStateError(this._status); - } // Check Transport type. - - - if (transportType !== JsSIP_C.DTMF_TRANSPORT.INFO && transportType !== JsSIP_C.DTMF_TRANSPORT.RFC2833) { - throw new TypeError("invalid transportType: ".concat(transportType)); - } // Convert to string. - - - if (typeof tones === 'number') { - tones = tones.toString(); - } // Check tones. - - - if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) { - throw new TypeError("Invalid tones: ".concat(tones)); - } // Check duration. - - - if (duration && !Utils.isDecimal(duration)) { - throw new TypeError("Invalid tone duration: ".concat(duration)); - } else if (!duration) { - duration = RTCSession_DTMF.C.DEFAULT_DURATION; - } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { - debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); - duration = RTCSession_DTMF.C.MIN_DURATION; - } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { - debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); - duration = RTCSession_DTMF.C.MAX_DURATION; - } else { - duration = Math.abs(duration); - } - - options.duration = duration; // Check interToneGap. - - if (interToneGap && !Utils.isDecimal(interToneGap)) { - throw new TypeError("Invalid interToneGap: ".concat(interToneGap)); - } else if (!interToneGap) { - interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP; - } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { - debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); - interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; - } else { - interToneGap = Math.abs(interToneGap); - } // RFC2833. Let RTCDTMFSender enqueue the DTMFs. - - - if (transportType === JsSIP_C.DTMF_TRANSPORT.RFC2833) { - // Send DTMF in current audio RTP stream. - var sender = this._getDTMFRTPSender(); - - if (sender) { - // Add remaining buffered tones. - tones = sender.toneBuffer + tones; // Insert tones. - - sender.insertDTMF(tones, duration, interToneGap); - } - - return; - } - - if (this._tones) { - // Tones are already queued, just add to the queue. - this._tones += tones; - return; - } - - this._tones = tones; // Send the first tone. - - _sendDTMF.call(this); - - function _sendDTMF() { - var _this5 = this; - - var timeout; - - if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) { - // Stop sending DTMF. - this._tones = null; - return; - } - - var tone = this._tones[position]; - position += 1; - - if (tone === ',') { - timeout = 2000; - } else { - // Send DTMF via SIP INFO messages. - var dtmf = new RTCSession_DTMF(this); - options.eventHandlers = { - onFailed: function onFailed() { - _this5._tones = null; - } - }; - dtmf.send(tone, options); - timeout = duration + interToneGap; - } // Set timeout for the next tone. - - - setTimeout(_sendDTMF.bind(this), timeout); - } - } - }, { - key: "sendInfo", - value: function sendInfo(contentType, body) { - var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - debug('sendInfo()'); // Check Session Status. - - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { - throw new Exceptions.InvalidStateError(this._status); - } - - var info = new RTCSession_Info(this); - info.send(contentType, body, options); - } - /** - * Mute - */ - - }, { - key: "mute", - value: function mute() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { - audio: true, - video: false - }; - debug('mute()'); - var audioMuted = false, - videoMuted = false; - - if (this._audioMuted === false && options.audio) { - audioMuted = true; - this._audioMuted = true; - - this._toggleMuteAudio(true); - } - - if (this._videoMuted === false && options.video) { - videoMuted = true; - this._videoMuted = true; - - this._toggleMuteVideo(true); - } - - if (audioMuted === true || videoMuted === true) { - this._onmute({ - audio: audioMuted, - video: videoMuted - }); - } - } - /** - * Unmute - */ - - }, { - key: "unmute", - value: function unmute() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { - audio: true, - video: true - }; - debug('unmute()'); - var audioUnMuted = false, - videoUnMuted = false; - - if (this._audioMuted === true && options.audio) { - audioUnMuted = true; - this._audioMuted = false; - - if (this._localHold === false) { - this._toggleMuteAudio(false); - } - } - - if (this._videoMuted === true && options.video) { - videoUnMuted = true; - this._videoMuted = false; - - if (this._localHold === false) { - this._toggleMuteVideo(false); - } - } - - if (audioUnMuted === true || videoUnMuted === true) { - this._onunmute({ - audio: audioUnMuted, - video: videoUnMuted - }); - } - } - /** - * Hold - */ - - }, { - key: "hold", - value: function hold() { - var _this6 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var done = arguments.length > 1 ? arguments[1] : undefined; - debug('hold()'); - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (this._localHold === true) { - return false; - } - - if (!this._isReadyToReOffer()) { - return false; - } - - this._localHold = true; - - this._onhold('local'); - - var eventHandlers = { - succeeded: function succeeded() { - if (done) { - done(); - } - }, - failed: function failed() { - _this6.terminate({ - cause: JsSIP_C.causes.WEBRTC_ERROR, - status_code: 500, - reason_phrase: 'Hold Failed' - }); - } - }; - - if (options.useUpdate) { - this._sendUpdate({ - sdpOffer: true, - eventHandlers: eventHandlers, - extraHeaders: options.extraHeaders - }); - } else { - this._sendReinvite({ - eventHandlers: eventHandlers, - extraHeaders: options.extraHeaders - }); - } - - return true; - } - }, { - key: "unhold", - value: function unhold() { - var _this7 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var done = arguments.length > 1 ? arguments[1] : undefined; - debug('unhold()'); - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (this._localHold === false) { - return false; - } - - if (!this._isReadyToReOffer()) { - return false; - } - - this._localHold = false; - - this._onunhold('local'); - - var eventHandlers = { - succeeded: function succeeded() { - if (done) { - done(); - } - }, - failed: function failed() { - _this7.terminate({ - cause: JsSIP_C.causes.WEBRTC_ERROR, - status_code: 500, - reason_phrase: 'Unhold Failed' - }); - } - }; - - if (options.useUpdate) { - this._sendUpdate({ - sdpOffer: true, - eventHandlers: eventHandlers, - extraHeaders: options.extraHeaders - }); - } else { - this._sendReinvite({ - eventHandlers: eventHandlers, - extraHeaders: options.extraHeaders - }); - } - - return true; - } - }, { - key: "renegotiate", - value: function renegotiate() { - var _this8 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var done = arguments.length > 1 ? arguments[1] : undefined; - debug('renegotiate()'); - var rtcOfferConstraints = options.rtcOfferConstraints || null; - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (!this._isReadyToReOffer()) { - return false; - } - - var eventHandlers = { - succeeded: function succeeded() { - if (done) { - done(); - } - }, - failed: function failed() { - _this8.terminate({ - cause: JsSIP_C.causes.WEBRTC_ERROR, - status_code: 500, - reason_phrase: 'Media Renegotiation Failed' - }); - } - }; - - this._setLocalMediaStatus(); - - if (options.useUpdate) { - this._sendUpdate({ - sdpOffer: true, - eventHandlers: eventHandlers, - rtcOfferConstraints: rtcOfferConstraints, - extraHeaders: options.extraHeaders - }); - } else { - this._sendReinvite({ - eventHandlers: eventHandlers, - rtcOfferConstraints: rtcOfferConstraints, - extraHeaders: options.extraHeaders - }); - } - - return true; - } - /** - * Refer - */ - - }, { - key: "refer", - value: function refer(target, options) { - var _this9 = this; - - debug('refer()'); - var originalTarget = target; - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } // Check target validity. - - - target = this._ua.normalizeTarget(target); - - if (!target) { - throw new TypeError("Invalid target: ".concat(originalTarget)); - } - - var referSubscriber = new RTCSession_ReferSubscriber(this); - referSubscriber.sendRefer(target, options); // Store in the map. - - var id = referSubscriber.id; - this._referSubscribers[id] = referSubscriber; // Listen for ending events so we can remove it from the map. - - referSubscriber.on('requestFailed', function () { - delete _this9._referSubscribers[id]; - }); - referSubscriber.on('accepted', function () { - delete _this9._referSubscribers[id]; - }); - referSubscriber.on('failed', function () { - delete _this9._referSubscribers[id]; - }); - return referSubscriber; - } - /** - * Send a generic in-dialog Request - */ - - }, { - key: "sendRequest", - value: function sendRequest(method, options) { - debug('sendRequest()'); - return this._dialog.sendRequest(method, options); - } - /** - * In dialog Request Reception - */ - - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - var _this10 = this; - - debug('receiveRequest()'); - - if (request.method === JsSIP_C.CANCEL) { - /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL - * was in progress and that the UAC MAY continue with the session established by - * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the - * established session. So the CANCEL is processed only if the session is not yet - * established. - */ - - /* - * Terminate the whole session in case the user didn't accept (or yet send the answer) - * nor reject the request opening the session. - */ - if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) { - this._status = C.STATUS_CANCELED; - - this._request.reply(487); - - this._failed('remote', request, JsSIP_C.causes.CANCELED); - } - } else { - // Requests arriving here are in-dialog requests. - switch (request.method) { - case JsSIP_C.ACK: - if (this._status !== C.STATUS_WAITING_FOR_ACK) { - return; - } // Update signaling status. - - - this._status = C.STATUS_CONFIRMED; - clearTimeout(this._timers.ackTimer); - clearTimeout(this._timers.invite2xxTimer); - - if (this._late_sdp) { - if (!request.body) { - this.terminate({ - cause: JsSIP_C.causes.MISSING_SDP, - status_code: 400 - }); - break; - } - - var e = { - originator: 'remote', - type: 'answer', - sdp: request.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var answer = new RTCSessionDescription({ - type: 'answer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this10._connection.setRemoteDescription(answer); - }).then(function () { - if (!_this10._is_confirmed) { - _this10._confirmed('remote', request); - } - })["catch"](function (error) { - _this10.terminate({ - cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION, - status_code: 488 - }); - - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this10.emit('peerconnection:setremotedescriptionfailed', error); - }); - } else if (!this._is_confirmed) { - this._confirmed('remote', request); - } - - break; - - case JsSIP_C.BYE: - if (this._status === C.STATUS_CONFIRMED || this._status === C.STATUS_WAITING_FOR_ACK) { - request.reply(200); - - this._ended('remote', request, JsSIP_C.causes.BYE); - } else if (this._status === C.STATUS_INVITE_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER) { - request.reply(200); - - this._request.reply(487, 'BYE Received'); - - this._ended('remote', request, JsSIP_C.causes.BYE); - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.INVITE: - if (this._status === C.STATUS_CONFIRMED) { - if (request.hasHeader('replaces')) { - this._receiveReplaces(request); - } else { - this._receiveReinvite(request); - } - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.INFO: - if (this._status === C.STATUS_1XX_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED || this._status === C.STATUS_WAITING_FOR_ACK || this._status === C.STATUS_CONFIRMED) { - var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; - - if (contentType && contentType.match(/^application\/dtmf-relay/i)) { - new RTCSession_DTMF(this).init_incoming(request); - } else if (contentType !== undefined) { - new RTCSession_Info(this).init_incoming(request); - } else { - request.reply(415); - } - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.UPDATE: - if (this._status === C.STATUS_CONFIRMED) { - this._receiveUpdate(request); - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.REFER: - if (this._status === C.STATUS_CONFIRMED) { - this._receiveRefer(request); - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - case JsSIP_C.NOTIFY: - if (this._status === C.STATUS_CONFIRMED) { - this._receiveNotify(request); - } else { - request.reply(403, 'Wrong Status'); - } - - break; - - default: - request.reply(501); - } - } - } - /** - * Session Callbacks - */ - - }, { - key: "onTransportError", - value: function onTransportError() { - debugerror('onTransportError()'); - - if (this._status !== C.STATUS_TERMINATED) { - this.terminate({ - status_code: 500, - reason_phrase: JsSIP_C.causes.CONNECTION_ERROR, - cause: JsSIP_C.causes.CONNECTION_ERROR - }); - } - } - }, { - key: "onRequestTimeout", - value: function onRequestTimeout() { - debugerror('onRequestTimeout()'); - - if (this._status !== C.STATUS_TERMINATED) { - this.terminate({ - status_code: 408, - reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT, - cause: JsSIP_C.causes.REQUEST_TIMEOUT - }); - } - } - }, { - key: "onDialogError", - value: function onDialogError() { - debugerror('onDialogError()'); - - if (this._status !== C.STATUS_TERMINATED) { - this.terminate({ - status_code: 500, - reason_phrase: JsSIP_C.causes.DIALOG_ERROR, - cause: JsSIP_C.causes.DIALOG_ERROR - }); - } - } // Called from DTMF handler. - - }, { - key: "newDTMF", - value: function newDTMF(data) { - debug('newDTMF()'); - this.emit('newDTMF', data); - } // Called from Info handler. - - }, { - key: "newInfo", - value: function newInfo(data) { - debug('newInfo()'); - this.emit('newInfo', data); - } - /** - * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP. - */ - - }, { - key: "_isReadyToReOffer", - value: function _isReadyToReOffer() { - if (!this._rtcReady) { - debug('_isReadyToReOffer() | internal WebRTC status not ready'); - return false; - } // No established yet. - - - if (!this._dialog) { - debug('_isReadyToReOffer() | session not established yet'); - return false; - } // Another INVITE transaction is in progress. - - - if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { - debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); - return false; - } - - return true; - } - }, { - key: "_close", - value: function _close() { - debug('close()'); // Close local MediaStream if it was not given by the user. - - if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { - debug('close() | closing local MediaStream'); - Utils.closeMediaStream(this._localMediaStream); - } - - if (this._status === C.STATUS_TERMINATED) { - return; - } - - this._status = C.STATUS_TERMINATED; // Terminate RTC. - - if (this._connection) { - try { - this._connection.close(); - } catch (error) { - debugerror('close() | error closing the RTCPeerConnection: %o', error); - } - } // Terminate signaling. - // Clear SIP timers. - - - for (var timer in this._timers) { - if (Object.prototype.hasOwnProperty.call(this._timers, timer)) { - clearTimeout(this._timers[timer]); - } - } // Clear Session Timers. - - - clearTimeout(this._sessionTimers.timer); // Terminate confirmed dialog. - - if (this._dialog) { - this._dialog.terminate(); - - delete this._dialog; - } // Terminate early dialogs. - - - for (var dialog in this._earlyDialogs) { - if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) { - this._earlyDialogs[dialog].terminate(); - - delete this._earlyDialogs[dialog]; - } - } // Terminate REFER subscribers. - - - for (var subscriber in this._referSubscribers) { - if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) { - delete this._referSubscribers[subscriber]; - } - } - - this._ua.destroyRTCSession(this); - } - /** - * Private API. - */ - - /** - * RFC3261 13.3.1.4 - * Response retransmissions cannot be accomplished by transaction layer - * since it is destroyed when receiving the first 2xx answer - */ - - }, { - key: "_setInvite2xxTimer", - value: function _setInvite2xxTimer(request, body) { - var timeout = Timers.T1; - - function invite2xxRetransmission() { - if (this._status !== C.STATUS_WAITING_FOR_ACK) { - return; - } - - request.reply(200, null, ["Contact: ".concat(this._contact)], body); - - if (timeout < Timers.T2) { - timeout = timeout * 2; - - if (timeout > Timers.T2) { - timeout = Timers.T2; - } - } - - this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout); - } - - this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout); - } - /** - * RFC3261 14.2 - * If a UAS generates a 2xx response and never receives an ACK, - * it SHOULD generate a BYE to terminate the dialog. - */ - - }, { - key: "_setACKTimer", - value: function _setACKTimer() { - var _this11 = this; - - this._timers.ackTimer = setTimeout(function () { - if (_this11._status === C.STATUS_WAITING_FOR_ACK) { - debug('no ACK received, terminating the session'); - clearTimeout(_this11._timers.invite2xxTimer); - - _this11.sendRequest(JsSIP_C.BYE); - - _this11._ended('remote', null, JsSIP_C.causes.NO_ACK); - } - }, Timers.TIMER_H); - } - }, { - key: "_createRTCConnection", - value: function _createRTCConnection(pcConfig, rtcConstraints) { - var _this12 = this; - - this._connection = new RTCPeerConnection(pcConfig, rtcConstraints); - - this._connection.addEventListener('iceconnectionstatechange', function () { - var state = _this12._connection.iceConnectionState; // TODO: Do more with different states. - - if (state === 'failed') { - _this12.terminate({ - cause: JsSIP_C.causes.RTP_TIMEOUT, - status_code: 408, - reason_phrase: JsSIP_C.causes.RTP_TIMEOUT - }); - } - }); - - debug('emit "peerconnection"'); - this.emit('peerconnection', { - peerconnection: this._connection - }); - } - }, { - key: "_createLocalDescription", - value: function _createLocalDescription(type, constraints) { - var _this13 = this; - - debug('createLocalDescription()'); - if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\"")); - var connection = this._connection; - this._rtcReady = false; - return Promise.resolve() // Create Offer or Answer. - .then(function () { - if (type === 'offer') { - return connection.createOffer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); - - _this13.emit('peerconnection:createofferfailed', error); - - return Promise.reject(error); - }); - } else { - return connection.createAnswer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); - - _this13.emit('peerconnection:createanswerfailed', error); - - return Promise.reject(error); - }); - } - }) // Set local description. - .then(function (desc) { - return connection.setLocalDescription(desc)["catch"](function (error) { - _this13._rtcReady = true; - debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); - - _this13.emit('peerconnection:setlocaldescriptionfailed', error); - - return Promise.reject(error); - }); - }).then(function () { - // Resolve right away if 'pc.iceGatheringState' is 'complete'. - if (connection.iceGatheringState === 'complete' && (!constraints || !constraints.iceRestart)) { - _this13._rtcReady = true; - var e = { - originator: 'local', - type: type, - sdp: connection.localDescription.sdp - }; - debug('emit "sdp"'); - - _this13.emit('sdp', e); - - return Promise.resolve(e.sdp); - } // Add 'pc.onicencandidate' event handler to resolve on last candidate. - - - return new Promise(function (resolve) { - var finished = false; - var iceCandidateListener; - var iceGatheringStateListener; - - var ready = function ready() { - connection.removeEventListener('icecandidate', iceCandidateListener); - connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener); - finished = true; - _this13._rtcReady = true; - var e = { - originator: 'local', - type: type, - sdp: connection.localDescription.sdp - }; - debug('emit "sdp"'); - - _this13.emit('sdp', e); - - resolve(e.sdp); - }; - - connection.addEventListener('icecandidate', iceCandidateListener = function iceCandidateListener(event) { - var candidate = event.candidate; - - if (candidate) { - _this13.emit('icecandidate', { - candidate: candidate, - ready: ready - }); - } else if (!finished) { - ready(); - } - }); - connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = function iceGatheringStateListener() { - if (connection.iceGatheringState === 'complete' && !finished) { - ready(); - } - }); - }); - }); - } - /** - * Dialog Management - */ - - }, { - key: "_createDialog", - value: function _createDialog(message, type, early) { - var local_tag = type === 'UAS' ? message.to_tag : message.from_tag; - var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag; - var id = message.call_id + local_tag + remote_tag; - var early_dialog = this._earlyDialogs[id]; // Early Dialog. - - if (early) { - if (early_dialog) { - return true; - } else { - early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created. - - if (early_dialog.error) { - debug(early_dialog.error); - - this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); - - return false; - } else { - this._earlyDialogs[id] = early_dialog; - return true; - } - } - } // Confirmed Dialog. - else { - this._from_tag = message.from_tag; - this._to_tag = message.to_tag; // In case the dialog is in _early_ state, update it. - - if (early_dialog) { - early_dialog.update(message, type); - this._dialog = early_dialog; - delete this._earlyDialogs[id]; - return true; - } // Otherwise, create a _confirmed_ dialog. - - - var dialog = new Dialog(this, message, type); - - if (dialog.error) { - debug(dialog.error); - - this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); - - return false; - } else { - this._dialog = dialog; - return true; - } - } - } - /** - * In dialog INVITE Reception - */ - - }, { - key: "_receiveReinvite", - value: function _receiveReinvite(request) { - var _this14 = this; - - debug('receiveReinvite()'); - var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; - var data = { - request: request, - callback: undefined, - reject: reject.bind(this) - }; - var rejected = false; - - function reject() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - rejected = true; - var status_code = options.status_code || 403; - var reason_phrase = options.reason_phrase || ''; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - - if (this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (status_code < 300 || status_code >= 700) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } - - request.reply(status_code, reason_phrase, extraHeaders); - } // Emit 'reinvite'. - - - this.emit('reinvite', data); - - if (rejected) { - return; - } - - this._late_sdp = false; // Request without SDP. - - if (!request.body) { - this._late_sdp = true; - - if (this._remoteHold) { - this._remoteHold = false; - - this._onunhold('remote'); - } - - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this14._createLocalDescription('offer', _this14._rtcOfferConstraints); - }).then(function (sdp) { - sendAnswer.call(_this14, sdp); - })["catch"](function () { - request.reply(500); - }); - return; - } // Request with SDP. - - - if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); - request.reply(415); - return; - } - - this._processInDialogSdpOffer(request) // Send answer. - .then(function (desc) { - if (_this14._status === C.STATUS_TERMINATED) { - return; - } - - sendAnswer.call(_this14, desc); - })["catch"](function (error) { - debugerror(error); - }); - - function sendAnswer(desc) { - var _this15 = this; - - var extraHeaders = ["Contact: ".concat(this._contact)]; - - this._handleSessionTimersInIncomingRequest(request, extraHeaders); - - if (this._late_sdp) { - desc = this._mangleOffer(desc); - } - - request.reply(200, null, extraHeaders, desc, function () { - _this15._status = C.STATUS_WAITING_FOR_ACK; - - _this15._setInvite2xxTimer(request, desc); - - _this15._setACKTimer(); - }); // If callback is given execute it. - - if (typeof data.callback === 'function') { - data.callback(); - } - } - } - /** - * In dialog UPDATE Reception - */ - - }, { - key: "_receiveUpdate", - value: function _receiveUpdate(request) { - var _this16 = this; - - debug('receiveUpdate()'); - var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; - var data = { - request: request, - callback: undefined, - reject: reject.bind(this) - }; - var rejected = false; - - function reject() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - rejected = true; - var status_code = options.status_code || 403; - var reason_phrase = options.reason_phrase || ''; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - - if (this._status !== C.STATUS_CONFIRMED) { - return false; - } - - if (status_code < 300 || status_code >= 700) { - throw new TypeError("Invalid status_code: ".concat(status_code)); - } - - request.reply(status_code, reason_phrase, extraHeaders); - } // Emit 'update'. - - - this.emit('update', data); - - if (rejected) { - return; - } - - if (!request.body) { - sendAnswer.call(this, null); - return; - } - - if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); - request.reply(415); - return; - } - - this._processInDialogSdpOffer(request) // Send answer. - .then(function (desc) { - if (_this16._status === C.STATUS_TERMINATED) { - return; - } - - sendAnswer.call(_this16, desc); - })["catch"](function (error) { - debugerror(error); - }); - - function sendAnswer(desc) { - var extraHeaders = ["Contact: ".concat(this._contact)]; - - this._handleSessionTimersInIncomingRequest(request, extraHeaders); - - request.reply(200, null, extraHeaders, desc); // If callback is given execute it. - - if (typeof data.callback === 'function') { - data.callback(); - } - } - } - }, { - key: "_processInDialogSdpOffer", - value: function _processInDialogSdpOffer(request) { - var _this17 = this; - - debug('_processInDialogSdpOffer()'); - var sdp = request.parseSDP(); - var hold = false; - - var _iterator4 = _createForOfIteratorHelper(sdp.media), - _step4; - - try { - for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - var m = _step4.value; - - if (holdMediaTypes.indexOf(m.type) === -1) { - continue; - } - - var direction = m.direction || sdp.direction || 'sendrecv'; - - if (direction === 'sendonly' || direction === 'inactive') { - hold = true; - } // If at least one of the streams is active don't emit 'hold'. - else { - hold = false; - break; - } - } - } catch (err) { - _iterator4.e(err); - } finally { - _iterator4.f(); - } - - var e = { - originator: 'remote', - type: 'offer', - sdp: request.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var offer = new RTCSessionDescription({ - type: 'offer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue // Set remote description. - .then(function () { - if (_this17._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - return _this17._connection.setRemoteDescription(offer)["catch"](function (error) { - request.reply(488); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this17.emit('peerconnection:setremotedescriptionfailed', error); - - throw error; - }); - }).then(function () { - if (_this17._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - if (_this17._remoteHold === true && hold === false) { - _this17._remoteHold = false; - - _this17._onunhold('remote'); - } else if (_this17._remoteHold === false && hold === true) { - _this17._remoteHold = true; - - _this17._onhold('remote'); - } - }) // Create local description. - .then(function () { - if (_this17._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) { - request.reply(500); - debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); - throw error; - }); - })["catch"](function (error) { - debugerror('_processInDialogSdpOffer() failed [error: %o]', error); - }); - return this._connectionPromiseQueue; - } - /** - * In dialog Refer Reception - */ - - }, { - key: "_receiveRefer", - value: function _receiveRefer(request) { - var _this18 = this; - - debug('receiveRefer()'); - - if (!request.refer_to) { - debug('no Refer-To header field present in REFER'); - request.reply(400); - return; - } - - if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { - debug('Refer-To header field points to a non-SIP URI scheme'); - request.reply(416); - return; - } // Reply before the transaction timer expires. - - - request.reply(202); - var notifier = new RTCSession_ReferNotifier(this, request.cseq); - debug('emit "refer"'); // Emit 'refer'. - - this.emit('refer', { - request: request, - accept: function accept(initCallback, options) { - _accept.call(_this18, initCallback, options); - }, - reject: function reject() { - _reject.call(_this18); - } - }); - - function _accept(initCallback) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - initCallback = typeof initCallback === 'function' ? initCallback : null; - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - var session = new RTCSession(this._ua); - session.on('progress', function (_ref2) { - var response = _ref2.response; - notifier.notify(response.status_code, response.reason_phrase); - }); - session.on('accepted', function (_ref3) { - var response = _ref3.response; - notifier.notify(response.status_code, response.reason_phrase); - }); - session.on('_failed', function (_ref4) { - var message = _ref4.message, - cause = _ref4.cause; - - if (message) { - notifier.notify(message.status_code, message.reason_phrase); - } else { - notifier.notify(487, cause); - } - }); // Consider the Replaces header present in the Refer-To URI. - - if (request.refer_to.uri.hasHeader('replaces')) { - var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces')); - options.extraHeaders = Utils.cloneArray(options.extraHeaders); - options.extraHeaders.push("Replaces: ".concat(replaces)); - } - - session.connect(request.refer_to.uri.toAor(), options, initCallback); - } - - function _reject() { - notifier.notify(603); - } - } - /** - * In dialog Notify Reception - */ - - }, { - key: "_receiveNotify", - value: function _receiveNotify(request) { - debug('receiveNotify()'); - - if (!request.event) { - request.reply(400); - } - - switch (request.event.event) { - case 'refer': - { - var id; - var referSubscriber; - - if (request.event.params && request.event.params.id) { - id = request.event.params.id; - referSubscriber = this._referSubscribers[id]; - } else if (Object.keys(this._referSubscribers).length === 1) { - referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]]; - } else { - request.reply(400, 'Missing event id parameter'); - return; - } - - if (!referSubscriber) { - request.reply(481, 'Subscription does not exist'); - return; - } - - referSubscriber.receiveNotify(request); - request.reply(200); - break; - } - - default: - { - request.reply(489); - } - } - } - /** - * INVITE with Replaces Reception - */ - - }, { - key: "_receiveReplaces", - value: function _receiveReplaces(request) { - var _this20 = this; - - debug('receiveReplaces()'); - - function _accept2(initCallback) { - var _this19 = this; - - if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { - return false; - } - - var session = new RTCSession(this._ua); // Terminate the current session when the new one is confirmed. - - session.on('confirmed', function () { - _this19.terminate(); - }); - session.init_incoming(request, initCallback); - } - - function _reject2() { - debug('Replaced INVITE rejected by the user'); - request.reply(486); - } // Emit 'replace'. - - - this.emit('replaces', { - request: request, - accept: function accept(initCallback) { - _accept2.call(_this20, initCallback); - }, - reject: function reject() { - _reject2.call(_this20); - } - }); - } - /** - * Initial Request Sender - */ - - }, { - key: "_sendInitialRequest", - value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) { - var _this21 = this; - - var request_sender = new RequestSender(this._ua, this._request, { - onRequestTimeout: function onRequestTimeout() { - _this21.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this21.onTransportError(); - }, - // Update the request on authentication. - onAuthenticated: function onAuthenticated(request) { - _this21._request = request; - }, - onReceiveResponse: function onReceiveResponse(response) { - _this21._receiveInviteResponse(response); - } - }); // This Promise is resolved within the next iteration, so the app has now - // a chance to set events such as 'peerconnection' and 'connecting'. - - Promise.resolve() // Get a stream if required. - .then(function () { - // A stream is given, let the app set events such as 'peerconnection' and 'connecting'. - if (mediaStream) { - return mediaStream; - } // Request for user media access. - else if (mediaConstraints.audio || mediaConstraints.video) { - _this21._localMediaStreamLocallyGenerated = true; - return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) { - if (_this21._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - - debugerror('emit "getusermediafailed" [error:%o]', error); - - _this21.emit('getusermediafailed', error); - - throw error; - }); - } - }).then(function (stream) { - if (_this21._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this21._localMediaStream = stream; - - if (stream) { - stream.getTracks().forEach(function (track) { - _this21._connection.addTrack(track, stream); - }); - } // TODO: should this be triggered here? - - - _this21._connecting(_this21._request); - - return _this21._createLocalDescription('offer', rtcOfferConstraints)["catch"](function (error) { - _this21._failed('local', null, JsSIP_C.causes.WEBRTC_ERROR); - - throw error; - }); - }).then(function (desc) { - if (_this21._is_canceled || _this21._status === C.STATUS_TERMINATED) { - throw new Error('terminated'); - } - - _this21._request.body = desc; - _this21._status = C.STATUS_INVITE_SENT; - debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. - - _this21.emit('sending', { - request: _this21._request - }); - - request_sender.send(); - })["catch"](function (error) { - if (_this21._status === C.STATUS_TERMINATED) { - return; - } - - debugerror(error); - }); - } - /** - * Get DTMF RTCRtpSender. - */ - - }, { - key: "_getDTMFRTPSender", - value: function _getDTMFRTPSender() { - var sender = this._connection.getSenders().find(function (rtpSender) { - return rtpSender.track && rtpSender.track.kind === 'audio'; - }); - - if (!(sender && sender.dtmf)) { - debugerror('sendDTMF() | no local audio track to send DTMF with'); - return; - } - - return sender.dtmf; - } - /** - * Reception of Response for Initial INVITE - */ - - }, { - key: "_receiveInviteResponse", - value: function _receiveInviteResponse(response) { - var _this22 = this; - - debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. - - if (this._dialog && response.status_code >= 200 && response.status_code <= 299) { - /* - * If it is a retransmission from the endpoint that established - * the dialog, send an ACK - */ - if (this._dialog.id.call_id === response.call_id && this._dialog.id.local_tag === response.from_tag && this._dialog.id.remote_tag === response.to_tag) { - this.sendRequest(JsSIP_C.ACK); - return; - } // If not, send an ACK and terminate. - else { - var dialog = new Dialog(this, response, 'UAC'); - - if (dialog.error !== undefined) { - debug(dialog.error); - return; - } - - this.sendRequest(JsSIP_C.ACK); - this.sendRequest(JsSIP_C.BYE); - return; - } - } // Proceed to cancellation if the user requested. - - - if (this._is_canceled) { - if (response.status_code >= 100 && response.status_code < 200) { - this._request.cancel(this._cancel_reason); - } else if (response.status_code >= 200 && response.status_code < 299) { - this._acceptAndTerminate(response); - } - - return; - } - - if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) { - return; - } - - switch (true) { - case /^100$/.test(response.status_code): - this._status = C.STATUS_1XX_RECEIVED; - break; - - case /^1[0-9]{2}$/.test(response.status_code): - { - // Do nothing with 1xx responses without To tag. - if (!response.to_tag) { - debug('1xx response received without to tag'); - break; - } // Create Early Dialog if 1XX comes with contact. - - - if (response.hasHeader('contact')) { - // An error on dialog creation will fire 'failed' event. - if (!this._createDialog(response, 'UAC', true)) { - break; - } - } - - this._status = C.STATUS_1XX_RECEIVED; - - if (!response.body) { - this._progress('remote', response); - - break; - } - - var e = { - originator: 'remote', - type: 'answer', - sdp: response.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var answer = new RTCSessionDescription({ - type: 'answer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this22._connection.setRemoteDescription(answer); - }).then(function () { - return _this22._progress('remote', response); - })["catch"](function (error) { - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this22.emit('peerconnection:setremotedescriptionfailed', error); - }); - break; - } - - case /^2[0-9]{2}$/.test(response.status_code): - { - this._status = C.STATUS_CONFIRMED; - - if (!response.body) { - this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP); - - this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - - break; - } // An error on dialog creation will fire 'failed' event. - - - if (!this._createDialog(response, 'UAC')) { - break; - } - - var _e = { - originator: 'remote', - type: 'answer', - sdp: response.body - }; - debug('emit "sdp"'); - this.emit('sdp', _e); - - var _answer = new RTCSessionDescription({ - type: 'answer', - sdp: _e.sdp - }); - - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - // Be ready for 200 with SDP after a 180/183 with SDP. - // We created a SDP 'answer' for it, so check the current signaling state. - if (_this22._connection.signalingState === 'stable') { - return _this22._connection.createOffer(_this22._rtcOfferConstraints).then(function (offer) { - return _this22._connection.setLocalDescription(offer); - })["catch"](function (error) { - _this22._acceptAndTerminate(response, 500, error.toString()); - - _this22._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR); - }); - } - }).then(function () { - _this22._connection.setRemoteDescription(_answer).then(function () { - // Handle Session Timers. - _this22._handleSessionTimersInIncomingResponse(response); - - _this22._accepted('remote', response); - - _this22.sendRequest(JsSIP_C.ACK); - - _this22._confirmed('local', null); - })["catch"](function (error) { - _this22._acceptAndTerminate(response, 488, 'Not Acceptable Here'); - - _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this22.emit('peerconnection:setremotedescriptionfailed', error); - }); - }); - break; - } - - default: - { - var cause = Utils.sipErrorCause(response.status_code); - - this._failed('remote', response, cause); - } - } - } - /** - * Send Re-INVITE - */ - - }, { - key: "_sendReinvite", - value: function _sendReinvite() { - var _this23 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendReinvite()'); - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; - var succeeded = false; - extraHeaders.push("Contact: ".concat(this._contact)); - extraHeaders.push('Content-Type: application/sdp'); // Session Timers. - - if (this._sessionTimers.running) { - extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas')); - } - - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this23._createLocalDescription('offer', rtcOfferConstraints); - }).then(function (sdp) { - sdp = _this23._mangleOffer(sdp); - var e = { - originator: 'local', - type: 'offer', - sdp: sdp - }; - debug('emit "sdp"'); - - _this23.emit('sdp', e); - - _this23.sendRequest(JsSIP_C.INVITE, { - extraHeaders: extraHeaders, - body: sdp, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - onSucceeded.call(_this23, response); - succeeded = true; - }, - onErrorResponse: function onErrorResponse(response) { - onFailed.call(_this23, response); - }, - onTransportError: function onTransportError() { - _this23.onTransportError(); // Do nothing because session ends. - - }, - onRequestTimeout: function onRequestTimeout() { - _this23.onRequestTimeout(); // Do nothing because session ends. - - }, - onDialogError: function onDialogError() { - _this23.onDialogError(); // Do nothing because session ends. - - } - } - }); - })["catch"](function () { - onFailed(); - }); - - function onSucceeded(response) { - var _this24 = this; - - if (this._status === C.STATUS_TERMINATED) { - return; - } - - this.sendRequest(JsSIP_C.ACK); // If it is a 2XX retransmission exit now. - - if (succeeded) { - return; - } // Handle Session Timers. - - - this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer. - - - if (!response.body) { - onFailed.call(this); - return; - } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') { - onFailed.call(this); - return; - } - - var e = { - originator: 'remote', - type: 'answer', - sdp: response.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var answer = new RTCSessionDescription({ - type: 'answer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this24._connection.setRemoteDescription(answer); - }).then(function () { - if (eventHandlers.succeeded) { - eventHandlers.succeeded(response); - } - })["catch"](function (error) { - onFailed.call(_this24); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this24.emit('peerconnection:setremotedescriptionfailed', error); - }); - } - - function onFailed(response) { - if (eventHandlers.failed) { - eventHandlers.failed(response); - } - } - } - /** - * Send UPDATE - */ - - }, { - key: "_sendUpdate", - value: function _sendUpdate() { - var _this25 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendUpdate()'); - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); - var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; - var sdpOffer = options.sdpOffer || false; - var succeeded = false; - extraHeaders.push("Contact: ".concat(this._contact)); // Session Timers. - - if (this._sessionTimers.running) { - extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas')); - } - - if (sdpOffer) { - extraHeaders.push('Content-Type: application/sdp'); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this25._createLocalDescription('offer', rtcOfferConstraints); - }).then(function (sdp) { - sdp = _this25._mangleOffer(sdp); - var e = { - originator: 'local', - type: 'offer', - sdp: sdp - }; - debug('emit "sdp"'); - - _this25.emit('sdp', e); - - _this25.sendRequest(JsSIP_C.UPDATE, { - extraHeaders: extraHeaders, - body: sdp, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - onSucceeded.call(_this25, response); - succeeded = true; - }, - onErrorResponse: function onErrorResponse(response) { - onFailed.call(_this25, response); - }, - onTransportError: function onTransportError() { - _this25.onTransportError(); // Do nothing because session ends. - - }, - onRequestTimeout: function onRequestTimeout() { - _this25.onRequestTimeout(); // Do nothing because session ends. - - }, - onDialogError: function onDialogError() { - _this25.onDialogError(); // Do nothing because session ends. - - } - } - }); - })["catch"](function () { - onFailed.call(_this25); - }); - } // No SDP. - else { - this.sendRequest(JsSIP_C.UPDATE, { - extraHeaders: extraHeaders, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - onSucceeded.call(_this25, response); - }, - onErrorResponse: function onErrorResponse(response) { - onFailed.call(_this25, response); - }, - onTransportError: function onTransportError() { - _this25.onTransportError(); // Do nothing because session ends. - - }, - onRequestTimeout: function onRequestTimeout() { - _this25.onRequestTimeout(); // Do nothing because session ends. - - }, - onDialogError: function onDialogError() { - _this25.onDialogError(); // Do nothing because session ends. - - } - } - }); - } - - function onSucceeded(response) { - var _this26 = this; - - if (this._status === C.STATUS_TERMINATED) { - return; - } // If it is a 2XX retransmission exit now. - - - if (succeeded) { - return; - } // Handle Session Timers. - - - this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer. - - - if (sdpOffer) { - if (!response.body) { - onFailed.call(this); - return; - } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') { - onFailed.call(this); - return; - } - - var e = { - originator: 'remote', - type: 'answer', - sdp: response.body - }; - debug('emit "sdp"'); - this.emit('sdp', e); - var answer = new RTCSessionDescription({ - type: 'answer', - sdp: e.sdp - }); - this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { - return _this26._connection.setRemoteDescription(answer); - }).then(function () { - if (eventHandlers.succeeded) { - eventHandlers.succeeded(response); - } - })["catch"](function (error) { - onFailed.call(_this26); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); - - _this26.emit('peerconnection:setremotedescriptionfailed', error); - }); - } // No SDP answer. - else if (eventHandlers.succeeded) { - eventHandlers.succeeded(response); - } - } - - function onFailed(response) { - if (eventHandlers.failed) { - eventHandlers.failed(response); - } - } - } - }, { - key: "_acceptAndTerminate", - value: function _acceptAndTerminate(response, status_code, reason_phrase) { - debug('acceptAndTerminate()'); - var extraHeaders = []; - - if (status_code) { - reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; - extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\"")); - } // An error on dialog creation will fire 'failed' event. - - - if (this._dialog || this._createDialog(response, 'UAC')) { - this.sendRequest(JsSIP_C.ACK); - this.sendRequest(JsSIP_C.BYE, { - extraHeaders: extraHeaders - }); - } // Update session status. - - - this._status = C.STATUS_TERMINATED; - } - /** - * Correctly set the SDP direction attributes if the call is on local hold - */ - - }, { - key: "_mangleOffer", - value: function _mangleOffer(sdp) { - if (!this._localHold && !this._remoteHold) { - return sdp; - } - - sdp = sdp_transform.parse(sdp); // Local hold. - - if (this._localHold && !this._remoteHold) { - debug('mangleOffer() | me on hold, mangling offer'); - - var _iterator5 = _createForOfIteratorHelper(sdp.media), - _step5; - - try { - for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { - var m = _step5.value; - - if (holdMediaTypes.indexOf(m.type) === -1) { - continue; - } - - if (!m.direction) { - m.direction = 'sendonly'; - } else if (m.direction === 'sendrecv') { - m.direction = 'sendonly'; - } else if (m.direction === 'recvonly') { - m.direction = 'inactive'; - } - } - } catch (err) { - _iterator5.e(err); - } finally { - _iterator5.f(); - } - } // Local and remote hold. - else if (this._localHold && this._remoteHold) { - debug('mangleOffer() | both on hold, mangling offer'); - - var _iterator6 = _createForOfIteratorHelper(sdp.media), - _step6; - - try { - for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { - var _m = _step6.value; - - if (holdMediaTypes.indexOf(_m.type) === -1) { - continue; - } - - _m.direction = 'inactive'; - } - } catch (err) { - _iterator6.e(err); - } finally { - _iterator6.f(); - } - } // Remote hold. - else if (this._remoteHold) { - debug('mangleOffer() | remote on hold, mangling offer'); - - var _iterator7 = _createForOfIteratorHelper(sdp.media), - _step7; - - try { - for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { - var _m2 = _step7.value; - - if (holdMediaTypes.indexOf(_m2.type) === -1) { - continue; - } - - if (!_m2.direction) { - _m2.direction = 'recvonly'; - } else if (_m2.direction === 'sendrecv') { - _m2.direction = 'recvonly'; - } else if (_m2.direction === 'recvonly') { - _m2.direction = 'inactive'; - } - } - } catch (err) { - _iterator7.e(err); - } finally { - _iterator7.f(); - } - } - - return sdp_transform.write(sdp); - } - }, { - key: "_setLocalMediaStatus", - value: function _setLocalMediaStatus() { - var enableAudio = true, - enableVideo = true; - - if (this._localHold || this._remoteHold) { - enableAudio = false; - enableVideo = false; - } - - if (this._audioMuted) { - enableAudio = false; - } - - if (this._videoMuted) { - enableVideo = false; - } - - this._toggleMuteAudio(!enableAudio); - - this._toggleMuteVideo(!enableVideo); - } - /** - * Handle SessionTimers for an incoming INVITE or UPDATE. - * @param {IncomingRequest} request - * @param {Array} responseExtraHeaders Extra headers for the 200 response. - */ - - }, { - key: "_handleSessionTimersInIncomingRequest", - value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) { - if (!this._sessionTimers.enabled) { - return; - } - - var session_expires_refresher; - - if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) { - this._sessionTimers.currentExpires = request.session_expires; - session_expires_refresher = request.session_expires_refresher || 'uas'; - } else { - this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires; - session_expires_refresher = 'uas'; - } - - responseExtraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(session_expires_refresher)); - this._sessionTimers.refresher = session_expires_refresher === 'uas'; - - this._runSessionTimer(); - } - /** - * Handle SessionTimers for an incoming response to INVITE or UPDATE. - * @param {IncomingResponse} response - */ - - }, { - key: "_handleSessionTimersInIncomingResponse", - value: function _handleSessionTimersInIncomingResponse(response) { - if (!this._sessionTimers.enabled) { - return; - } - - var session_expires_refresher; - - if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) { - this._sessionTimers.currentExpires = response.session_expires; - session_expires_refresher = response.session_expires_refresher || 'uac'; - } else { - this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires; - session_expires_refresher = 'uac'; - } - - this._sessionTimers.refresher = session_expires_refresher === 'uac'; - - this._runSessionTimer(); - } - }, { - key: "_runSessionTimer", - value: function _runSessionTimer() { - var _this27 = this; - - var expires = this._sessionTimers.currentExpires; - this._sessionTimers.running = true; - clearTimeout(this._sessionTimers.timer); // I'm the refresher. - - if (this._sessionTimers.refresher) { - this._sessionTimers.timer = setTimeout(function () { - if (_this27._status === C.STATUS_TERMINATED) { - return; - } - - debug('runSessionTimer() | sending session refresh request'); - - if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { - _this27._sendUpdate(); - } else { - _this27._sendReinvite(); - } - }, expires * 500); // Half the given interval (as the RFC states). - } // I'm not the refresher. - else { - this._sessionTimers.timer = setTimeout(function () { - if (_this27._status === C.STATUS_TERMINATED) { - return; - } - - debugerror('runSessionTimer() | timer expired, terminating the session'); - - _this27.terminate({ - cause: JsSIP_C.causes.REQUEST_TIMEOUT, - status_code: 408, - reason_phrase: 'Session Timer Expired' - }); - }, expires * 1100); - } - } - }, { - key: "_toggleMuteAudio", - value: function _toggleMuteAudio(mute) { - var senders = this._connection.getSenders().filter(function (sender) { - return sender.track && sender.track.kind === 'audio'; - }); - - var _iterator8 = _createForOfIteratorHelper(senders), - _step8; - - try { - for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { - var sender = _step8.value; - sender.track.enabled = !mute; - } - } catch (err) { - _iterator8.e(err); - } finally { - _iterator8.f(); - } - } - }, { - key: "_toggleMuteVideo", - value: function _toggleMuteVideo(mute) { - var senders = this._connection.getSenders().filter(function (sender) { - return sender.track && sender.track.kind === 'video'; - }); - - var _iterator9 = _createForOfIteratorHelper(senders), - _step9; - - try { - for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { - var sender = _step9.value; - sender.track.enabled = !mute; - } - } catch (err) { - _iterator9.e(err); - } finally { - _iterator9.f(); - } - } - }, { - key: "_newRTCSession", - value: function _newRTCSession(originator, request) { - debug('newRTCSession()'); - - this._ua.newRTCSession(this, { - originator: originator, - session: this, - request: request - }); - } - }, { - key: "_connecting", - value: function _connecting(request) { - debug('session connecting'); - debug('emit "connecting"'); - this.emit('connecting', { - request: request - }); - } - }, { - key: "_progress", - value: function _progress(originator, response) { - debug('session progress'); - debug('emit "progress"'); - this.emit('progress', { - originator: originator, - response: response || null - }); - } - }, { - key: "_accepted", - value: function _accepted(originator, message) { - debug('session accepted'); - this._start_time = new Date(); - debug('emit "accepted"'); - this.emit('accepted', { - originator: originator, - response: message || null - }); - } - }, { - key: "_confirmed", - value: function _confirmed(originator, ack) { - debug('session confirmed'); - this._is_confirmed = true; - debug('emit "confirmed"'); - this.emit('confirmed', { - originator: originator, - ack: ack || null - }); - } - }, { - key: "_ended", - value: function _ended(originator, message, cause) { - debug('session ended'); - this._end_time = new Date(); - - this._close(); - - debug('emit "ended"'); - this.emit('ended', { - originator: originator, - message: message || null, - cause: cause - }); - } - }, { - key: "_failed", - value: function _failed(originator, message, cause) { - debug('session failed'); // Emit private '_failed' event first. - - debug('emit "_failed"'); - this.emit('_failed', { - originator: originator, - message: message || null, - cause: cause - }); - - this._close(); - - debug('emit "failed"'); - this.emit('failed', { - originator: originator, - message: message || null, - cause: cause - }); - } - }, { - key: "_onhold", - value: function _onhold(originator) { - debug('session onhold'); - - this._setLocalMediaStatus(); - - debug('emit "hold"'); - this.emit('hold', { - originator: originator - }); - } - }, { - key: "_onunhold", - value: function _onunhold(originator) { - debug('session onunhold'); - - this._setLocalMediaStatus(); - - debug('emit "unhold"'); - this.emit('unhold', { - originator: originator - }); - } - }, { - key: "_onmute", - value: function _onmute(_ref5) { - var audio = _ref5.audio, - video = _ref5.video; - debug('session onmute'); - - this._setLocalMediaStatus(); - - debug('emit "muted"'); - this.emit('muted', { - audio: audio, - video: video - }); - } - }, { - key: "_onunmute", - value: function _onunmute(_ref6) { - var audio = _ref6.audio, - video = _ref6.video; - debug('session onunmute'); - - this._setLocalMediaStatus(); - - debug('emit "unmuted"'); - this.emit('unmuted', { - audio: audio, - video: video - }); - } - }], [{ - key: "C", - get: - /** - * Expose C object. - */ - function get() { - return C; - } - }]); - - return RTCSession; -}(EventEmitter); -},{"./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(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('../Constants'); - -var Exceptions = require('../Exceptions'); - -var Utils = require('../Utils'); - -var debug = require('debug')('JsSIP:RTCSession:DTMF'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); - -debugerror.log = console.warn.bind(console); -var C = { - MIN_DURATION: 70, - MAX_DURATION: 6000, - DEFAULT_DURATION: 100, - MIN_INTER_TONE_GAP: 50, - DEFAULT_INTER_TONE_GAP: 500 -}; - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(DTMF, _EventEmitter); - - var _super = _createSuper(DTMF); - - function DTMF(session) { - var _this; - - _classCallCheck(this, DTMF); - - _this = _super.call(this); - _this._session = session; - _this._direction = null; - _this._tone = null; - _this._duration = null; - _this._request = null; - return _this; - } - - _createClass(DTMF, [{ - key: "tone", - get: function get() { - return this._tone; - } - }, { - key: "duration", - get: function get() { - return this._duration; - } - }, { - key: "send", - value: function send(tone) { - var _this2 = this; - - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - - if (tone === undefined) { - throw new TypeError('Not enough arguments'); - } - - this._direction = 'outgoing'; // Check RTCSession Status. - - if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) { - throw new Exceptions.InvalidStateError(this._session.status); - } - - var extraHeaders = Utils.cloneArray(options.extraHeaders); - this.eventHandlers = Utils.cloneObject(options.eventHandlers); // Check tone type. - - if (typeof tone === 'string') { - tone = tone.toUpperCase(); - } else if (typeof tone === 'number') { - tone = tone.toString(); - } else { - throw new TypeError("Invalid tone: ".concat(tone)); - } // Check tone value. - - - if (!tone.match(/^[0-9A-DR#*]$/)) { - throw new TypeError("Invalid tone: ".concat(tone)); - } else { - this._tone = tone; - } // Duration is checked/corrected in RTCSession. - - - this._duration = options.duration; - extraHeaders.push('Content-Type: application/dtmf-relay'); - var body = "Signal=".concat(this._tone, "\r\n"); - body += "Duration=".concat(this._duration); - - this._session.newDTMF({ - originator: 'local', - dtmf: this, - request: this._request - }); - - this._session.sendRequest(JsSIP_C.INFO, { - extraHeaders: extraHeaders, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - _this2.emit('succeeded', { - originator: 'remote', - response: response - }); - }, - onErrorResponse: function onErrorResponse(response) { - if (_this2.eventHandlers.onFailed) { - _this2.eventHandlers.onFailed(); - } - - _this2.emit('failed', { - originator: 'remote', - response: response - }); - }, - onRequestTimeout: function onRequestTimeout() { - _this2._session.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this2._session.onTransportError(); - }, - onDialogError: function onDialogError() { - _this2._session.onDialogError(); - } - }, - body: body - }); - } - }, { - key: "init_incoming", - value: function init_incoming(request) { - var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/; - var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/; - this._direction = 'incoming'; - this._request = request; - request.reply(200); - - if (request.body) { - var body = request.body.split('\n'); - - if (body.length >= 1) { - if (reg_tone.test(body[0])) { - this._tone = body[0].replace(reg_tone, '$2'); - } - } - - if (body.length >= 2) { - if (reg_duration.test(body[1])) { - this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10); - } - } - } - - if (!this._duration) { - this._duration = C.DEFAULT_DURATION; - } - - if (!this._tone) { - debug('invalid INFO DTMF received, discarded'); - } else { - this._session.newDTMF({ - originator: 'remote', - dtmf: this, - request: request - }); - } - } - }]); - - return DTMF; -}(EventEmitter); -/** - * Expose C object. - */ - - -module.exports.C = C; -},{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],14:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); - -debugerror.log = console.warn.bind(console); - -var JsSIP_C = require('../Constants'); - -var Exceptions = require('../Exceptions'); - -var Utils = require('../Utils'); - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(Info, _EventEmitter); - - var _super = _createSuper(Info); - - function Info(session) { - var _this; - - _classCallCheck(this, Info); - - _this = _super.call(this); - _this._session = session; - _this._direction = null; - _this._contentType = null; - _this._body = null; - return _this; - } - - _createClass(Info, [{ - key: "contentType", - get: function get() { - return this._contentType; - } - }, { - key: "body", - get: function get() { - return this._body; - } - }, { - key: "send", - value: function send(contentType, body) { - var _this2 = this; - - var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - this._direction = 'outgoing'; - - if (contentType === undefined) { - throw new TypeError('Not enough arguments'); - } // Check RTCSession Status. - - - if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) { - throw new Exceptions.InvalidStateError(this._session.status); - } - - this._contentType = contentType; - this._body = body; - var extraHeaders = Utils.cloneArray(options.extraHeaders); - extraHeaders.push("Content-Type: ".concat(contentType)); - - this._session.newInfo({ - originator: 'local', - info: this, - request: this.request - }); - - this._session.sendRequest(JsSIP_C.INFO, { - extraHeaders: extraHeaders, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - _this2.emit('succeeded', { - originator: 'remote', - response: response - }); - }, - onErrorResponse: function onErrorResponse(response) { - _this2.emit('failed', { - originator: 'remote', - response: response - }); - }, - onTransportError: function onTransportError() { - _this2._session.onTransportError(); - }, - onRequestTimeout: function onRequestTimeout() { - _this2._session.onRequestTimeout(); - }, - onDialogError: function onDialogError() { - _this2._session.onDialogError(); - } - }, - body: body - }); - } - }, { - key: "init_incoming", - value: function init_incoming(request) { - this._direction = 'incoming'; - this.request = request; - request.reply(200); - this._contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; - this._body = request.body; - - this._session.newInfo({ - originator: 'remote', - info: this, - request: request - }); - } - }]); - - return Info; -}(EventEmitter); -},{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],15:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var JsSIP_C = require('../Constants'); - -var debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); - -var C = { - event_type: 'refer', - body_type: 'message/sipfrag;version=2.0', - expires: 300 -}; - -module.exports = /*#__PURE__*/function () { - function ReferNotifier(session, id, expires) { - _classCallCheck(this, ReferNotifier); - - this._session = session; - this._id = id; - this._expires = expires || C.expires; - this._active = true; // The creation of a Notifier results in an immediate NOTIFY. - - this.notify(100); - } - - _createClass(ReferNotifier, [{ - key: "notify", - value: function notify(code, reason) { - debug('notify()'); - - if (this._active === false) { - return; - } - - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - var state; - - if (code >= 200) { - state = 'terminated;reason=noresource'; - } else { - state = "active;expires=".concat(this._expires); - } // Put this in a try/catch block. - - - this._session.sendRequest(JsSIP_C.NOTIFY, { - extraHeaders: ["Event: ".concat(C.event_type, ";id=").concat(this._id), "Subscription-State: ".concat(state), "Content-Type: ".concat(C.body_type)], - body: "SIP/2.0 ".concat(code, " ").concat(reason), - eventHandlers: { - // If a negative response is received, subscription is canceled. - onErrorResponse: function onErrorResponse() { - this._active = false; - } - } - }); - } - }]); - - return ReferNotifier; -}(); -},{"../Constants":2,"debug":30}],16:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('../Constants'); - -var Grammar = require('../Grammar'); - -var Utils = require('../Utils'); - -var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(ReferSubscriber, _EventEmitter); - - var _super = _createSuper(ReferSubscriber); - - function ReferSubscriber(session) { - var _this; - - _classCallCheck(this, ReferSubscriber); - - _this = _super.call(this); - _this._id = null; - _this._session = session; - return _this; - } - - _createClass(ReferSubscriber, [{ - key: "id", - get: function get() { - return this._id; - } - }, { - key: "sendRefer", - value: function sendRefer(target) { - var _this2 = this; - - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendRefer()'); - var extraHeaders = Utils.cloneArray(options.extraHeaders); - var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers. - - for (var event in eventHandlers) { - if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { - this.on(event, eventHandlers[event]); - } - } // Replaces URI header field. - - - var replaces = null; - - if (options.replaces) { - replaces = options.replaces._request.call_id; - replaces += ";to-tag=".concat(options.replaces._to_tag); - replaces += ";from-tag=".concat(options.replaces._from_tag); - replaces = encodeURIComponent(replaces); - } // Refer-To header field. - - - var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">"); - extraHeaders.push(referTo); // Referred-By header field. - - var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); - extraHeaders.push(referredBy); - extraHeaders.push("Contact: ".concat(this._session.contact)); - - var request = this._session.sendRequest(JsSIP_C.REFER, { - extraHeaders: extraHeaders, - eventHandlers: { - onSuccessResponse: function onSuccessResponse(response) { - _this2._requestSucceeded(response); - }, - onErrorResponse: function onErrorResponse(response) { - _this2._requestFailed(response, JsSIP_C.causes.REJECTED); - }, - onTransportError: function onTransportError() { - _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR); - }, - onRequestTimeout: function onRequestTimeout() { - _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT); - }, - onDialogError: function onDialogError() { - _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR); - } - } - }); - - this._id = request.cseq; - } - }, { - key: "receiveNotify", - value: function receiveNotify(request) { - debug('receiveNotify()'); - - if (!request.body) { - return; - } - - var status_line = Grammar.parse(request.body.trim(), 'Status_Line'); - - if (status_line === -1) { - debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); - return; - } - - switch (true) { - case /^100$/.test(status_line.status_code): - this.emit('trying', { - request: request, - status_line: status_line - }); - break; - - case /^1[0-9]{2}$/.test(status_line.status_code): - this.emit('progress', { - request: request, - status_line: status_line - }); - break; - - case /^2[0-9]{2}$/.test(status_line.status_code): - this.emit('accepted', { - request: request, - status_line: status_line - }); - break; - - default: - this.emit('failed', { - request: request, - status_line: status_line - }); - break; - } - } - }, { - key: "_requestSucceeded", - value: function _requestSucceeded(response) { - debug('REFER succeeded'); - debug('emit "requestSucceeded"'); - this.emit('requestSucceeded', { - response: response - }); - } - }, { - key: "_requestFailed", - value: function _requestFailed(response, cause) { - debug('REFER failed'); - debug('emit "requestFailed"'); - this.emit('requestFailed', { - response: response || null, - cause: cause - }); - } - }]); - - return ReferSubscriber; -}(EventEmitter); -},{"../Constants":2,"../Grammar":7,"../Utils":26,"debug":30,"events":29}],17:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Utils = require('./Utils'); - -var JsSIP_C = require('./Constants'); - -var SIPMessage = require('./SIPMessage'); - -var RequestSender = require('./RequestSender'); - -var debug = require('debug')('JsSIP:Registrator'); - -var MIN_REGISTER_EXPIRES = 10; // In seconds. - -module.exports = /*#__PURE__*/function () { - function Registrator(ua, transport) { - _classCallCheck(this, Registrator); - - var reg_id = 1; // Force reg_id to 1. - - this._ua = ua; - this._transport = transport; - this._registrar = ua.configuration.registrar_server; - this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2. - - this._call_id = Utils.createRandomToken(22); - this._cseq = 0; - this._to_uri = ua.configuration.uri; - this._registrationTimer = null; // Ongoing Register request. - - this._registering = false; // Set status. - - this._registered = false; // Contact header. - - this._contact = this._ua.contact.toString(); // Sip.ice media feature tag (RFC 5768). - - this._contact += ';+sip.ice'; // Custom headers for REGISTER and un-REGISTER. - - this._extraHeaders = []; // Custom Contact header params for REGISTER and un-REGISTER. - - this._extraContactParams = ''; - - if (reg_id) { - this._contact += ";reg-id=".concat(reg_id); - this._contact += ";+sip.instance=\"\""); - } - } - - _createClass(Registrator, [{ - key: "registered", - get: function get() { - return this._registered; - } - }, { - key: "setExtraHeaders", - value: function setExtraHeaders(extraHeaders) { - if (!Array.isArray(extraHeaders)) { - extraHeaders = []; - } - - this._extraHeaders = extraHeaders.slice(); - } - }, { - key: "setExtraContactParams", - value: function setExtraContactParams(extraContactParams) { - if (!(extraContactParams instanceof Object)) { - extraContactParams = {}; - } // Reset it. - - - this._extraContactParams = ''; - - for (var param_key in extraContactParams) { - if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) { - var param_value = extraContactParams[param_key]; - this._extraContactParams += ";".concat(param_key); - - if (param_value) { - this._extraContactParams += "=".concat(param_value); - } - } - } - } - }, { - key: "register", - value: function register() { - var _this = this; - - if (this._registering) { - debug('Register request in progress...'); - return; - } - - var extraHeaders = this._extraHeaders.slice(); - - extraHeaders.push("Contact: ".concat(this._contact, ";expires=").concat(this._expires).concat(this._extraContactParams)); - extraHeaders.push("Expires: ".concat(this._expires)); - var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, { - 'to_uri': this._to_uri, - 'call_id': this._call_id, - 'cseq': this._cseq += 1 - }, extraHeaders); - var request_sender = new RequestSender(this._ua, request, { - onRequestTimeout: function onRequestTimeout() { - _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT); - }, - onTransportError: function onTransportError() { - _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR); - }, - // Increase the CSeq on authentication. - onAuthenticated: function onAuthenticated() { - _this._cseq += 1; - }, - onReceiveResponse: function onReceiveResponse(response) { - // Discard responses to older REGISTER/un-REGISTER requests. - if (response.cseq !== _this._cseq) { - return; - } // Clear registration timer. - - - if (_this._registrationTimer !== null) { - clearTimeout(_this._registrationTimer); - _this._registrationTimer = null; - } - - switch (true) { - case /^1[0-9]{2}$/.test(response.status_code): - { - // Ignore provisional responses. - break; - } - - case /^2[0-9]{2}$/.test(response.status_code): - { - _this._registering = false; - - if (!response.hasHeader('Contact')) { - debug('no Contact header in response to REGISTER, response ignored'); - break; - } - - var contacts = response.headers['Contact'].reduce(function (a, b) { - return a.concat(b.parsed); - }, []); // Get the Contact pointing to us and update the expires value accordingly. - - var contact = contacts.find(function (element) { - return element.uri.user === _this._ua.contact.uri.user; - }); - - if (!contact) { - debug('no Contact header pointing to us, response ignored'); - break; - } - - var expires = contact.getParam('expires'); - - if (!expires && response.hasHeader('expires')) { - expires = response.getHeader('expires'); - } - - if (!expires) { - expires = _this._expires; - } - - expires = Number(expires); - if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES; - var timeout = expires > 64 ? expires * 1000 / 2 + Math.floor((expires / 2 - 32) * 1000 * Math.random()) : expires * 1000 - 5000; // Re-Register or emit an event before the expiration interval has elapsed. - // For that, decrease the expires value. ie: 3 seconds. - - _this._registrationTimer = setTimeout(function () { - _this._registrationTimer = null; // If there are no listeners for registrationExpiring, renew registration. - // If there are listeners, let the function listening do the register call. - - if (_this._ua.listeners('registrationExpiring').length === 0) { - _this.register(); - } else { - _this._ua.emit('registrationExpiring'); - } - }, timeout); // Save gruu values. - - if (contact.hasParam('temp-gruu')) { - _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, ''); - } - - if (contact.hasParam('pub-gruu')) { - _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, ''); - } - - if (!_this._registered) { - _this._registered = true; - - _this._ua.registered({ - response: response - }); - } - - break; - } - // Interval too brief RFC3261 10.2.8. - - case /^423$/.test(response.status_code): - { - if (response.hasHeader('min-expires')) { - // Increase our registration interval to the suggested minimum. - _this._expires = Number(response.getHeader('min-expires')); - if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES; // Attempt the registration again immediately. - - _this.register(); - } else { - // This response MUST contain a Min-Expires header field. - debug('423 response received for REGISTER without Min-Expires'); - - _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); - } - - break; - } - - default: - { - var cause = Utils.sipErrorCause(response.status_code); - - _this._registrationFailure(response, cause); - } - } - } - }); - this._registering = true; - request_sender.send(); - } - }, { - key: "unregister", - value: function unregister() { - var _this2 = this; - - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - if (!this._registered) { - debug('already unregistered'); - return; - } - - this._registered = false; // Clear the registration timer. - - if (this._registrationTimer !== null) { - clearTimeout(this._registrationTimer); - this._registrationTimer = null; - } - - var extraHeaders = this._extraHeaders.slice(); - - if (options.all) { - extraHeaders.push("Contact: *".concat(this._extraContactParams)); - } else { - extraHeaders.push("Contact: ".concat(this._contact, ";expires=0").concat(this._extraContactParams)); - } - - extraHeaders.push('Expires: 0'); - var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, { - 'to_uri': this._to_uri, - 'call_id': this._call_id, - 'cseq': this._cseq += 1 - }, extraHeaders); - var request_sender = new RequestSender(this._ua, request, { - onRequestTimeout: function onRequestTimeout() { - _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT); - }, - onTransportError: function onTransportError() { - _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR); - }, - // Increase the CSeq on authentication. - onAuthenticated: function onAuthenticated() { - _this2._cseq += 1; - }, - onReceiveResponse: function onReceiveResponse(response) { - switch (true) { - case /^1[0-9]{2}$/.test(response.status_code): - // Ignore provisional responses. - break; - - case /^2[0-9]{2}$/.test(response.status_code): - _this2._unregistered(response); - - break; - - default: - { - var cause = Utils.sipErrorCause(response.status_code); - - _this2._unregistered(response, cause); - } - } - } - }); - request_sender.send(); - } - }, { - key: "close", - value: function close() { - if (this._registered) { - this.unregister(); - } - } - }, { - key: "onTransportClosed", - value: function onTransportClosed() { - this._registering = false; - - if (this._registrationTimer !== null) { - clearTimeout(this._registrationTimer); - this._registrationTimer = null; - } - - if (this._registered) { - this._registered = false; - - this._ua.unregistered({}); - } - } - }, { - key: "_registrationFailure", - value: function _registrationFailure(response, cause) { - this._registering = false; - - this._ua.registrationFailed({ - response: response || null, - cause: cause - }); - - if (this._registered) { - this._registered = false; - - this._ua.unregistered({ - response: response || null, - cause: cause - }); - } - } - }, { - key: "_unregistered", - value: function _unregistered(response, cause) { - this._registering = false; - this._registered = false; - - this._ua.unregistered({ - response: response || null, - cause: cause || null - }); - } - }]); - - return Registrator; -}(); -},{"./Constants":2,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30}],18:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var JsSIP_C = require('./Constants'); - -var DigestAuthentication = require('./DigestAuthentication'); - -var Transactions = require('./Transactions'); - -var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers. - - -var EventHandlers = { - onRequestTimeout: function onRequestTimeout() {}, - onTransportError: function onTransportError() {}, - onReceiveResponse: function onReceiveResponse() {}, - onAuthenticated: function onAuthenticated() {} -}; - -module.exports = /*#__PURE__*/function () { - // Igor's extension: alternative credential - function RequestSender(ua, request, eventHandlers) { - var config2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; - - _classCallCheck(this, RequestSender); - - this._ua = ua; - this._eventHandlers = eventHandlers; - this._method = request.method; - this._request = request; - this._auth = null; - this._challenged = false; - this._staled = false; - this._config2 = config2; // Define the undefined handlers. - - for (var handler in EventHandlers) { - if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { - if (!this._eventHandlers[handler]) { - this._eventHandlers[handler] = EventHandlers[handler]; - } - } - } // If ua is in closing process or even closed just allow sending Bye and ACK. - - - if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) { - this._eventHandlers.onTransportError(); - } - } - /** - * Create the client transaction and send the message. - */ - - - _createClass(RequestSender, [{ - key: "send", - value: function send() { - var _this = this; - - var eventHandlers = { - onRequestTimeout: function onRequestTimeout() { - _this._eventHandlers.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this._eventHandlers.onTransportError(); - }, - onReceiveResponse: function onReceiveResponse(response) { - _this._receiveResponse(response); - } - }; - - switch (this._method) { - case 'INVITE': - this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); - break; - - case 'ACK': - this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); - break; - - default: - this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); - } // If authorization JWT is present, use it. - - - if (this._ua._configuration.authorization_jwt) { - this._request.setHeader('Authorization', this._ua._configuration.authorization_jwt); - } - - this.clientTransaction.send(); - } - /** - * Called from client transaction when receiving a correct response to the request. - * Authenticate request if needed or pass the response back to the applicant. - */ - - }, { - key: "_receiveResponse", - value: function _receiveResponse(response) { - var challenge; - var authorization_header_name; - var status_code = response.status_code; - /* - * Authentication - * Authenticate once. _challenged_ flag used to avoid infinite authentications. - */ - - if ((status_code === 401 || status_code === 407) && (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { - // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. - if (response.status_code === 401) { - challenge = response.parseHeader('www-authenticate'); - authorization_header_name = 'authorization'; - } else { - challenge = response.parseHeader('proxy-authenticate'); - authorization_header_name = 'proxy-authorization'; - } // Verify it seems a valid challenge. - - - if (!challenge) { - debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); - - this._eventHandlers.onReceiveResponse(response); - - return; - } - - if (!this._challenged || !this._staled && challenge.stale === true) { - if (!this._auth) { - var cnf = this._config2 ? this._config2 : this._ua.configuration; - this._auth = new DigestAuthentication({ - username: cnf.authorization_user, - password: cnf.password, - realm: cnf.realm, - ha1: cnf.ha1 - }); - } // Verify that the challenge is really valid. - - - if (!this._auth.authenticate(this._request, challenge)) { - this._eventHandlers.onReceiveResponse(response); - - return; - } - - this._challenged = true; // Update ha1 and realm in the UA or in alternative config. - - if (!this._config2) { - this._ua.set('realm', this._auth.get('realm')); - - this._ua.set('ha1', this._auth.get('ha1')); - } else { - this._config2.realm = this._auth.get('realm'); - this._config2.ha1 = this._auth.get('ha1'); - } - - if (challenge.stale) { - this._staled = true; - } - - this._request = this._request.clone(); - this._request.cseq += 1; - - this._request.setHeader('cseq', "".concat(this._request.cseq, " ").concat(this._method)); - - this._request.setHeader(authorization_header_name, this._auth.toString()); - - this._eventHandlers.onAuthenticated(this._request); - - this.send(); - } else { - this._eventHandlers.onReceiveResponse(response); - } - } else { - this._eventHandlers.onReceiveResponse(response); - } - } - }]); - - return RequestSender; -}(); -},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":22,"debug":30}],19:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var sdp_transform = require('sdp-transform'); - -var JsSIP_C = require('./Constants'); - -var Utils = require('./Utils'); - -var NameAddrHeader = require('./NameAddrHeader'); - -var Grammar = require('./Grammar'); - -var debug = require('debug')('JsSIP:SIPMessage'); -/** - * -param {String} method request method - * -param {String} ruri request uri - * -param {UA} ua - * -param {Object} params parameters that will have priority over ua.configuration parameters: - *
- * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set - * -param {Object} [headers] extra headers - * -param {String} [body] - */ - - -var OutgoingRequest = /*#__PURE__*/function () { - function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) { - _classCallCheck(this, OutgoingRequest); - - // Mandatory parameters check. - if (!method || !ruri || !ua) { - return null; - } - - params = params || {}; - this.ua = ua; - this.headers = {}; - this.method = method; - this.ruri = ruri; - this.body = body; - this.extraHeaders = Utils.cloneArray(extraHeaders); // Fill the Common SIP Request Headers. - // Route. - - if (params.route_set) { - this.setHeader('route', params.route_set); - } else if (ua.configuration.use_preloaded_route) { - this.setHeader('route', "<".concat(ua.transport.sip_uri, ";lr>")); - } // Via. - // Empty Via header. Will be filled by the client transaction. - - - this.setHeader('via', ''); // Max-Forwards. - - this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS); // To - - var to_uri = params.to_uri || ruri; - var to_params = params.to_tag ? { - tag: params.to_tag - } : null; - var to_display_name = typeof params.to_display_name !== 'undefined' ? params.to_display_name : null; - this.to = new NameAddrHeader(to_uri, to_display_name, to_params); - this.setHeader('to', this.to.toString()); // From. - - var from_uri = params.from_uri || ua.configuration.uri; - var from_params = { - tag: params.from_tag || Utils.newTag() - }; - var display_name; - - if (typeof params.from_display_name !== 'undefined') { - display_name = params.from_display_name; - } else if (ua.configuration.display_name) { - display_name = ua.configuration.display_name; - } else { - display_name = null; - } - - this.from = new NameAddrHeader(from_uri, display_name, from_params); - this.setHeader('from', this.from.toString()); // Call-ID. - - var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15); - this.call_id = call_id; - this.setHeader('call-id', call_id); // CSeq. - - var cseq = params.cseq || Math.floor(Math.random() * 10000); - this.cseq = cseq; - this.setHeader('cseq', "".concat(cseq, " ").concat(method)); - } - /** - * Replace the the given header by the given value. - * -param {String} name header name - * -param {String | Array} value header value - */ - - - _createClass(OutgoingRequest, [{ - key: "setHeader", - value: function setHeader(name, value) { - // Remove the header from extraHeaders if present. - var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); - - for (var idx = 0; idx < this.extraHeaders.length; idx++) { - if (regexp.test(this.extraHeaders[idx])) { - this.extraHeaders.splice(idx, 1); - } - } - - this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value]; - } - /** - * Get the value of the given header name at the given position. - * -param {String} name header name - * -returns {String|undefined} Returns the specified header, null if header doesn't exist. - */ - - }, { - key: "getHeader", - value: function getHeader(name) { - var headers = this.headers[Utils.headerize(name)]; - - if (headers) { - if (headers[0]) { - return headers[0]; - } - } else { - var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); - - var _iterator = _createForOfIteratorHelper(this.extraHeaders), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var header = _step.value; - - if (regexp.test(header)) { - return header.substring(header.indexOf(':') + 1).trim(); - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } - - return; - } - /** - * Get the header/s of the given name. - * -param {String} name header name - * -returns {Array} Array with all the headers of the specified name. - */ - - }, { - key: "getHeaders", - value: function getHeaders(name) { - var headers = this.headers[Utils.headerize(name)]; - var result = []; - - if (headers) { - var _iterator2 = _createForOfIteratorHelper(headers), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var header = _step2.value; - result.push(header); - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - - return result; - } else { - var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); - - var _iterator3 = _createForOfIteratorHelper(this.extraHeaders), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var _header = _step3.value; - - if (regexp.test(_header)) { - result.push(_header.substring(_header.indexOf(':') + 1).trim()); - } - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } - - return result; - } - } - /** - * Verify the existence of the given header. - * -param {String} name header name - * -returns {boolean} true if header with given name exists, false otherwise - */ - - }, { - key: "hasHeader", - value: function hasHeader(name) { - if (this.headers[Utils.headerize(name)]) { - return true; - } else { - var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); - - var _iterator4 = _createForOfIteratorHelper(this.extraHeaders), - _step4; - - try { - for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - var header = _step4.value; - - if (regexp.test(header)) { - return true; - } - } - } catch (err) { - _iterator4.e(err); - } finally { - _iterator4.f(); - } - } - - return false; - } - /** - * Parse the current body as a SDP and store the resulting object - * into this.sdp. - * -param {Boolean} force: Parse even if this.sdp already exists. - * - * Returns this.sdp. - */ - - }, { - key: "parseSDP", - value: function parseSDP(force) { - if (!force && this.sdp) { - return this.sdp; - } else { - this.sdp = sdp_transform.parse(this.body || ''); - return this.sdp; - } - } - }, { - key: "toString", - value: function toString() { - var msg = "".concat(this.method, " ").concat(this.ruri, " SIP/2.0\r\n"); - - for (var headerName in this.headers) { - if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) { - var _iterator5 = _createForOfIteratorHelper(this.headers[headerName]), - _step5; - - try { - for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { - var headerValue = _step5.value; - msg += "".concat(headerName, ": ").concat(headerValue, "\r\n"); - } - } catch (err) { - _iterator5.e(err); - } finally { - _iterator5.f(); - } - } - } - - var _iterator6 = _createForOfIteratorHelper(this.extraHeaders), - _step6; - - try { - for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { - var header = _step6.value; - msg += "".concat(header.trim(), "\r\n"); - } // Supported. - - } catch (err) { - _iterator6.e(err); - } finally { - _iterator6.f(); - } - - var supported = []; - - switch (this.method) { - case JsSIP_C.REGISTER: - supported.push('path', 'gruu'); - break; - - case JsSIP_C.INVITE: - if (this.ua.configuration.session_timers) { - supported.push('timer'); - } - - if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) { - supported.push('gruu'); - } - - supported.push('ice', 'replaces'); - break; - - case JsSIP_C.UPDATE: - if (this.ua.configuration.session_timers) { - supported.push('timer'); - } - - supported.push('ice'); - break; - } - - supported.push('outbound'); - var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT; // Allow. - - msg += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); - msg += "Supported: ".concat(supported, "\r\n"); - msg += "User-Agent: ".concat(userAgent, "\r\n"); - - if (this.body) { - var length = Utils.str_utf8_length(this.body); - msg += "Content-Length: ".concat(length, "\r\n\r\n"); - msg += this.body; - } else { - msg += 'Content-Length: 0\r\n\r\n'; - } - - return msg; - } - }, { - key: "clone", - value: function clone() { - var request = new OutgoingRequest(this.method, this.ruri, this.ua); - Object.keys(this.headers).forEach(function (name) { - request.headers[name] = this.headers[name].slice(); - }, this); - request.body = this.body; - request.extraHeaders = Utils.cloneArray(this.extraHeaders); - request.to = this.to; - request.from = this.from; - request.call_id = this.call_id; - request.cseq = this.cseq; - return request; - } - }]); - - return OutgoingRequest; -}(); - -var InitialOutgoingInviteRequest = /*#__PURE__*/function (_OutgoingRequest) { - _inherits(InitialOutgoingInviteRequest, _OutgoingRequest); - - var _super = _createSuper(InitialOutgoingInviteRequest); - - function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) { - var _this; - - _classCallCheck(this, InitialOutgoingInviteRequest); - - _this = _super.call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body); - _this.transaction = null; - return _this; - } - - _createClass(InitialOutgoingInviteRequest, [{ - key: "cancel", - value: function cancel(reason) { - this.transaction.cancel(reason); - } - }, { - key: "clone", - value: function clone() { - var request = new InitialOutgoingInviteRequest(this.ruri, this.ua); - Object.keys(this.headers).forEach(function (name) { - request.headers[name] = this.headers[name].slice(); - }, this); - request.body = this.body; - request.extraHeaders = Utils.cloneArray(this.extraHeaders); - request.to = this.to; - request.from = this.from; - request.call_id = this.call_id; - request.cseq = this.cseq; - request.transaction = this.transaction; - return request; - } - }]); - - return InitialOutgoingInviteRequest; -}(OutgoingRequest); - -var IncomingMessage = /*#__PURE__*/function () { - function IncomingMessage() { - _classCallCheck(this, IncomingMessage); - - 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; - } - /** - * Insert a header of the given name and value into the last position of the - * header array. - */ - - - _createClass(IncomingMessage, [{ - key: "addHeader", - value: function addHeader(name, value) { - var header = { - raw: value - }; - name = Utils.headerize(name); - - if (this.headers[name]) { - this.headers[name].push(header); - } else { - this.headers[name] = [header]; - } - } - /** - * Get the value of the given header name at the given position. - */ - - }, { - key: "getHeader", - value: function getHeader(name) { - var header = this.headers[Utils.headerize(name)]; - - if (header) { - if (header[0]) { - return header[0].raw; - } - } else { - return; - } - } - /** - * Get the header/s of the given name. - */ - - }, { - key: "getHeaders", - value: function getHeaders(name) { - var headers = this.headers[Utils.headerize(name)]; - var result = []; - - if (!headers) { - return []; - } - - var _iterator7 = _createForOfIteratorHelper(headers), - _step7; - - try { - for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { - var header = _step7.value; - result.push(header.raw); - } - } catch (err) { - _iterator7.e(err); - } finally { - _iterator7.f(); - } - - return result; - } - /** - * Verify the existence of the given header. - */ - - }, { - key: "hasHeader", - value: function hasHeader(name) { - return this.headers[Utils.headerize(name)] ? true : false; - } - /** - * Parse the given header on the given index. - * -param {String} name header name - * -param {Number} [idx=0] header index - * -returns {Object|undefined} Parsed header object, undefined if the header - * is not present or in case of a parsing error. - */ - - }, { - key: "parseHeader", - value: function parseHeader(name) { - var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - name = Utils.headerize(name); - - if (!this.headers[name]) { - debug("header \"".concat(name, "\" not present")); - return; - } else if (idx >= this.headers[name].length) { - debug("not so many \"".concat(name, "\" headers present")); - return; - } - - var header = this.headers[name][idx]; - var value = header.raw; - - if (header.parsed) { - return header.parsed; - } // Substitute '-' by '_' for grammar rule matching. - - - var parsed = Grammar.parse(value, name.replace(/-/g, '_')); - - if (parsed === -1) { - this.headers[name].splice(idx, 1); // delete from headers - - debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); - return; - } else { - header.parsed = parsed; - return parsed; - } - } - /** - * Message Header attribute selector. Alias of parseHeader. - * -param {String} name header name - * -param {Number} [idx=0] header index - * -returns {Object|undefined} Parsed header object, undefined if the header - * is not present or in case of a parsing error. - * - * -example - * message.s('via',3).port - */ - - }, { - key: "s", - value: function s(name, idx) { - return this.parseHeader(name, idx); - } - /** - * Replace the value of the given header by the value. - * -param {String} name header name - * -param {String} value header value - */ - - }, { - key: "setHeader", - value: function setHeader(name, value) { - var header = { - raw: value - }; - this.headers[Utils.headerize(name)] = [header]; - } - /** - * Parse the current body as a SDP and store the resulting object - * into this.sdp. - * -param {Boolean} force: Parse even if this.sdp already exists. - * - * Returns this.sdp. - */ - - }, { - key: "parseSDP", - value: function parseSDP(force) { - if (!force && this.sdp) { - return this.sdp; - } else { - this.sdp = sdp_transform.parse(this.body || ''); - return this.sdp; - } - } - }, { - key: "toString", - value: function toString() { - return this.data; - } - }]); - - return IncomingMessage; -}(); - -var IncomingRequest = /*#__PURE__*/function (_IncomingMessage) { - _inherits(IncomingRequest, _IncomingMessage); - - var _super2 = _createSuper(IncomingRequest); - - function IncomingRequest(ua) { - var _this2; - - _classCallCheck(this, IncomingRequest); - - _this2 = _super2.call(this); - _this2.ua = ua; - _this2.headers = {}; - _this2.ruri = null; - _this2.transport = null; - _this2.server_transaction = null; - return _this2; - } - /** - * Stateful reply. - * -param {Number} code status code - * -param {String} reason reason phrase - * -param {Object} headers extra headers - * -param {String} body body - * -param {Function} [onSuccess] onSuccess callback - * -param {Function} [onFailure] onFailure callback - */ - - - _createClass(IncomingRequest, [{ - key: "reply", - value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) { - var supported = []; - var to = this.getHeader('To'); - code = code || null; - reason = reason || null; // Validate code and reason values. - - if (!code || code < 100 || code > 699) { - throw new TypeError("Invalid status_code: ".concat(code)); - } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { - throw new TypeError("Invalid reason_phrase: ".concat(reason)); - } - - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - extraHeaders = Utils.cloneArray(extraHeaders); - var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); - - if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) { - var headers = this.getHeaders('record-route'); - - var _iterator8 = _createForOfIteratorHelper(headers), - _step8; - - try { - for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { - var header = _step8.value; - response += "Record-Route: ".concat(header, "\r\n"); - } - } catch (err) { - _iterator8.e(err); - } finally { - _iterator8.f(); - } - } - - var vias = this.getHeaders('via'); - - var _iterator9 = _createForOfIteratorHelper(vias), - _step9; - - try { - for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { - var via = _step9.value; - response += "Via: ".concat(via, "\r\n"); - } - } catch (err) { - _iterator9.e(err); - } finally { - _iterator9.f(); - } - - if (!this.to_tag && code > 100) { - to += ";tag=".concat(Utils.newTag()); - } else if (this.to_tag && !this.s('to').hasParam('tag')) { - to += ";tag=".concat(this.to_tag); - } - - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(this.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(this.call_id, "\r\n"); - response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); - - var _iterator10 = _createForOfIteratorHelper(extraHeaders), - _step10; - - try { - for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { - var _header2 = _step10.value; - response += "".concat(_header2.trim(), "\r\n"); - } // Supported. - - } catch (err) { - _iterator10.e(err); - } finally { - _iterator10.f(); - } - - switch (this.method) { - case JsSIP_C.INVITE: - if (this.ua.configuration.session_timers) { - supported.push('timer'); - } - - if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) { - supported.push('gruu'); - } - - supported.push('ice', 'replaces'); - break; - - case JsSIP_C.UPDATE: - if (this.ua.configuration.session_timers) { - supported.push('timer'); - } - - if (body) { - supported.push('ice'); - } - - supported.push('replaces'); - } - - supported.push('outbound'); // Allow and Accept. - - if (this.method === JsSIP_C.OPTIONS) { - response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); - response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n"); - } else if (code === 405) { - response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); - } else if (code === 415) { - response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n"); - } - - response += "Supported: ".concat(supported, "\r\n"); - - if (body) { - var length = Utils.str_utf8_length(body); - response += 'Content-Type: application/sdp\r\n'; - response += "Content-Length: ".concat(length, "\r\n\r\n"); - response += body; - } else { - response += "Content-Length: ".concat(0, "\r\n\r\n"); - } - - this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); - } - /** - * Stateless reply. - * -param {Number} code status code - * -param {String} reason reason phrase - */ - - }, { - key: "reply_sl", - value: function reply_sl() { - var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var vias = this.getHeaders('via'); // Validate code and reason values. - - if (!code || code < 100 || code > 699) { - throw new TypeError("Invalid status_code: ".concat(code)); - } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { - throw new TypeError("Invalid reason_phrase: ".concat(reason)); - } - - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); - - var _iterator11 = _createForOfIteratorHelper(vias), - _step11; - - try { - for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { - var via = _step11.value; - response += "Via: ".concat(via, "\r\n"); - } - } catch (err) { - _iterator11.e(err); - } finally { - _iterator11.f(); - } - - var to = this.getHeader('To'); - - if (!this.to_tag && code > 100) { - to += ";tag=".concat(Utils.newTag()); - } else if (this.to_tag && !this.s('to').hasParam('tag')) { - to += ";tag=".concat(this.to_tag); - } - - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(this.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(this.call_id, "\r\n"); - response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); - response += "Content-Length: ".concat(0, "\r\n\r\n"); - this.transport.send(response); - } - }]); - - return IncomingRequest; -}(IncomingMessage); - -var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { - _inherits(IncomingResponse, _IncomingMessage2); - - var _super3 = _createSuper(IncomingResponse); - - function IncomingResponse() { - var _this3; - - _classCallCheck(this, IncomingResponse); - - _this3 = _super3.call(this); - _this3.headers = {}; - _this3.status_code = null; - _this3.reason_phrase = null; - return _this3; - } - - return IncomingResponse; -}(IncomingMessage); - -module.exports = { - OutgoingRequest: OutgoingRequest, - InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, - IncomingRequest: IncomingRequest, - IncomingResponse: IncomingResponse -}; -},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":26,"debug":30,"sdp-transform":35}],20:[function(require,module,exports){ -"use strict"; - -var Utils = require('./Utils'); - -var Grammar = require('./Grammar'); - -var debugerror = require('debug')('JsSIP:ERROR:Socket'); - -debugerror.log = console.warn.bind(console); -/** - * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ - * - * interface Socket { - * attribute String via_transport - * attribute String url - * attribute String sip_uri - * - * method connect(); - * method disconnect(); - * method send(data); - * - * attribute EventHandler onconnect - * attribute EventHandler ondisconnect - * attribute EventHandler ondata - * } - * - */ - -exports.isSocket = function (socket) { - // Ignore if an array is given. - if (Array.isArray(socket)) { - return false; - } - - if (typeof socket === 'undefined') { - debugerror('undefined JsSIP.Socket instance'); - return false; - } // Check Properties. - - - try { - if (!Utils.isString(socket.url)) { - debugerror('missing or invalid JsSIP.Socket url property'); - throw new Error(); - } - - if (!Utils.isString(socket.via_transport)) { - debugerror('missing or invalid JsSIP.Socket via_transport property'); - throw new Error(); - } - - if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { - debugerror('missing or invalid JsSIP.Socket sip_uri property'); - throw new Error(); - } - } catch (e) { - return false; - } // Check Methods. - - - try { - ['connect', 'disconnect', 'send'].forEach(function (method) { - if (!Utils.isFunction(socket[method])) { - debugerror("missing or invalid JsSIP.Socket method: ".concat(method)); - throw new Error(); - } - }); - } catch (e) { - return false; - } - - return true; -}; -},{"./Grammar":7,"./Utils":26,"debug":30}],21:[function(require,module,exports){ -"use strict"; - -var T1 = 500, - T2 = 4000, - T4 = 5000; -module.exports = { - T1: T1, - T2: T2, - T4: T4, - TIMER_B: 64 * T1, - TIMER_D: 0 * T1, - TIMER_F: 64 * T1, - TIMER_H: 64 * T1, - TIMER_I: 0 * T1, - TIMER_J: 0 * T1, - TIMER_K: 0 * T4, - TIMER_L: 64 * T1, - TIMER_M: 64 * T1, - PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 - -}; -},{}],22:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('./Constants'); - -var SIPMessage = require('./SIPMessage'); - -var Timers = require('./Timers'); - -var debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); - -var debugict = require('debug')('JsSIP:InviteClientTransaction'); - -var debugact = require('debug')('JsSIP:AckClientTransaction'); - -var debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); - -var debugist = require('debug')('JsSIP:InviteServerTransaction'); - -var C = { - // Transaction states. - STATUS_TRYING: 1, - STATUS_PROCEEDING: 2, - STATUS_CALLING: 3, - STATUS_ACCEPTED: 4, - STATUS_COMPLETED: 5, - STATUS_TERMINATED: 6, - STATUS_CONFIRMED: 7, - // Transaction types. - NON_INVITE_CLIENT: 'nict', - NON_INVITE_SERVER: 'nist', - INVITE_CLIENT: 'ict', - INVITE_SERVER: 'ist' -}; - -var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { - _inherits(NonInviteClientTransaction, _EventEmitter); - - var _super = _createSuper(NonInviteClientTransaction); - - function NonInviteClientTransaction(ua, transport, request, eventHandlers) { - var _this; - - _classCallCheck(this, NonInviteClientTransaction); - - _this = _super.call(this); - _this.type = C.NON_INVITE_CLIENT; - _this.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); - _this.ua = ua; - _this.transport = transport; - _this.request = request; - _this.eventHandlers = eventHandlers; - var via = "SIP/2.0/".concat(transport.via_transport); - via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this.id); - - _this.request.setHeader('via', via); - - _this.ua.newTransaction(_assertThisInitialized(_this)); - - return _this; - } - - _createClass(NonInviteClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "stateChanged", - value: function stateChanged(state) { - this.state = state; - this.emit('stateChanged'); - } - }, { - key: "send", - value: function send() { - var _this2 = this; - - this.stateChanged(C.STATUS_TRYING); - this.F = setTimeout(function () { - _this2.timer_F(); - }, Timers.TIMER_F); - - if (!this.transport.send(this.request)) { - this.onTransportError(); - } - } - }, { - key: "onTransportError", - value: function onTransportError() { - debugnict("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 timer_F() { - debugnict("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 timer_K() { - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - }, { - key: "receiveResponse", - value: function receiveResponse(response) { - var _this3 = this; - - var status_code = response.status_code; - - if (status_code < 200) { - switch (this.state) { - case C.STATUS_TRYING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_PROCEEDING); - this.eventHandlers.onReceiveResponse(response); - break; - } - } else { - switch (this.state) { - case C.STATUS_TRYING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_COMPLETED); - clearTimeout(this.F); - - if (status_code === 408) { - this.eventHandlers.onRequestTimeout(); - } else { - this.eventHandlers.onReceiveResponse(response); - } - - this.K = setTimeout(function () { - _this3.timer_K(); - }, Timers.TIMER_K); - break; - - case C.STATUS_COMPLETED: - break; - } - } - } - }]); - - return NonInviteClientTransaction; -}(EventEmitter); - -var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { - _inherits(InviteClientTransaction, _EventEmitter2); - - var _super2 = _createSuper(InviteClientTransaction); - - function InviteClientTransaction(ua, transport, request, eventHandlers) { - var _this4; - - _classCallCheck(this, InviteClientTransaction); - - _this4 = _super2.call(this); - _this4.type = C.INVITE_CLIENT; - _this4.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); - _this4.ua = ua; - _this4.transport = transport; - _this4.request = request; - _this4.eventHandlers = eventHandlers; - request.transaction = _assertThisInitialized(_this4); - var via = "SIP/2.0/".concat(transport.via_transport); - via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this4.id); - - _this4.request.setHeader('via', via); - - _this4.ua.newTransaction(_assertThisInitialized(_this4)); - - return _this4; - } - - _createClass(InviteClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "stateChanged", - value: function stateChanged(state) { - this.state = state; - this.emit('stateChanged'); - } - }, { - key: "send", - value: function send() { - var _this5 = this; - - this.stateChanged(C.STATUS_CALLING); - this.B = setTimeout(function () { - _this5.timer_B(); - }, Timers.TIMER_B); - - if (!this.transport.send(this.request)) { - this.onTransportError(); - } - } - }, { - key: "onTransportError", - value: function onTransportError() { - clearTimeout(this.B); - clearTimeout(this.D); - clearTimeout(this.M); - - if (this.state !== C.STATUS_ACCEPTED) { - debugict("transport error occurred, deleting transaction ".concat(this.id)); - this.eventHandlers.onTransportError(); - } - - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } // RFC 6026 7.2. - - }, { - key: "timer_M", - value: function timer_M() { - debugict("Timer M expired for transaction ".concat(this.id)); - - if (this.state === C.STATUS_ACCEPTED) { - clearTimeout(this.B); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - } // RFC 3261 17.1.1. - - }, { - key: "timer_B", - value: function timer_B() { - debugict("Timer B expired for transaction ".concat(this.id)); - - if (this.state === C.STATUS_CALLING) { - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - this.eventHandlers.onRequestTimeout(); - } - } - }, { - key: "timer_D", - value: function timer_D() { - debugict("Timer D expired for transaction ".concat(this.id)); - clearTimeout(this.B); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - }, { - key: "sendACK", - value: function sendACK(response) { - var _this6 = this; - - var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, { - 'route_set': this.request.getHeaders('route'), - 'call_id': this.request.getHeader('call-id'), - 'cseq': this.request.cseq - }); - ack.setHeader('from', this.request.getHeader('from')); - ack.setHeader('via', this.request.getHeader('via')); - ack.setHeader('to', response.getHeader('to')); - this.D = setTimeout(function () { - _this6.timer_D(); - }, Timers.TIMER_D); - this.transport.send(ack); - } - }, { - key: "cancel", - value: function cancel(reason) { - // Send only if a provisional response (>100) has been received. - if (this.state !== C.STATUS_PROCEEDING) { - return; - } - - var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, { - 'route_set': this.request.getHeaders('route'), - 'call_id': this.request.getHeader('call-id'), - 'cseq': this.request.cseq - }); - cancel.setHeader('from', this.request.getHeader('from')); - cancel.setHeader('via', this.request.getHeader('via')); - cancel.setHeader('to', this.request.getHeader('to')); - - if (reason) { - cancel.setHeader('reason', reason); - } - - this.transport.send(cancel); - } - }, { - key: "receiveResponse", - value: function receiveResponse(response) { - var _this7 = this; - - var status_code = response.status_code; - - if (status_code >= 100 && status_code <= 199) { - switch (this.state) { - case C.STATUS_CALLING: - this.stateChanged(C.STATUS_PROCEEDING); - this.eventHandlers.onReceiveResponse(response); - break; - - case C.STATUS_PROCEEDING: - this.eventHandlers.onReceiveResponse(response); - break; - } - } else if (status_code >= 200 && status_code <= 299) { - switch (this.state) { - case C.STATUS_CALLING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_ACCEPTED); - this.M = setTimeout(function () { - _this7.timer_M(); - }, Timers.TIMER_M); - this.eventHandlers.onReceiveResponse(response); - break; - - case C.STATUS_ACCEPTED: - this.eventHandlers.onReceiveResponse(response); - break; - } - } else if (status_code >= 300 && status_code <= 699) { - switch (this.state) { - case C.STATUS_CALLING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_COMPLETED); - this.sendACK(response); - this.eventHandlers.onReceiveResponse(response); - break; - - case C.STATUS_COMPLETED: - this.sendACK(response); - break; - } - } - } - }]); - - return InviteClientTransaction; -}(EventEmitter); - -var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { - _inherits(AckClientTransaction, _EventEmitter3); - - var _super3 = _createSuper(AckClientTransaction); - - function AckClientTransaction(ua, transport, request, eventHandlers) { - var _this8; - - _classCallCheck(this, AckClientTransaction); - - _this8 = _super3.call(this); - _this8.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); - _this8.transport = transport; - _this8.request = request; - _this8.eventHandlers = eventHandlers; - var via = "SIP/2.0/".concat(transport.via_transport); - via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this8.id); - - _this8.request.setHeader('via', via); - - return _this8; - } - - _createClass(AckClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "send", - value: function send() { - if (!this.transport.send(this.request)) { - this.onTransportError(); - } - } - }, { - key: "onTransportError", - value: function onTransportError() { - debugact("transport error occurred for transaction ".concat(this.id)); - this.eventHandlers.onTransportError(); - } - }]); - - return AckClientTransaction; -}(EventEmitter); - -var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { - _inherits(NonInviteServerTransaction, _EventEmitter4); - - var _super4 = _createSuper(NonInviteServerTransaction); - - function NonInviteServerTransaction(ua, transport, request) { - var _this9; - - _classCallCheck(this, NonInviteServerTransaction); - - _this9 = _super4.call(this); - _this9.type = C.NON_INVITE_SERVER; - _this9.id = request.via_branch; - _this9.ua = ua; - _this9.transport = transport; - _this9.request = request; - _this9.last_response = ''; - request.server_transaction = _assertThisInitialized(_this9); - _this9.state = C.STATUS_TRYING; - ua.newTransaction(_assertThisInitialized(_this9)); - return _this9; - } - - _createClass(NonInviteServerTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "stateChanged", - value: function stateChanged(state) { - this.state = state; - this.emit('stateChanged'); - } - }, { - key: "timer_J", - value: function timer_J() { - debugnist("Timer J expired for transaction ".concat(this.id)); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - }, { - key: "onTransportError", - value: function onTransportError() { - if (!this.transportError) { - this.transportError = true; - debugnist("transport error occurred, deleting transaction ".concat(this.id)); - clearTimeout(this.J); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - } - }, { - key: "receiveResponse", - value: function receiveResponse(status_code, response, onSuccess, onFailure) { - var _this10 = this; - - if (status_code === 100) { - /* RFC 4320 4.1 - * 'A SIP element MUST NOT - * send any provisional response with a - * Status-Code other than 100 to a non-INVITE request.' - */ - switch (this.state) { - case C.STATUS_TRYING: - this.stateChanged(C.STATUS_PROCEEDING); - - if (!this.transport.send(response)) { - this.onTransportError(); - } - - break; - - case C.STATUS_PROCEEDING: - this.last_response = response; - - if (!this.transport.send(response)) { - this.onTransportError(); - - if (onFailure) { - onFailure(); - } - } else if (onSuccess) { - onSuccess(); - } - - break; - } - } else if (status_code >= 200 && status_code <= 699) { - switch (this.state) { - case C.STATUS_TRYING: - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_COMPLETED); - this.last_response = response; - this.J = setTimeout(function () { - _this10.timer_J(); - }, Timers.TIMER_J); - - if (!this.transport.send(response)) { - this.onTransportError(); - - if (onFailure) { - onFailure(); - } - } else if (onSuccess) { - onSuccess(); - } - - break; - - case C.STATUS_COMPLETED: - break; - } - } - } - }]); - - return NonInviteServerTransaction; -}(EventEmitter); - -var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { - _inherits(InviteServerTransaction, _EventEmitter5); - - var _super5 = _createSuper(InviteServerTransaction); - - function InviteServerTransaction(ua, transport, request) { - var _this11; - - _classCallCheck(this, InviteServerTransaction); - - _this11 = _super5.call(this); - _this11.type = C.INVITE_SERVER; - _this11.id = request.via_branch; - _this11.ua = ua; - _this11.transport = transport; - _this11.request = request; - _this11.last_response = ''; - request.server_transaction = _assertThisInitialized(_this11); - _this11.state = C.STATUS_PROCEEDING; - ua.newTransaction(_assertThisInitialized(_this11)); - _this11.resendProvisionalTimer = null; - request.reply(100); - return _this11; - } - - _createClass(InviteServerTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "stateChanged", - value: function stateChanged(state) { - this.state = state; - this.emit('stateChanged'); - } - }, { - key: "timer_H", - value: function timer_H() { - debugist("Timer H expired for transaction ".concat(this.id)); - - if (this.state === C.STATUS_COMPLETED) { - debugist('ACK not received, dialog will be terminated'); - } - - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - }, { - key: "timer_I", - value: function timer_I() { - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } // RFC 6026 7.1. - - }, { - key: "timer_L", - value: function timer_L() { - debugist("Timer L expired for transaction ".concat(this.id)); - - if (this.state === C.STATUS_ACCEPTED) { - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - } - }, { - key: "onTransportError", - value: function onTransportError() { - if (!this.transportError) { - this.transportError = true; - debugist("transport error occurred, deleting transaction ".concat(this.id)); - - if (this.resendProvisionalTimer !== null) { - clearInterval(this.resendProvisionalTimer); - this.resendProvisionalTimer = null; - } - - clearTimeout(this.L); - clearTimeout(this.H); - clearTimeout(this.I); - this.stateChanged(C.STATUS_TERMINATED); - this.ua.destroyTransaction(this); - } - } - }, { - key: "resend_provisional", - value: function resend_provisional() { - if (!this.transport.send(this.last_response)) { - this.onTransportError(); - } - } // INVITE Server Transaction RFC 3261 17.2.1. - - }, { - key: "receiveResponse", - value: function receiveResponse(status_code, response, onSuccess, onFailure) { - var _this12 = this; - - if (status_code >= 100 && status_code <= 199) { - switch (this.state) { - case C.STATUS_PROCEEDING: - if (!this.transport.send(response)) { - this.onTransportError(); - } - - this.last_response = response; - break; - } - } - - if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) { - // Trigger the resendProvisionalTimer only for the first non 100 provisional response. - if (this.resendProvisionalTimer === null) { - this.resendProvisionalTimer = setInterval(function () { - _this12.resend_provisional(); - }, Timers.PROVISIONAL_RESPONSE_INTERVAL); - } - } else if (status_code >= 200 && status_code <= 299) { - switch (this.state) { - case C.STATUS_PROCEEDING: - this.stateChanged(C.STATUS_ACCEPTED); - this.last_response = response; - this.L = setTimeout(function () { - _this12.timer_L(); - }, Timers.TIMER_L); - - if (this.resendProvisionalTimer !== null) { - clearInterval(this.resendProvisionalTimer); - this.resendProvisionalTimer = null; - } - - /* falls through */ - - case C.STATUS_ACCEPTED: - // Note that this point will be reached for proceeding this.state also. - if (!this.transport.send(response)) { - this.onTransportError(); - - if (onFailure) { - onFailure(); - } - } else if (onSuccess) { - onSuccess(); - } - - break; - } - } else if (status_code >= 300 && status_code <= 699) { - switch (this.state) { - case C.STATUS_PROCEEDING: - if (this.resendProvisionalTimer !== null) { - clearInterval(this.resendProvisionalTimer); - this.resendProvisionalTimer = null; - } - - if (!this.transport.send(response)) { - this.onTransportError(); - - if (onFailure) { - onFailure(); - } - } else { - this.stateChanged(C.STATUS_COMPLETED); - this.H = setTimeout(function () { - _this12.timer_H(); - }, Timers.TIMER_H); - - if (onSuccess) { - onSuccess(); - } - } - - break; - } - } - } - }]); - - return InviteServerTransaction; -}(EventEmitter); -/** - * INVITE: - * _true_ if retransmission - * _false_ new request - * - * ACK: - * _true_ ACK to non2xx response - * _false_ ACK must be passed to TU (accepted state) - * ACK to 2xx response - * - * CANCEL: - * _true_ no matching invite transaction - * _false_ matching invite transaction and no final response sent - * - * OTHER: - * _true_ retransmission - * _false_ new request - */ - - -function checkTransaction(_ref, request) { - var _transactions = _ref._transactions; - var tr; - - switch (request.method) { - case JsSIP_C.INVITE: - tr = _transactions.ist[request.via_branch]; - - if (tr) { - switch (tr.state) { - case C.STATUS_PROCEEDING: - tr.transport.send(tr.last_response); - break; - // RFC 6026 7.1 Invite retransmission. - // Received while in C.STATUS_ACCEPTED state. Absorb it. - - case C.STATUS_ACCEPTED: - break; - } - - return true; - } - - break; - - case JsSIP_C.ACK: - tr = _transactions.ist[request.via_branch]; // RFC 6026 7.1. - - if (tr) { - if (tr.state === C.STATUS_ACCEPTED) { - return false; - } else if (tr.state === C.STATUS_COMPLETED) { - tr.state = C.STATUS_CONFIRMED; - tr.I = setTimeout(function () { - tr.timer_I(); - }, Timers.TIMER_I); - return true; - } - } // ACK to 2XX Response. - else { - return false; - } - - break; - - case JsSIP_C.CANCEL: - tr = _transactions.ist[request.via_branch]; - - if (tr) { - request.reply_sl(200); - - if (tr.state === C.STATUS_PROCEEDING) { - return false; - } else { - return true; - } - } else { - request.reply_sl(481); - return true; - } - - default: - // Non-INVITE Server Transaction RFC 3261 17.2.2. - tr = _transactions.nist[request.via_branch]; - - if (tr) { - switch (tr.state) { - case C.STATUS_TRYING: - break; - - case C.STATUS_PROCEEDING: - case C.STATUS_COMPLETED: - tr.transport.send(tr.last_response); - break; - } - - return true; - } - - break; - } -} - -module.exports = { - C: C, - NonInviteClientTransaction: NonInviteClientTransaction, - InviteClientTransaction: InviteClientTransaction, - AckClientTransaction: AckClientTransaction, - NonInviteServerTransaction: NonInviteServerTransaction, - InviteServerTransaction: InviteServerTransaction, - checkTransaction: checkTransaction -}; -},{"./Constants":2,"./SIPMessage":19,"./Timers":21,"debug":30,"events":29}],23:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Socket = require('./Socket'); - -var debug = require('debug')('JsSIP:Transport'); - -var debugerror = require('debug')('JsSIP:ERROR:Transport'); - -var JsSIP_C = require('./Constants'); - -debugerror.log = console.warn.bind(console); -/** - * Constants - */ - -var C = { - // Transport status. - STATUS_CONNECTED: 0, - STATUS_CONNECTING: 1, - STATUS_DISCONNECTED: 2, - // Socket status. - SOCKET_STATUS_READY: 0, - SOCKET_STATUS_ERROR: 1, - // Recovery options. - recovery_options: { - // minimum interval in seconds between recover attempts. - min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL, - // maximum interval in seconds between recover attempts. - max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL - } -}; -/* - * Manages one or multiple JsSIP.Socket instances. - * Is reponsible for transport recovery logic among all socket instances. - * - * @socket JsSIP::Socket instance - */ - -module.exports = /*#__PURE__*/function () { - function Transport(sockets) { - var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options; - - _classCallCheck(this, Transport); - - debug('new()'); - this.status = C.STATUS_DISCONNECTED; // Current socket. - - this.socket = null; // Socket collection. - - this.sockets = []; - this.recovery_options = recovery_options; - this.recover_attempts = 0; - this.recovery_timer = null; - this.close_requested = false; // It seems that TextDecoder is not available in some versions of React-Native. - // See https://github.com/versatica/JsSIP/issues/695 - - try { - this.textDecoder = new TextDecoder('utf8'); - } catch (error) { - debugerror("cannot use TextDecoder: ".concat(error)); - } - - if (typeof sockets === 'undefined') { - throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument'); - } - - if (!(sockets instanceof Array)) { - sockets = [sockets]; - } - - sockets.forEach(function (socket) { - if (!Socket.isSocket(socket.socket)) { - throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance'); - } - - if (socket.weight && !Number(socket.weight)) { - throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number'); - } - - this.sockets.push({ - socket: socket.socket, - weight: socket.weight || 0, - status: C.SOCKET_STATUS_READY - }); - }, this); // Get the socket with higher weight. - - this._getSocket(); - } - /** - * Instance Methods - */ - - - _createClass(Transport, [{ - key: "via_transport", - get: function get() { - return this.socket.via_transport; - } - }, { - key: "url", - get: function get() { - return this.socket.url; - } - }, { - key: "sip_uri", - get: function get() { - return this.socket.sip_uri; - } - }, { - key: "connect", - value: function connect() { - debug('connect()'); - - if (this.isConnected()) { - debug('Transport is already connected'); - return; - } else if (this.isConnecting()) { - debug('Transport is connecting'); - return; - } - - this.close_requested = false; - this.status = C.STATUS_CONNECTING; - this.onconnecting({ - socket: this.socket, - attempts: this.recover_attempts - }); - - if (!this.close_requested) { - // Bind socket event callbacks. - this.socket.onconnect = this._onConnect.bind(this); - this.socket.ondisconnect = this._onDisconnect.bind(this); - this.socket.ondata = this._onData.bind(this); - this.socket.connect(); - } - - return; - } - }, { - key: "disconnect", - value: function disconnect() { - debug('close()'); - this.close_requested = true; - this.recover_attempts = 0; - this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer. - - if (this.recovery_timer !== null) { - clearTimeout(this.recovery_timer); - this.recovery_timer = null; - } // Unbind socket event callbacks. - - - this.socket.onconnect = function () {}; - - this.socket.ondisconnect = function () {}; - - this.socket.ondata = function () {}; - - this.socket.disconnect(); - this.ondisconnect({ - socket: this.socket, - error: false - }); - } - }, { - key: "send", - value: function send(data) { - debug('send()'); - - if (!this.isConnected()) { - debugerror('unable to send message, transport is not connected'); - return false; - } - - var message = data.toString(); - debug("sending message:\n\n".concat(message, "\n")); - return this.socket.send(message); - } - }, { - key: "isConnected", - value: function isConnected() { - return this.status === C.STATUS_CONNECTED; - } - }, { - key: "isConnecting", - value: function isConnecting() { - return this.status === C.STATUS_CONNECTING; - } - /** - * Private API. - */ - - }, { - key: "_reconnect", - value: function _reconnect() { - var _this = this; - - this.recover_attempts += 1; - var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1); - - if (k < this.recovery_options.min_interval) { - k = this.recovery_options.min_interval; - } else if (k > this.recovery_options.max_interval) { - k = this.recovery_options.max_interval; - } - - debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); - this.recovery_timer = setTimeout(function () { - if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) { - // Get the next available socket with higher weight. - _this._getSocket(); // Connect the socket. - - - _this.connect(); - } - }, k * 1000); - } - /** - * get the next available socket with higher weight - */ - - }, { - key: "_getSocket", - value: function _getSocket() { - var candidates = []; - this.sockets.forEach(function (socket) { - if (socket.status === C.SOCKET_STATUS_ERROR) { - return; // continue the array iteration - } else if (candidates.length === 0) { - candidates.push(socket); - } else if (socket.weight > candidates[0].weight) { - candidates = [socket]; - } else if (socket.weight === candidates[0].weight) { - candidates.push(socket); - } - }); - - if (candidates.length === 0) { - // All sockets have failed. reset sockets status. - this.sockets.forEach(function (socket) { - socket.status = C.SOCKET_STATUS_READY; - }); // Get next available socket. - - this._getSocket(); - - return; - } - - var idx = Math.floor(Math.random() * candidates.length); - this.socket = candidates[idx].socket; - } - /** - * Socket Event Handlers - */ - - }, { - key: "_onConnect", - value: function _onConnect() { - this.recover_attempts = 0; - this.status = C.STATUS_CONNECTED; // Clear recovery_timer. - - if (this.recovery_timer !== null) { - clearTimeout(this.recovery_timer); - this.recovery_timer = null; - } - - this.onconnect({ - socket: this - }); - } - }, { - key: "_onDisconnect", - value: function _onDisconnect(error, code, reason) { - this.status = C.STATUS_DISCONNECTED; - this.ondisconnect({ - socket: this.socket, - error: error, - code: code, - reason: reason - }); - - if (this.close_requested) { - return; - } // Update socket status. - else { - this.sockets.forEach(function (socket) { - if (this.socket === socket.socket) { - socket.status = C.SOCKET_STATUS_ERROR; - } - }, this); - } - - this._reconnect(error); - } - }, { - key: "_onData", - value: function _onData(data) { - // CRLF Keep Alive response from server. Ignore it. - if (data === '\r\n') { - debug('received message with CRLF Keep Alive response'); - return; - } // Binary message. - else if (typeof data !== 'string') { - try { - if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data)); - } catch (evt) { - debug('received binary message failed to be converted into string,' + ' message discarded'); - return; - } - - debug("received binary message:\n\n".concat(data, "\n")); - } // Text message. - else { - debug("received text message:\n\n".concat(data, "\n")); - } - - this.ondata({ - transport: this, - message: data - }); - } - }]); - - return Transport; -}(); -},{"./Constants":2,"./Socket":20,"debug":30}],24:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('./Constants'); - -var Registrator = require('./Registrator'); - -var RTCSession = require('./RTCSession'); - -var Message = require('./Message'); - -var Transactions = require('./Transactions'); - -var Transport = require('./Transport'); - -var Utils = require('./Utils'); - -var Exceptions = require('./Exceptions'); - -var URI = require('./URI'); - -var Parser = require('./Parser'); - -var SIPMessage = require('./SIPMessage'); - -var RequestSender = require('./RequestSender'); - -var sanityCheck = require('./sanityCheck'); - -var config = require('./Config'); - -var debug = require('debug')('JsSIP:UA'); - -var debugerror = require('debug')('JsSIP:ERROR:UA'); - -debugerror.log = console.warn.bind(console); -var C = { - // UA status codes. - STATUS_INIT: 0, - STATUS_READY: 1, - STATUS_USER_CLOSED: 2, - STATUS_NOT_READY: 3, - // UA error codes. - CONFIGURATION_ERROR: 1, - NETWORK_ERROR: 2 -}; -/** - * The User-Agent class. - * @class JsSIP.UA - * @param {Object} configuration Configuration parameters. - * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid. - * @throws {TypeError} If no configuration is given. - */ - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(UA, _EventEmitter); - - var _super = _createSuper(UA); - - function UA(configuration) { - var _this; - - _classCallCheck(this, UA); - - debug('new() [configuration:%o]', configuration); - _this = _super.call(this); - _this._cache = { - credentials: {} - }; - _this._configuration = Object.assign({}, config.settings); - _this._dynConfiguration = {}; - _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE). - - _this._applicants = {}; - _this._sessions = {}; - _this._transport = null; - _this._contact = null; - _this._status = C.STATUS_INIT; - _this._error = null; - _this._transactions = { - nist: {}, - nict: {}, - ist: {}, - ict: {} - }; // Custom UA empty object for high level use. - - _this._data = {}; - _this._closeTimer = null; // Check configuration argument. - - if (configuration === undefined) { - throw new TypeError('Not enough arguments'); - } // Load configuration. - - - try { - _this._loadConfig(configuration); - } catch (e) { - _this._status = C.STATUS_NOT_READY; - _this._error = C.CONFIGURATION_ERROR; - throw e; - } // Initialize registrator. - - - _this._registrator = new Registrator(_assertThisInitialized(_this)); - return _this; - } - - _createClass(UA, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "configuration", - get: function get() { - return this._configuration; - } - }, { - key: "transport", - get: function get() { - return this._transport; - } // ================= - // High Level API - // ================= - - /** - * Connect to the server if status = STATUS_INIT. - * Resume UA after being closed. - */ - - }, { - key: "start", - value: function start() { - debug('start()'); - - if (this._status === C.STATUS_INIT) { - this._transport.connect(); - } else if (this._status === C.STATUS_USER_CLOSED) { - debug('restarting UA'); // Disconnect. - - if (this._closeTimer !== null) { - clearTimeout(this._closeTimer); - this._closeTimer = null; - - this._transport.disconnect(); - } // Reconnect. - - - this._status = C.STATUS_INIT; - - this._transport.connect(); - } else if (this._status === C.STATUS_READY) { - debug('UA is in READY status, not restarted'); - } else { - debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); - } // Set dynamic configuration. - - - this._dynConfiguration.register = this._configuration.register; - } - /** - * Register. - */ - - }, { - key: "register", - value: function register() { - debug('register()'); - this._dynConfiguration.register = true; - - this._registrator.register(); - } - /** - * Unregister. - */ - - }, { - key: "unregister", - value: function unregister(options) { - debug('unregister()'); - this._dynConfiguration.register = false; - - this._registrator.unregister(options); - } - /** - * Get the Registrator instance. - */ - - }, { - key: "registrator", - value: function registrator() { - return this._registrator; - } - /** - * Registration state. - */ - - }, { - key: "isRegistered", - value: function isRegistered() { - return this._registrator.registered; - } - /** - * Connection state. - */ - - }, { - key: "isConnected", - value: function isConnected() { - return this._transport.isConnected(); - } - /** - * Make an outgoing call. - * - * -param {String} target - * -param {Object} [options] - * - * -throws {TypeError} - * - */ - - }, { - key: "call", - value: function call(target, options) { - debug('call()'); - var session = new RTCSession(this); - session.connect(target, options); - return session; - } - /** - * Send a message. - * - * -param {String} target - * -param {String} body - * -param {Object} [options] - * - * -throws {TypeError} - * - */ - - }, { - key: "sendMessage", - value: function sendMessage(target, body, options) { - debug('sendMessage()'); - var message = new Message(this); - message.send(target, body, options); - return message; - } - /* arbitrary client transaction */ - - }, { - key: "sendRequest", - value: function sendRequest(method, target, params, headers, body, handlers, credential) { - debug('sendRequest()'); - var request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); - var requestSender = new RequestSender(this, request, handlers, credential); - requestSender.send(); - } - /** - * Terminate ongoing sessions. - */ - - }, { - key: "terminateSessions", - value: function terminateSessions(options) { - debug('terminateSessions()'); - - for (var idx in this._sessions) { - if (!this._sessions[idx].isEnded()) { - this._sessions[idx].terminate(options); - } - } - } - /** - * Gracefully close. - * - */ - - }, { - key: "stop", - value: function stop() { - var _this2 = this; - - debug('stop()'); // Remove dynamic settings. - - this._dynConfiguration = {}; - - if (this._status === C.STATUS_USER_CLOSED) { - debug('UA already closed'); - return; - } // Close registrator. - - - this._registrator.close(); // If there are session wait a bit so CANCEL/BYE can be sent and their responses received. - - - var num_sessions = Object.keys(this._sessions).length; // Run _terminate_ on every Session. - - for (var session in this._sessions) { - if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { - debug("closing session ".concat(session)); - - try { - this._sessions[session].terminate(); - } catch (error) {} - } - } // Run _close_ on every applicant. - - - for (var applicant in this._applicants) { - if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try { - this._applicants[applicant].close(); - } catch (error) {} - } - - this._status = C.STATUS_USER_CLOSED; - var num_transactions = Object.keys(this._transactions.nict).length + Object.keys(this._transactions.nist).length + Object.keys(this._transactions.ict).length + Object.keys(this._transactions.ist).length; - - if (num_transactions === 0 && num_sessions === 0) { - this._transport.disconnect(); - } else { - this._closeTimer = setTimeout(function () { - _this2._closeTimer = null; - - _this2._transport.disconnect(); - }, 2000); - } - } - /** - * Normalice a string into a valid SIP request URI - * -param {String} target - * -returns {JsSIP.URI|undefined} - */ - - }, { - key: "normalizeTarget", - value: function normalizeTarget(target) { - return Utils.normalizeTarget(target, this._configuration.hostport_params); - } - /** - * Allow retrieving configuration and autogenerated fields in runtime. - */ - - }, { - key: "get", - value: function get(parameter) { - switch (parameter) { - case 'authorization_user': - return this._configuration.authorization_user; - - case 'realm': - return this._configuration.realm; - - case 'ha1': - return this._configuration.ha1; - - case 'authorization_jwt': - return this._configuration.authorization_jwt; - - default: - debugerror('get() | cannot get "%s" parameter in runtime', parameter); - return undefined; - } - } - /** - * Allow configuration changes in runtime. - * Returns true if the parameter could be set. - */ - - }, { - key: "set", - value: function set(parameter, value) { - switch (parameter) { - case 'authorization_user': - { - this._configuration.authorization_user = String(value); - break; - } - - case 'password': - { - this._configuration.password = String(value); - break; - } - - case 'realm': - { - this._configuration.realm = String(value); - break; - } - - case 'ha1': - { - this._configuration.ha1 = String(value); // Delete the plain SIP password. - - this._configuration.password = null; - break; - } - - case 'authorization_jwt': - { - this._configuration.authorization_jwt = String(value); - break; - } - - case 'display_name': - { - this._configuration.display_name = value; - break; - } - - default: - debugerror('set() | cannot set "%s" parameter in runtime', parameter); - return false; - } - - return true; - } // ========================== - // Event Handlers. - // ========================== - - /** - * new Transaction - */ - - }, { - key: "newTransaction", - value: function newTransaction(transaction) { - this._transactions[transaction.type][transaction.id] = transaction; - this.emit('newTransaction', { - transaction: transaction - }); - } - /** - * Transaction destroyed. - */ - - }, { - key: "destroyTransaction", - value: function destroyTransaction(transaction) { - delete this._transactions[transaction.type][transaction.id]; - this.emit('transactionDestroyed', { - transaction: transaction - }); - } - /** - * new Dialog - */ - - }, { - key: "newDialog", - value: function newDialog(dialog) { - this._dialogs[dialog.id] = dialog; - } - /** - * Dialog destroyed. - */ - - }, { - key: "destroyDialog", - value: function destroyDialog(dialog) { - delete this._dialogs[dialog.id]; - } - /** - * new Message - */ - - }, { - key: "newMessage", - value: function newMessage(message, data) { - this._applicants[message] = message; - this.emit('newMessage', data); - } - /** - * Message destroyed. - */ - - }, { - key: "destroyMessage", - value: function destroyMessage(message) { - delete this._applicants[message]; - } - /** - * new RTCSession - */ - - }, { - key: "newRTCSession", - value: function newRTCSession(session, data) { - this._sessions[session.id] = session; - this.emit('newRTCSession', data); - } - /** - * RTCSession destroyed. - */ - - }, { - key: "destroyRTCSession", - value: function destroyRTCSession(session) { - delete this._sessions[session.id]; - } - /** - * Registered - */ - - }, { - key: "registered", - value: function registered(data) { - this.emit('registered', data); - } - /** - * Unregistered - */ - - }, { - key: "unregistered", - value: function unregistered(data) { - this.emit('unregistered', data); - } - /** - * Registration Failed - */ - - }, { - key: "registrationFailed", - value: function registrationFailed(data) { - this.emit('registrationFailed', data); - } // ========================= - // ReceiveRequest. - // ========================= - - /** - * Request reception - */ - - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - var method = request.method; // Check that request URI points to us. - - if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { - debug('Request-URI does not point to us'); - - if (request.method !== JsSIP_C.ACK) { - request.reply_sl(404); - } - - return; - } // Check request URI scheme. - - - if (request.ruri.scheme === JsSIP_C.SIPS) { - request.reply_sl(416); - return; - } // Check transaction. - - - if (Transactions.checkTransaction(this, request)) { - return; - } // Create the server transaction. - - - if (method === JsSIP_C.INVITE) { - /* eslint-disable no-new */ - new Transactions.InviteServerTransaction(this, this._transport, request); - /* eslint-enable no-new */ - } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) { - /* eslint-disable no-new */ - new Transactions.NonInviteServerTransaction(this, this._transport, request); - /* eslint-enable no-new */ - } - /* RFC3261 12.2.2 - * Requests that do not change in any way the state of a dialog may be - * received within a dialog (for example, an OPTIONS request). - * They are processed as if they had been received outside the dialog. - */ - - - if (method === JsSIP_C.OPTIONS) { - request.reply(200); - } else if (method === JsSIP_C.MESSAGE) { - if (this.listeners('newMessage').length === 0) { - request.reply(405); - return; - } - - var message = new Message(this); - message.init_incoming(request); - } // incoming subscribe - else if (method === JsSIP_C.SUBSCRIBE) { - if (this.listeners('newSubscribe').length === 0) { - request.reply(405); - return; - } - } else if (method === JsSIP_C.INVITE) { - // Initial INVITE. - if (!request.to_tag && this.listeners('newRTCSession').length === 0) { - request.reply(405); - return; - } - } - - var dialog; - var session; // Initial Request. - - if (!request.to_tag) { - switch (method) { - case JsSIP_C.INVITE: - if (window.RTCPeerConnection) { - // TODO - if (request.hasHeader('replaces')) { - var replaces = request.replaces; - dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag); - - if (dialog) { - session = dialog.owner; - - if (!session.isEnded()) { - session.receiveRequest(request); - } else { - request.reply(603); - } - } else { - request.reply(481); - } - } else { - session = new RTCSession(this); - session.init_incoming(request); - } - } else { - debugerror('INVITE received but WebRTC is not supported'); - request.reply(488); - } - - break; - - case JsSIP_C.BYE: - // Out of dialog BYE received. - request.reply(481); - break; - - case JsSIP_C.CANCEL: - session = this._findSession(request); - - if (session) { - session.receiveRequest(request); - } else { - debug('received CANCEL request for a non existent session'); - } - - break; - - case JsSIP_C.ACK: - /* Absorb it. - * ACK request without a corresponding Invite Transaction - * and without To tag. - */ - break; - - case JsSIP_C.NOTIFY: - // Receive new sip event. - this.emit('sipEvent', { - event: request.event, - request: request - }); - request.reply(200); - break; - - case JsSIP_C.SUBSCRIBE: - // Igor's extension: incoming SUBSCRIBE - this.emit('newSubscribe', { - event: request.event, - request: request - }); - break; - - default: - request.reply(405); - break; - } - } // In-dialog request. - else { - dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag); - - if (dialog) { - dialog.receiveRequest(request); - } else if (method === JsSIP_C.NOTIFY) { - session = this._findSession(request); - - if (session) { - session.receiveRequest(request); - } else { - debug('received NOTIFY request for a non existent subscription'); - request.reply(481, 'Subscription does not exist'); - } - } - /* RFC3261 12.2.2 - * Request with to tag, but no matching dialog found. - * Exception: ACK for an Invite request for which a dialog has not - * been created. - */ - else if (method !== JsSIP_C.ACK) { - request.reply(481); - } - } - } // ================= - // Utils. - // ================= - - /** - * Get the session to which the request belongs to, if any. - */ - - }, { - key: "_findSession", - value: function _findSession(_ref) { - var call_id = _ref.call_id, - from_tag = _ref.from_tag, - to_tag = _ref.to_tag; - var sessionIDa = call_id + from_tag; - var sessionA = this._sessions[sessionIDa]; - var sessionIDb = call_id + to_tag; - var sessionB = this._sessions[sessionIDb]; - - if (sessionA) { - return sessionA; - } else if (sessionB) { - return sessionB; - } else { - return null; - } - } - /** - * Get the dialog to which the request belongs to, if any. - */ - - }, { - key: "_findDialog", - value: function _findDialog(call_id, from_tag, to_tag) { - var id = call_id + from_tag + to_tag; - var dialog = this._dialogs[id]; - - if (dialog) { - return dialog; - } else { - id = call_id + to_tag + from_tag; - dialog = this._dialogs[id]; - - if (dialog) { - return dialog; - } else { - return null; - } - } - } - }, { - key: "_loadConfig", - value: function _loadConfig(configuration) { - // Check and load the given configuration. - try { - config.load(this._configuration, configuration); - } catch (e) { - throw e; - } // Post Configuration Process. - // Allow passing 0 number as display_name. - - - if (this._configuration.display_name === 0) { - this._configuration.display_name = '0'; - } // Instance-id for GRUU. - - - if (!this._configuration.instance_id) { - this._configuration.instance_id = Utils.newUUID(); - } // Jssip_id instance parameter. Static random tag of length 5. - - - this._configuration.jssip_id = Utils.createRandomToken(5); // String containing this._configuration.uri without scheme and user. - - var hostport_params = this._configuration.uri.clone(); - - hostport_params.user = null; - this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, ''); // Transport. - - try { - this._transport = new Transport(this._configuration.sockets, { - // Recovery options. - max_interval: this._configuration.connection_recovery_max_interval, - min_interval: this._configuration.connection_recovery_min_interval - }); // Transport event callbacks. - - this._transport.onconnecting = onTransportConnecting.bind(this); - this._transport.onconnect = onTransportConnect.bind(this); - this._transport.ondisconnect = onTransportDisconnect.bind(this); - this._transport.ondata = onTransportData.bind(this); - } catch (e) { - debugerror(e); - throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); - } // Remove sockets instance from configuration object. - - - delete this._configuration.sockets; // Check whether authorization_user is explicitly defined. - // Take 'this._configuration.uri.user' value if not. - - if (!this._configuration.authorization_user) { - this._configuration.authorization_user = this._configuration.uri.user; - } // If no 'registrar_server' is set use the 'uri' value without user portion and - // without URI params/headers. - - - if (!this._configuration.registrar_server) { - var registrar_server = this._configuration.uri.clone(); - - registrar_server.user = null; - registrar_server.clearParams(); - registrar_server.clearHeaders(); - this._configuration.registrar_server = registrar_server; - } // User no_answer_timeout. - - - this._configuration.no_answer_timeout *= 1000; // Via Host. - - if (this._configuration.contact_uri) { - this._configuration.via_host = this._configuration.contact_uri.host; - } // Contact URI. - else { - this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, { - transport: 'ws' - }); - } - - this._contact = { - pub_gruu: null, - temp_gruu: null, - uri: this._configuration.contact_uri, - toString: function toString() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - var anonymous = options.anonymous || null; - var outbound = options.outbound || null; - var contact = '<'; - - if (anonymous) { - contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws'; - } else { - contact += this.pub_gruu || this.uri.toString(); - } - - if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) { - contact += ';ob'; - } - - contact += '>'; - return contact; - } - }; // Seal the configuration. - - var writable_parameters = ['authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register']; - - for (var parameter in this._configuration) { - if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) { - if (writable_parameters.indexOf(parameter) !== -1) { - Object.defineProperty(this._configuration, parameter, { - writable: true, - configurable: false - }); - } else { - Object.defineProperty(this._configuration, parameter, { - writable: false, - configurable: false - }); - } - } - } - - debug('configuration parameters after validation:'); - - for (var _parameter in this._configuration) { - // Only show the user user configurable parameters. - if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) { - switch (_parameter) { - case 'uri': - case 'registrar_server': - debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); - break; - - case 'password': - case 'ha1': - case 'authorization_jwt': - debug("- ".concat(_parameter, ": NOT SHOWN")); - break; - - default: - debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); - } - } - } - - return; - } - }], [{ - key: "C", - get: // Expose C object. - function get() { - return C; - } - }]); - - return UA; -}(EventEmitter); -/** - * Transport event handlers - */ -// Transport connecting event. - - -function onTransportConnecting(data) { - this.emit('connecting', data); -} // Transport connected event. - - -function onTransportConnect(data) { - if (this._status === C.STATUS_USER_CLOSED) { - return; - } - - this._status = C.STATUS_READY; - this._error = null; - this.emit('connected', data); - - if (this._dynConfiguration.register) { - this._registrator.register(); - } -} // Transport disconnected event. - - -function onTransportDisconnect(data) { - // Run _onTransportError_ callback on every client transaction using _transport_. - var client_transactions = ['nict', 'ict', 'nist', 'ist']; - - for (var _i = 0, _client_transactions = client_transactions; _i < _client_transactions.length; _i++) { - var type = _client_transactions[_i]; - - for (var id in this._transactions[type]) { - if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) { - this._transactions[type][id].onTransportError(); - } - } - } - - this.emit('disconnected', data); // Call registrator _onTransportClosed_. - - this._registrator.onTransportClosed(); - - if (this._status !== C.STATUS_USER_CLOSED) { - this._status = C.STATUS_NOT_READY; - this._error = C.NETWORK_ERROR; - } -} // Transport data event. - - -function onTransportData(data) { - var transport = data.transport; - var message = data.message; - message = Parser.parseMessage(message, this); - - if (!message) { - return; - } - - if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) { - return; - } // Do some sanity check. - - - if (!sanityCheck(message, this, transport)) { - return; - } - - if (message instanceof SIPMessage.IncomingRequest) { - message.transport = transport; - this.receiveRequest(message); - } else if (message instanceof SIPMessage.IncomingResponse) { - /* Unike stated in 18.1.2, if a response does not match - * any transaction, it is discarded here and no passed to the core - * in order to be discarded there. - */ - var transaction; - - switch (message.method) { - case JsSIP_C.INVITE: - transaction = this._transactions.ict[message.via_branch]; - - if (transaction) { - transaction.receiveResponse(message); - } - - break; - - case JsSIP_C.ACK: - // Just in case ;-). - break; - - default: - transaction = this._transactions.nict[message.via_branch]; - - if (transaction) { - transaction.receiveResponse(message); - } - - break; - } - } -} -},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./RequestSender":18,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":30,"events":29}],25:[function(require,module,exports){ -"use strict"; - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var JsSIP_C = require('./Constants'); - -var Utils = require('./Utils'); - -var Grammar = require('./Grammar'); -/** - * -param {String} [scheme] - * -param {String} [user] - * -param {String} host - * -param {String} [port] - * -param {Object} [parameters] - * -param {Object} [headers] - * - */ - - -module.exports = /*#__PURE__*/function () { - function URI(scheme, user, host, port) { - var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; - var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; - - _classCallCheck(this, URI); - - // Checks. - if (!host) { - throw new TypeError('missing or invalid "host" parameter'); - } // Initialize parameters. - - - this._parameters = {}; - this._headers = {}; - this._scheme = scheme || JsSIP_C.SIP; - this._user = user; - this._host = host; - this._port = port; - - for (var param in parameters) { - if (Object.prototype.hasOwnProperty.call(parameters, param)) { - this.setParam(param, parameters[param]); - } - } - - for (var header in headers) { - if (Object.prototype.hasOwnProperty.call(headers, header)) { - this.setHeader(header, headers[header]); - } - } - } - - _createClass(URI, [{ - key: "scheme", - get: function get() { - return this._scheme; - }, - set: function set(value) { - this._scheme = value.toLowerCase(); - } - }, { - key: "user", - get: function get() { - return this._user; - }, - set: function set(value) { - this._user = value; - } - }, { - key: "host", - get: function get() { - return this._host; - }, - set: function set(value) { - this._host = value.toLowerCase(); - } - }, { - key: "port", - get: function get() { - return this._port; - }, - set: function set(value) { - this._port = value === 0 ? value : parseInt(value, 10) || null; - } - }, { - key: "setParam", - value: function setParam(key, value) { - if (key) { - this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString(); - } - } - }, { - key: "getParam", - value: function getParam(key) { - if (key) { - return this._parameters[key.toLowerCase()]; - } - } - }, { - key: "hasParam", - value: function hasParam(key) { - if (key) { - return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false; - } - } - }, { - key: "deleteParam", - value: function deleteParam(parameter) { - parameter = parameter.toLowerCase(); - - if (this._parameters.hasOwnProperty(parameter)) { - var value = this._parameters[parameter]; - delete this._parameters[parameter]; - return value; - } - } - }, { - key: "clearParams", - value: function clearParams() { - this._parameters = {}; - } - }, { - key: "setHeader", - value: function setHeader(name, value) { - this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value]; - } - }, { - key: "getHeader", - value: function getHeader(name) { - if (name) { - return this._headers[Utils.headerize(name)]; - } - } - }, { - key: "hasHeader", - value: function hasHeader(name) { - if (name) { - return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false; - } - } - }, { - key: "deleteHeader", - value: function deleteHeader(header) { - header = Utils.headerize(header); - - if (this._headers.hasOwnProperty(header)) { - var value = this._headers[header]; - delete this._headers[header]; - return value; - } - } - }, { - key: "clearHeaders", - value: function clearHeaders() { - this._headers = {}; - } - }, { - key: "clone", - value: function clone() { - return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers))); - } - }, { - key: "toString", - value: function toString() { - var headers = []; - var uri = "".concat(this._scheme, ":"); - - if (this._user) { - uri += "".concat(Utils.escapeUser(this._user), "@"); - } - - uri += this._host; - - if (this._port || this._port === 0) { - uri += ":".concat(this._port); - } - - for (var parameter in this._parameters) { - if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) { - uri += ";".concat(parameter); - - if (this._parameters[parameter] !== null) { - uri += "=".concat(this._parameters[parameter]); - } - } - } - - for (var header in this._headers) { - if (Object.prototype.hasOwnProperty.call(this._headers, header)) { - var _iterator = _createForOfIteratorHelper(this._headers[header]), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var item = _step.value; - headers.push("".concat(header, "=").concat(item)); - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } - } - - if (headers.length > 0) { - uri += "?".concat(headers.join('&')); - } - - return uri; - } - }, { - key: "toAor", - value: function toAor(show_port) { - var aor = "".concat(this._scheme, ":"); - - if (this._user) { - aor += "".concat(Utils.escapeUser(this._user), "@"); - } - - aor += this._host; - - if (show_port && (this._port || this._port === 0)) { - aor += ":".concat(this._port); - } - - return aor; - } - }], [{ - key: "parse", - value: - /** - * Parse the given string and returns a JsSIP.URI instance or undefined if - * it is an invalid URI. - */ - function parse(uri) { - uri = Grammar.parse(uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } else { - return undefined; - } - } - }]); - - return URI; -}(); -},{"./Constants":2,"./Grammar":7,"./Utils":26}],26:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var JsSIP_C = require('./Constants'); - -var URI = require('./URI'); - -var Grammar = require('./Grammar'); - -exports.str_utf8_length = function (string) { - return unescape(encodeURIComponent(string)).length; -}; // Used by 'hasMethods'. - - -var isFunction = exports.isFunction = function (fn) { - if (fn !== undefined) { - return Object.prototype.toString.call(fn) === '[object Function]' ? true : false; - } else { - return false; - } -}; - -exports.isString = function (str) { - if (str !== undefined) { - return Object.prototype.toString.call(str) === '[object String]' ? true : false; - } else { - return false; - } -}; - -exports.isDecimal = function (num) { - return !isNaN(num) && parseFloat(num) === parseInt(num, 10); -}; - -exports.isEmpty = function (value) { - return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value); -}; - -exports.hasMethods = function (obj) { - for (var _len = arguments.length, methodNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - methodNames[_key - 1] = arguments[_key]; - } - - for (var _i = 0, _methodNames = methodNames; _i < _methodNames.length; _i++) { - var methodName = _methodNames[_i]; - - if (isFunction(obj[methodName])) { - return false; - } - } - - return true; -}; // Used by 'newTag'. - - -var createRandomToken = exports.createRandomToken = function (size) { - var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32; - var i, - r, - token = ''; - - for (i = 0; i < size; i++) { - r = Math.random() * base | 0; - token += r.toString(base); - } - - return token; -}; - -exports.newTag = function () { - return createRandomToken(10); -}; // https://stackoverflow.com/users/109538/broofa. - - -exports.newUUID = function () { - var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r = Math.random() * 16 | 0, - v = c === 'x' ? r : r & 0x3 | 0x8; - return v.toString(16); - }); - return UUID; -}; - -exports.hostType = function (host) { - if (!host) { - return; - } else { - host = Grammar.parse(host, 'host'); - - if (host !== -1) { - return host.host_type; - } - } -}; -/** -* Hex-escape a SIP URI user. -* Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F). -* -* Used by 'normalizeTarget'. -*/ - - -var escapeUser = exports.escapeUser = function (user) { - return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/'); -}; -/** -* Normalize SIP URI. -* NOTE: It does not allow a SIP URI without username. -* Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'. -* Detects the domain part (if given) and properly hex-escapes the user portion. -* If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators. -*/ - - -exports.normalizeTarget = function (target, domain) { - // If no target is given then raise an error. - if (!target) { - return; // If a URI instance is given then return it. - } else if (target instanceof URI) { - return target; // If a string is given split it by '@': - // - Last fragment is the desired domain. - // - Otherwise append the given domain argument. - } else if (typeof target === 'string') { - var target_array = target.split('@'); - var target_user; - var target_domain; - - switch (target_array.length) { - case 1: - if (!domain) { - return; - } - - target_user = target; - target_domain = domain; - break; - - case 2: - target_user = target_array[0]; - target_domain = target_array[1]; - break; - - default: - target_user = target_array.slice(0, target_array.length - 1).join('@'); - target_domain = target_array[target_array.length - 1]; - } // Remove the URI scheme (if present). - - - target_user = target_user.replace(/^(sips?|tel):/i, ''); // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols. - - if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) { - target_user = target_user.replace(/[-.()]/g, ''); - } // Build the complete SIP URI. - - - target = "".concat(JsSIP_C.SIP, ":").concat(escapeUser(target_user), "@").concat(target_domain); // Finally parse the resulting URI. - - var uri; - - if (uri = URI.parse(target)) { - return uri; - } else { - return; - } - } else { - return; - } -}; - -exports.headerize = function (string) { - var exceptions = { - 'Call-Id': 'Call-ID', - 'Cseq': 'CSeq', - 'Www-Authenticate': 'WWW-Authenticate' - }; - var name = string.toLowerCase().replace(/_/g, '-').split('-'); - var hname = ''; - var parts = name.length; - var part; - - for (part = 0; part < parts; part++) { - if (part !== 0) { - hname += '-'; - } - - hname += name[part].charAt(0).toUpperCase() + name[part].substring(1); - } - - if (exceptions[hname]) { - hname = exceptions[hname]; - } - - return hname; -}; - -exports.sipErrorCause = function (status_code) { - for (var cause in JsSIP_C.SIP_ERROR_CAUSES) { - if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) { - return JsSIP_C.causes[cause]; - } - } - - return JsSIP_C.causes.SIP_FAILURE_CODE; -}; -/** -* Generate a random Test-Net IP (https://tools.ietf.org/html/rfc5735) -*/ - - -exports.getRandomTestNetIP = function () { - function getOctet(from, to) { - return Math.floor(Math.random() * (to - from + 1) + from); - } - - return "192.0.2.".concat(getOctet(1, 254)); -}; // MD5 (Message-Digest Algorithm) https://www.webtoolkit.info. - - -exports.calculateMD5 = function (string) { - function rotateLeft(lValue, iShiftBits) { - return lValue << iShiftBits | lValue >>> 32 - iShiftBits; - } - - function addUnsigned(lX, lY) { - var lX8 = lX & 0x80000000; - var lY8 = lY & 0x80000000; - var lX4 = lX & 0x40000000; - var lY4 = lY & 0x40000000; - var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); - - if (lX4 & lY4) { - return lResult ^ 0x80000000 ^ lX8 ^ lY8; - } - - if (lX4 | lY4) { - if (lResult & 0x40000000) { - return lResult ^ 0xC0000000 ^ lX8 ^ lY8; - } else { - return lResult ^ 0x40000000 ^ lX8 ^ lY8; - } - } else { - return lResult ^ lX8 ^ lY8; - } - } - - function doF(x, y, z) { - return x & y | ~x & z; - } - - function doG(x, y, z) { - return x & z | y & ~z; - } - - function doH(x, y, z) { - return x ^ y ^ z; - } - - function doI(x, y, z) { - return y ^ (x | ~z); - } - - function doFF(a, b, c, d, x, s, ac) { - a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac)); - return addUnsigned(rotateLeft(a, s), b); - } - - function doGG(a, b, c, d, x, s, ac) { - a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac)); - return addUnsigned(rotateLeft(a, s), b); - } - - function doHH(a, b, c, d, x, s, ac) { - a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac)); - return addUnsigned(rotateLeft(a, s), b); - } - - function doII(a, b, c, d, x, s, ac) { - a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac)); - return addUnsigned(rotateLeft(a, s), b); - } - - function convertToWordArray(str) { - var lWordCount; - var lMessageLength = str.length; - var lNumberOfWords_temp1 = lMessageLength + 8; - var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64; - var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; - var lWordArray = new Array(lNumberOfWords - 1); - var lBytePosition = 0; - var lByteCount = 0; - - while (lByteCount < lMessageLength) { - lWordCount = (lByteCount - lByteCount % 4) / 4; - lBytePosition = lByteCount % 4 * 8; - lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition; - lByteCount++; - } - - lWordCount = (lByteCount - lByteCount % 4) / 4; - lBytePosition = lByteCount % 4 * 8; - lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition; - lWordArray[lNumberOfWords - 2] = lMessageLength << 3; - lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; - return lWordArray; - } - - function wordToHex(lValue) { - var wordToHexValue = '', - wordToHexValue_temp = '', - lByte, - lCount; - - for (lCount = 0; lCount <= 3; lCount++) { - lByte = lValue >>> lCount * 8 & 255; - wordToHexValue_temp = "0".concat(lByte.toString(16)); - wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2); - } - - return wordToHexValue; - } - - function utf8Encode(str) { - str = str.replace(/\r\n/g, '\n'); - var utftext = ''; - - for (var n = 0; n < str.length; n++) { - var _c = str.charCodeAt(n); - - if (_c < 128) { - utftext += String.fromCharCode(_c); - } else if (_c > 127 && _c < 2048) { - utftext += String.fromCharCode(_c >> 6 | 192); - utftext += String.fromCharCode(_c & 63 | 128); - } else { - utftext += String.fromCharCode(_c >> 12 | 224); - utftext += String.fromCharCode(_c >> 6 & 63 | 128); - utftext += String.fromCharCode(_c & 63 | 128); - } - } - - return utftext; - } - - var x = []; - var k, AA, BB, CC, DD, a, b, c, d; - var S11 = 7, - S12 = 12, - S13 = 17, - S14 = 22; - var S21 = 5, - S22 = 9, - S23 = 14, - S24 = 20; - var S31 = 4, - S32 = 11, - S33 = 16, - S34 = 23; - var S41 = 6, - S42 = 10, - S43 = 15, - S44 = 21; - string = utf8Encode(string); - x = convertToWordArray(string); - a = 0x67452301; - b = 0xEFCDAB89; - c = 0x98BADCFE; - d = 0x10325476; - - for (k = 0; k < x.length; k += 16) { - AA = a; - BB = b; - CC = c; - DD = d; - a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478); - d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); - c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB); - b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); - a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); - d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A); - c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613); - b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501); - a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8); - d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); - c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); - b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); - a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122); - d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193); - c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E); - b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821); - a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562); - d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340); - c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51); - b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); - a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D); - d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453); - c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); - b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); - a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); - d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6); - c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); - b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED); - a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); - d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); - c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9); - b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); - a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); - d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681); - c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); - b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); - a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); - d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); - c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); - b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); - a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); - d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); - c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); - b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05); - a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); - d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); - c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); - b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); - a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244); - d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97); - c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7); - b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039); - a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3); - d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); - c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); - b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1); - a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); - d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); - c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314); - b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1); - a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82); - d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235); - c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); - b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391); - a = addUnsigned(a, AA); - b = addUnsigned(b, BB); - c = addUnsigned(c, CC); - d = addUnsigned(d, DD); - } - - var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); - return temp.toLowerCase(); -}; - -exports.closeMediaStream = function (stream) { - if (!stream) { - return; - } // Latest spec states that MediaStream has no stop() method and instead must - // call stop() on every MediaStreamTrack. - - - try { - var tracks; - - if (stream.getTracks) { - tracks = stream.getTracks(); - - var _iterator = _createForOfIteratorHelper(tracks), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var track = _step.value; - track.stop(); - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } else { - tracks = stream.getAudioTracks(); - - var _iterator2 = _createForOfIteratorHelper(tracks), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var _track = _step2.value; - - _track.stop(); - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - - tracks = stream.getVideoTracks(); - - var _iterator3 = _createForOfIteratorHelper(tracks), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var _track2 = _step3.value; - - _track2.stop(); - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } - } - } catch (error) { - // Deprecated by the spec, but still in use. - // NOTE: In Temasys IE plugin stream.stop is a callable 'object'. - if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') { - stream.stop(); - } - } -}; - -exports.cloneArray = function (array) { - return array && array.slice() || []; -}; - -exports.cloneObject = function (obj) { - var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - return obj && Object.assign({}, obj) || fallback; -}; -},{"./Constants":2,"./Grammar":7,"./URI":25}],27:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Grammar = require('./Grammar'); - -var debug = require('debug')('JsSIP:WebSocketInterface'); - -var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); - -debugerror.log = console.warn.bind(console); - -module.exports = /*#__PURE__*/function () { - function WebSocketInterface(url) { - _classCallCheck(this, WebSocketInterface); - - debug('new() [url:"%s"]', url); - this._url = url; - this._sip_uri = null; - this._via_transport = null; - this._ws = null; - var parsed_url = Grammar.parse(url, 'absoluteURI'); - - if (parsed_url === -1) { - debugerror("invalid WebSocket URI: ".concat(url)); - throw new TypeError("Invalid argument: ".concat(url)); - } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { - debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); - throw new TypeError("Invalid argument: ".concat(url)); - } else { - this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws"); - this._via_transport = parsed_url.scheme.toUpperCase(); - } - } - - _createClass(WebSocketInterface, [{ - key: "via_transport", - get: function get() { - return this._via_transport; - }, - set: function set(value) { - this._via_transport = value.toUpperCase(); - } - }, { - key: "sip_uri", - get: function get() { - return this._sip_uri; - } - }, { - key: "url", - get: function get() { - return this._url; - } - }, { - key: "connect", - value: function connect() { - debug('connect()'); - - if (this.isConnected()) { - debug("WebSocket ".concat(this._url, " is already connected")); - return; - } else if (this.isConnecting()) { - debug("WebSocket ".concat(this._url, " is connecting")); - return; - } - - if (this._ws) { - this.disconnect(); - } - - debug("connecting to WebSocket ".concat(this._url)); - - try { - this._ws = new WebSocket(this._url, 'sip'); - this._ws.binaryType = 'arraybuffer'; - this._ws.onopen = this._onOpen.bind(this); - this._ws.onclose = this._onClose.bind(this); - this._ws.onmessage = this._onMessage.bind(this); - this._ws.onerror = this._onError.bind(this); - } catch (e) { - this._onError(e); - } - } - }, { - key: "disconnect", - value: function disconnect() { - debug('disconnect()'); - - if (this._ws) { - // Unbind websocket event callbacks. - 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 send(message) { - debug('send()'); - - if (this.isConnected()) { - this._ws.send(message); - - return true; - } else { - debugerror('unable to send message, WebSocket is not open'); - return false; - } - } - }, { - key: "isConnected", - value: function isConnected() { - return this._ws && this._ws.readyState === this._ws.OPEN; - } - }, { - key: "isConnecting", - value: function isConnecting() { - return this._ws && this._ws.readyState === this._ws.CONNECTING; - } - /** - * WebSocket Event Handlers - */ - - }, { - key: "_onOpen", - value: function _onOpen() { - debug("WebSocket ".concat(this._url, " connected")); - this.onconnect(); - } - }, { - key: "_onClose", - value: function _onClose(_ref) { - var wasClean = _ref.wasClean, - code = _ref.code, - reason = _ref.reason; - debug("WebSocket ".concat(this._url, " closed")); - - if (wasClean === false) { - debug('WebSocket abrupt disconnection'); - } - - this.ondisconnect(!wasClean, code, reason); - } - }, { - key: "_onMessage", - value: function _onMessage(_ref2) { - var data = _ref2.data; - debug('received WebSocket message'); - this.ondata(data); - } - }, { - key: "_onError", - value: function _onError(e) { - debugerror("WebSocket ".concat(this._url, " error: "), e); - } - }]); - - return WebSocketInterface; -}(); -},{"./Grammar":7,"debug":30}],28:[function(require,module,exports){ -"use strict"; - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var JsSIP_C = require('./Constants'); - -var SIPMessage = require('./SIPMessage'); - -var Utils = require('./Utils'); - -var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses. - - -var all = [minimumHeaders]; // Checks for requests. - -var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2]; // Checks for responses. - -var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response]; // local variables. - -var message; -var ua; -var transport; - -module.exports = function (m, u, t) { - message = m; - ua = u; - transport = t; - - var _iterator = _createForOfIteratorHelper(all), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var _check2 = _step.value; - - if (_check2() === false) { - return false; - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - - if (message instanceof SIPMessage.IncomingRequest) { - var _iterator2 = _createForOfIteratorHelper(requests), - _step2; - - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var check = _step2.value; - - if (check() === false) { - return false; - } - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - } else if (message instanceof SIPMessage.IncomingResponse) { - var _iterator3 = _createForOfIteratorHelper(responses), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var _check = _step3.value; - - if (_check() === false) { - return false; - } - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } - } // Everything is OK. - - - return true; -}; -/* - * Sanity Check for incoming Messages - * - * Requests: - * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme - * - _rfc3261_16_3_4_ Receive a Request already sent by us - * Does not look at via sent-by but at jssip_id, which is inserted as - * a prefix in all initial requests generated by the ua - * - _rfc3261_18_3_request_ Body Content-Length - * - _rfc3261_8_2_2_2_ Merged Requests - * - * Responses: - * - _rfc3261_8_1_3_3_ Multiple Via headers - * - _rfc3261_18_3_response_ Body Content-Length - * - * All: - * - Minimum headers in a SIP message - */ -// Sanity Check functions for requests. - - -function rfc3261_8_2_2_1() { - if (message.s('to').uri.scheme !== 'sip') { - reply(416); - return false; - } -} - -function rfc3261_16_3_4() { - if (!message.to_tag) { - if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) { - reply(482); - return false; - } - } -} - -function rfc3261_18_3_request() { - var len = Utils.str_utf8_length(message.body); - var contentLength = message.getHeader('content-length'); - - if (len < contentLength) { - reply(400); - return false; - } -} - -function rfc3261_8_2_2_2() { - var fromTag = message.from_tag; - var call_id = message.call_id; - var cseq = message.cseq; - var tr; // Accept any in-dialog request. - - if (message.to_tag) { - return; - } // INVITE request. - - - if (message.method === JsSIP_C.INVITE) { - // If the branch matches the key of any IST then assume it is a retransmission - // and ignore the INVITE. - // TODO: we should reply the last response. - if (ua._transactions.ist[message.via_branch]) { - return false; - } // Otherwise check whether it is a merged request. - else { - for (var transaction in ua._transactions.ist) { - if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) { - tr = ua._transactions.ist[transaction]; - - if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) { - reply(482); - return false; - } - } - } - } - } // Non INVITE request. - // If the branch matches the key of any NIST then assume it is a retransmission - // and ignore the request. - // TODO: we should reply the last response. - else if (ua._transactions.nist[message.via_branch]) { - return false; - } // Otherwise check whether it is a merged request. - else { - for (var _transaction in ua._transactions.nist) { - if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) { - tr = ua._transactions.nist[_transaction]; - - if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) { - reply(482); - return false; - } - } - } - } -} // Sanity Check functions for responses. - - -function rfc3261_8_1_3_3() { - if (message.getHeaders('via').length > 1) { - debug('more than one Via header field present in the response, dropping the response'); - return false; - } -} - -function rfc3261_18_3_response() { - var len = Utils.str_utf8_length(message.body), - contentLength = message.getHeader('content-length'); - - if (len < contentLength) { - debug('message body length is lower than the value in Content-Length header field, dropping the response'); - return false; - } -} // Sanity Check functions for requests and responses. - - -function minimumHeaders() { - var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via']; - - for (var _i = 0, _mandatoryHeaders = mandatoryHeaders; _i < _mandatoryHeaders.length; _i++) { - var header = _mandatoryHeaders[_i]; - - if (!message.hasHeader(header)) { - debug("missing mandatory header field : ".concat(header, ", dropping the response")); - return false; - } - } -} // Reply. - - -function reply(status_code) { - var vias = message.getHeaders('via'); - var to; - var response = "SIP/2.0 ".concat(status_code, " ").concat(JsSIP_C.REASON_PHRASE[status_code], "\r\n"); - - var _iterator4 = _createForOfIteratorHelper(vias), - _step4; - - try { - for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - var via = _step4.value; - response += "Via: ".concat(via, "\r\n"); - } - } catch (err) { - _iterator4.e(err); - } finally { - _iterator4.f(); - } - - to = message.getHeader('To'); - - if (!message.to_tag) { - to += ";tag=".concat(Utils.newTag()); - } - - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(message.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(message.call_id, "\r\n"); - response += "CSeq: ".concat(message.cseq, " ").concat(message.method, "\r\n"); - response += '\r\n'; - transport.send(response); -} -},{"./Constants":2,"./SIPMessage":19,"./Utils":26,"debug":30}],29:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var objectCreate = Object.create || objectCreatePolyfill -var objectKeys = Object.keys || objectKeysPolyfill -var bind = Function.prototype.bind || functionBindPolyfill - -function EventEmitter() { - if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) { - this._events = objectCreate(null); - this._eventsCount = 0; - } - - this._maxListeners = this._maxListeners || undefined; -} -module.exports = EventEmitter; - -// Backwards-compat with node 0.10.x -EventEmitter.EventEmitter = EventEmitter; - -EventEmitter.prototype._events = undefined; -EventEmitter.prototype._maxListeners = undefined; - -// By default EventEmitters will print a warning if more than 10 listeners are -// added to it. This is a useful default which helps finding memory leaks. -var defaultMaxListeners = 10; - -var hasDefineProperty; -try { - var o = {}; - if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 }); - hasDefineProperty = o.x === 0; -} catch (err) { hasDefineProperty = false } -if (hasDefineProperty) { - Object.defineProperty(EventEmitter, 'defaultMaxListeners', { - enumerable: true, - get: function() { - return defaultMaxListeners; - }, - set: function(arg) { - // check whether the input is a positive number (whose value is zero or - // greater and not a NaN). - if (typeof arg !== 'number' || arg < 0 || arg !== arg) - throw new TypeError('"defaultMaxListeners" must be a positive number'); - defaultMaxListeners = arg; - } - }); -} else { - EventEmitter.defaultMaxListeners = defaultMaxListeners; -} - -// Obviously not all Emitters should be limited to 10. This function allows -// that to be increased. Set to zero for unlimited. -EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { - if (typeof n !== 'number' || n < 0 || isNaN(n)) - throw new TypeError('"n" argument must be a positive number'); - this._maxListeners = n; - return this; -}; - -function $getMaxListeners(that) { - if (that._maxListeners === undefined) - return EventEmitter.defaultMaxListeners; - return that._maxListeners; -} - -EventEmitter.prototype.getMaxListeners = function getMaxListeners() { - return $getMaxListeners(this); -}; - -// These standalone emit* functions are used to optimize calling of event -// handlers for fast cases because emit() itself often has a variable number of -// arguments and can be deoptimized because of that. These functions always have -// the same number of arguments and thus do not get deoptimized, so the code -// inside them can execute faster. -function emitNone(handler, isFn, self) { - if (isFn) - handler.call(self); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].call(self); - } -} -function emitOne(handler, isFn, self, arg1) { - if (isFn) - handler.call(self, arg1); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].call(self, arg1); - } -} -function emitTwo(handler, isFn, self, arg1, arg2) { - if (isFn) - handler.call(self, arg1, arg2); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].call(self, arg1, arg2); - } -} -function emitThree(handler, isFn, self, arg1, arg2, arg3) { - if (isFn) - handler.call(self, arg1, arg2, arg3); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].call(self, arg1, arg2, arg3); - } -} - -function emitMany(handler, isFn, self, args) { - if (isFn) - handler.apply(self, args); - else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - listeners[i].apply(self, args); - } -} - -EventEmitter.prototype.emit = function emit(type) { - var er, handler, len, args, i, events; - var doError = (type === 'error'); - - events = this._events; - if (events) - doError = (doError && events.error == null); - else if (!doError) - return false; - - // If there is no 'error' event listener then throw. - if (doError) { - if (arguments.length > 1) - er = arguments[1]; - if (er instanceof Error) { - throw er; // Unhandled 'error' event - } else { - // At least give some kind of context to the user - var err = new Error('Unhandled "error" event. (' + er + ')'); - err.context = er; - throw err; - } - return false; - } - - handler = events[type]; - - if (!handler) - return false; - - var isFn = typeof handler === 'function'; - len = arguments.length; - switch (len) { - // fast cases - case 1: - emitNone(handler, isFn, this); - break; - case 2: - emitOne(handler, isFn, this, arguments[1]); - break; - case 3: - emitTwo(handler, isFn, this, arguments[1], arguments[2]); - break; - case 4: - emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]); - break; - // slower - default: - args = new Array(len - 1); - for (i = 1; i < len; i++) - args[i - 1] = arguments[i]; - emitMany(handler, isFn, this, args); - } - - return true; -}; - -function _addListener(target, type, listener, prepend) { - var m; - var events; - var existing; - - if (typeof listener !== 'function') - throw new TypeError('"listener" argument must be a function'); - - events = target._events; - if (!events) { - events = target._events = objectCreate(null); - target._eventsCount = 0; - } else { - // To avoid recursion in the case that type === "newListener"! Before - // adding it to the listeners, first emit "newListener". - if (events.newListener) { - target.emit('newListener', type, - listener.listener ? listener.listener : listener); - - // Re-assign `events` because a newListener handler could have caused the - // this._events to be assigned to a new object - events = target._events; - } - existing = events[type]; - } - - if (!existing) { - // Optimize the case of one listener. Don't need the extra array object. - existing = events[type] = listener; - ++target._eventsCount; - } else { - if (typeof existing === 'function') { - // Adding the second element, need to change to array. - existing = events[type] = - prepend ? [listener, existing] : [existing, listener]; - } else { - // If we've already got an array, just append. - if (prepend) { - existing.unshift(listener); - } else { - existing.push(listener); - } - } - - // Check for listener leak - if (!existing.warned) { - m = $getMaxListeners(target); - if (m && m > 0 && existing.length > m) { - existing.warned = true; - var w = new Error('Possible EventEmitter memory leak detected. ' + - existing.length + ' "' + String(type) + '" listeners ' + - 'added. Use emitter.setMaxListeners() to ' + - 'increase limit.'); - w.name = 'MaxListenersExceededWarning'; - w.emitter = target; - w.type = type; - w.count = existing.length; - if (typeof console === 'object' && console.warn) { - console.warn('%s: %s', w.name, w.message); - } - } - } - } - - return target; -} - -EventEmitter.prototype.addListener = function addListener(type, listener) { - return _addListener(this, type, listener, false); -}; - -EventEmitter.prototype.on = EventEmitter.prototype.addListener; - -EventEmitter.prototype.prependListener = - function prependListener(type, listener) { - return _addListener(this, type, listener, true); - }; - -function onceWrapper() { - if (!this.fired) { - this.target.removeListener(this.type, this.wrapFn); - this.fired = true; - switch (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: - var args = new Array(arguments.length); - for (var i = 0; i < args.length; ++i) - args[i] = arguments[i]; - this.listener.apply(this.target, args); - } - } -} - -function _onceWrap(target, type, listener) { - var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener }; - var wrapped = bind.call(onceWrapper, state); - wrapped.listener = listener; - state.wrapFn = wrapped; - return wrapped; -} - -EventEmitter.prototype.once = function once(type, listener) { - if (typeof listener !== 'function') - throw new TypeError('"listener" argument must be a function'); - this.on(type, _onceWrap(this, type, listener)); - return this; -}; - -EventEmitter.prototype.prependOnceListener = - function prependOnceListener(type, listener) { - if (typeof listener !== 'function') - throw new TypeError('"listener" argument must be a function'); - this.prependListener(type, _onceWrap(this, type, listener)); - return this; - }; - -// Emits a 'removeListener' event if and only if the listener was removed. -EventEmitter.prototype.removeListener = - function removeListener(type, listener) { - var list, events, position, i, originalListener; - - if (typeof listener !== 'function') - throw new TypeError('"listener" argument must be a function'); - - events = this._events; - if (!events) - return this; - - list = events[type]; - if (!list) - return this; - - if (list === listener || list.listener === listener) { - if (--this._eventsCount === 0) - this._events = objectCreate(null); - else { - delete events[type]; - if (events.removeListener) - this.emit('removeListener', type, list.listener || listener); - } - } else if (typeof list !== 'function') { - position = -1; - - for (i = list.length - 1; i >= 0; i--) { - if (list[i] === listener || list[i].listener === listener) { - originalListener = list[i].listener; - position = i; - break; - } - } - - if (position < 0) - return this; - - if (position === 0) - list.shift(); - else - spliceOne(list, position); - - if (list.length === 1) - events[type] = list[0]; - - if (events.removeListener) - this.emit('removeListener', type, originalListener || listener); - } - - return this; - }; - -EventEmitter.prototype.removeAllListeners = - function removeAllListeners(type) { - var listeners, events, i; - - events = this._events; - if (!events) - return this; - - // not listening for removeListener, no need to emit - if (!events.removeListener) { - if (arguments.length === 0) { - this._events = objectCreate(null); - this._eventsCount = 0; - } else if (events[type]) { - if (--this._eventsCount === 0) - this._events = objectCreate(null); - else - delete events[type]; - } - return this; - } - - // emit removeListener for all listeners on all events - if (arguments.length === 0) { - var keys = objectKeys(events); - var key; - for (i = 0; i < keys.length; ++i) { - key = keys[i]; - if (key === 'removeListener') continue; - this.removeAllListeners(key); - } - this.removeAllListeners('removeListener'); - this._events = objectCreate(null); - this._eventsCount = 0; - return this; - } - - listeners = events[type]; - - if (typeof listeners === 'function') { - this.removeListener(type, listeners); - } else if (listeners) { - // LIFO order - for (i = listeners.length - 1; i >= 0; i--) { - this.removeListener(type, listeners[i]); - } - } - - return this; - }; - -function _listeners(target, type, unwrap) { - var events = target._events; - - if (!events) - return []; - - var evlistener = events[type]; - if (!evlistener) - return []; - - if (typeof evlistener === 'function') - return unwrap ? [evlistener.listener || evlistener] : [evlistener]; - - return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); -} - -EventEmitter.prototype.listeners = function listeners(type) { - return _listeners(this, type, true); -}; - -EventEmitter.prototype.rawListeners = function rawListeners(type) { - return _listeners(this, type, false); -}; - -EventEmitter.listenerCount = function(emitter, type) { - if (typeof emitter.listenerCount === 'function') { - return emitter.listenerCount(type); - } else { - return listenerCount.call(emitter, type); - } -}; - -EventEmitter.prototype.listenerCount = listenerCount; -function listenerCount(type) { - var events = this._events; - - if (events) { - var evlistener = events[type]; - - if (typeof evlistener === 'function') { - return 1; - } else if (evlistener) { - return evlistener.length; - } - } - - return 0; -} - -EventEmitter.prototype.eventNames = function eventNames() { - return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : []; -}; - -// About 1.5x faster than the two-arg version of Array#splice(). -function spliceOne(list, index) { - for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) - list[i] = list[k]; - list.pop(); -} - -function arrayClone(arr, n) { - var copy = new Array(n); - for (var i = 0; i < n; ++i) - copy[i] = arr[i]; - return copy; -} - -function unwrapListeners(arr) { - var ret = new Array(arr.length); - for (var i = 0; i < ret.length; ++i) { - ret[i] = arr[i].listener || arr[i]; - } - return ret; -} - -function objectCreatePolyfill(proto) { - var F = function() {}; - F.prototype = proto; - return new F; -} -function objectKeysPolyfill(obj) { - var keys = []; - for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) { - keys.push(k); - } - return k; -} -function functionBindPolyfill(context) { - var fn = this; - return function () { - return fn.apply(context, arguments); - }; -} - -},{}],30:[function(require,module,exports){ -(function (process){(function (){ -/* eslint-env browser */ - -/** - * This is the web browser implementation of `debug()`. - */ - -exports.formatArgs = formatArgs; -exports.save = save; -exports.load = load; -exports.useColors = useColors; -exports.storage = localstorage(); -exports.destroy = (() => { - let warned = false; - - return () => { - if (!warned) { - warned = true; - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); - } - }; -})(); - -/** - * Colors. - */ - -exports.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' -]; - -/** - * Currently only WebKit-based Web Inspectors, Firefox >= v31, - * and the Firebug extension (any Firefox version) are known - * to support "%c" CSS customizations. - * - * TODO: add a `localStorage` variable to explicitly enable/disable colors - */ - -// eslint-disable-next-line complexity -function useColors() { - // NB: In an Electron preload script, document will be defined but not fully - // initialized. Since we know we're in Chrome, we'll just detect this case - // explicitly - if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { - return true; - } - - // Internet Explorer and Edge do not support colors. - if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { - return false; - } - - // Is webkit? http://stackoverflow.com/a/16459606/376773 - // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 - return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || - // Is firebug? http://stackoverflow.com/a/398120/376773 - (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || - // Is firefox >= v31? - // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages - (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || - // Double check webkit in userAgent just in case we are in a worker - (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); -} - -/** - * Colorize log arguments if enabled. - * - * @api public - */ - -function formatArgs(args) { - args[0] = (this.useColors ? '%c' : '') + - this.namespace + - (this.useColors ? ' %c' : ' ') + - args[0] + - (this.useColors ? '%c ' : ' ') + - '+' + module.exports.humanize(this.diff); - - if (!this.useColors) { - return; - } - - const c = 'color: ' + this.color; - args.splice(1, 0, c, 'color: inherit'); - - // The final "%c" is somewhat tricky, because there could be other - // arguments passed either before or after the %c, so we need to - // figure out the correct index to insert the CSS into - let index = 0; - let lastC = 0; - args[0].replace(/%[a-zA-Z%]/g, match => { - if (match === '%%') { - return; - } - index++; - if (match === '%c') { - // We only are interested in the *last* %c - // (the user may have provided their own) - lastC = index; - } - }); - - args.splice(lastC, 0, c); -} - -/** - * Invokes `console.debug()` when available. - * No-op when `console.debug` is not a "function". - * If `console.debug` is not available, falls back - * to `console.log`. - * - * @api public - */ -exports.log = console.debug || console.log || (() => {}); - -/** - * Save `namespaces`. - * - * @param {String} namespaces - * @api private - */ -function save(namespaces) { - try { - if (namespaces) { - exports.storage.setItem('debug', namespaces); - } else { - exports.storage.removeItem('debug'); - } - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? - } -} - -/** - * Load `namespaces`. - * - * @return {String} returns the previously persisted debug modes - * @api private - */ -function load() { - let r; - try { - r = exports.storage.getItem('debug'); - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? - } - - // If debug isn't set in LS, and we're in Electron, try to load $DEBUG - if (!r && typeof process !== 'undefined' && 'env' in process) { - r = process.env.DEBUG; - } - - return r; -} - -/** - * Localstorage attempts to return the localstorage. - * - * This is necessary because safari throws - * when a user disables cookies/localstorage - * and you attempt to access it. - * - * @return {LocalStorage} - * @api private - */ - -function localstorage() { - try { - // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context - // The Browser also has localStorage in the global context. - return localStorage; - } catch (error) { - // Swallow - // XXX (@Qix-) should we be logging these? - } -} - -module.exports = require('./common')(exports); - -const {formatters} = module.exports; - -/** - * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. - */ - -formatters.j = function (v) { - try { - return JSON.stringify(v); - } catch (error) { - return '[UnexpectedJSONParseError]: ' + error.message; - } -}; - -}).call(this)}).call(this,require('_process')) -},{"./common":31,"_process":33}],31:[function(require,module,exports){ - -/** - * This is the common logic for both the Node.js and web browser - * implementations of `debug()`. - */ - -function setup(env) { - createDebug.debug = createDebug; - createDebug.default = createDebug; - createDebug.coerce = coerce; - createDebug.disable = disable; - createDebug.enable = enable; - createDebug.enabled = enabled; - createDebug.humanize = require('ms'); - createDebug.destroy = destroy; - - Object.keys(env).forEach(key => { - createDebug[key] = env[key]; - }); - - /** - * The currently active debug mode names, and names to skip. - */ - - createDebug.names = []; - createDebug.skips = []; - - /** - * Map of special "%n" handling functions, for the debug "format" argument. - * - * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". - */ - createDebug.formatters = {}; - - /** - * Selects a color for a debug namespace - * @param {String} namespace The namespace string for the for the debug instance to be colored - * @return {Number|String} An ANSI color code for the given namespace - * @api private - */ - function selectColor(namespace) { - let hash = 0; - - for (let i = 0; i < namespace.length; i++) { - hash = ((hash << 5) - hash) + namespace.charCodeAt(i); - hash |= 0; // Convert to 32bit integer - } - - return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; - } - createDebug.selectColor = selectColor; - - /** - * Create a debugger with the given `namespace`. - * - * @param {String} namespace - * @return {Function} - * @api public - */ - function createDebug(namespace) { - let prevTime; - let enableOverride = null; - - function debug(...args) { - // Disabled? - if (!debug.enabled) { - return; - } - - const self = debug; - - // Set `diff` timestamp - const curr = Number(new Date()); - const ms = curr - (prevTime || curr); - self.diff = ms; - self.prev = prevTime; - self.curr = curr; - prevTime = curr; - - args[0] = createDebug.coerce(args[0]); - - if (typeof args[0] !== 'string') { - // Anything else let's inspect with %O - args.unshift('%O'); - } - - // Apply any `formatters` transformations - let index = 0; - args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { - // If we encounter an escaped % then don't increase the array index - if (match === '%%') { - return '%'; - } - index++; - const formatter = createDebug.formatters[format]; - if (typeof formatter === 'function') { - const val = args[index]; - match = formatter.call(self, val); - - // Now we need to remove `args[index]` since it's inlined in the `format` - args.splice(index, 1); - index--; - } - return match; - }); - - // Apply env-specific formatting (colors, etc.) - createDebug.formatArgs.call(self, args); - - const logFn = self.log || createDebug.log; - logFn.apply(self, args); - } - - debug.namespace = namespace; - debug.useColors = createDebug.useColors(); - debug.color = createDebug.selectColor(namespace); - debug.extend = extend; - debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. - - Object.defineProperty(debug, 'enabled', { - enumerable: true, - configurable: false, - get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, - set: v => { - enableOverride = v; - } - }); - - // Env-specific initialization logic for debug instances - if (typeof createDebug.init === 'function') { - createDebug.init(debug); - } - - return debug; - } - - function extend(namespace, delimiter) { - const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); - newDebug.log = this.log; - return newDebug; - } - - /** - * Enables a debug mode by namespaces. This can include modes - * separated by a colon and wildcards. - * - * @param {String} namespaces - * @api public - */ - function enable(namespaces) { - createDebug.save(namespaces); - - createDebug.names = []; - createDebug.skips = []; - - let i; - const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); - const len = split.length; - - for (i = 0; i < len; i++) { - if (!split[i]) { - // ignore empty strings - continue; - } - - namespaces = split[i].replace(/\*/g, '.*?'); - - if (namespaces[0] === '-') { - createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); - } else { - createDebug.names.push(new RegExp('^' + namespaces + '$')); - } - } - } - - /** - * Disable debug output. - * - * @return {String} namespaces - * @api public - */ - function disable() { - const namespaces = [ - ...createDebug.names.map(toNamespace), - ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace) - ].join(','); - createDebug.enable(''); - return namespaces; - } - - /** - * Returns true if the given mode name is enabled, false otherwise. - * - * @param {String} name - * @return {Boolean} - * @api public - */ - function enabled(name) { - if (name[name.length - 1] === '*') { - return true; - } - - let i; - let len; - - for (i = 0, len = createDebug.skips.length; i < len; i++) { - if (createDebug.skips[i].test(name)) { - return false; - } - } - - for (i = 0, len = createDebug.names.length; i < len; i++) { - if (createDebug.names[i].test(name)) { - return true; - } - } - - return false; - } - - /** - * Convert regexp to namespace - * - * @param {RegExp} regxep - * @return {String} namespace - * @api private - */ - function toNamespace(regexp) { - return regexp.toString() - .substring(2, regexp.toString().length - 2) - .replace(/\.\*\?$/, '*'); - } - - /** - * Coerce `val`. - * - * @param {Mixed} val - * @return {Mixed} - * @api private - */ - function coerce(val) { - if (val instanceof Error) { - return val.stack || val.message; - } - return val; - } - - /** - * XXX DO NOT USE. This is a temporary stub function. - * XXX It WILL be removed in the next major release. - */ - function destroy() { - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); - } - - createDebug.enable(createDebug.load()); - - return createDebug; -} - -module.exports = setup; - -},{"ms":32}],32:[function(require,module,exports){ -/** - * Helpers. - */ - -var s = 1000; -var m = s * 60; -var h = m * 60; -var d = h * 24; -var w = d * 7; -var y = d * 365.25; - -/** - * Parse or format the given `val`. - * - * Options: - * - * - `long` verbose formatting [false] - * - * @param {String|Number} val - * @param {Object} [options] - * @throws {Error} throw an error if val is not a non-empty string or a number - * @return {String|Number} - * @api public - */ - -module.exports = function(val, options) { - options = options || {}; - var type = typeof val; - if (type === 'string' && val.length > 0) { - return parse(val); - } else if (type === 'number' && isFinite(val)) { - return options.long ? fmtLong(val) : fmtShort(val); - } - throw new Error( - 'val is not a non-empty string or a valid number. val=' + - JSON.stringify(val) - ); -}; - -/** - * Parse the given `str` and return milliseconds. - * - * @param {String} str - * @return {Number} - * @api private - */ - -function parse(str) { - str = String(str); - if (str.length > 100) { - return; - } - var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( - str - ); - if (!match) { - return; - } - var n = parseFloat(match[1]); - var type = (match[2] || 'ms').toLowerCase(); - switch (type) { - case 'years': - case 'year': - case 'yrs': - case 'yr': - case 'y': - return n * y; - case 'weeks': - case 'week': - case 'w': - return n * w; - case 'days': - case 'day': - case 'd': - return n * d; - case 'hours': - case 'hour': - case 'hrs': - case 'hr': - case 'h': - return n * h; - case 'minutes': - case 'minute': - case 'mins': - case 'min': - case 'm': - return n * m; - case 'seconds': - case 'second': - case 'secs': - case 'sec': - case 's': - return n * s; - case 'milliseconds': - case 'millisecond': - case 'msecs': - case 'msec': - case 'ms': - return n; - default: - return undefined; - } -} - -/** - * Short format for `ms`. - * - * @param {Number} ms - * @return {String} - * @api private - */ - -function fmtShort(ms) { - var msAbs = Math.abs(ms); - if (msAbs >= d) { - return Math.round(ms / d) + 'd'; - } - if (msAbs >= h) { - return Math.round(ms / h) + 'h'; - } - if (msAbs >= m) { - return Math.round(ms / m) + 'm'; - } - if (msAbs >= s) { - return Math.round(ms / s) + 's'; - } - return ms + 'ms'; -} - -/** - * Long format for `ms`. - * - * @param {Number} ms - * @return {String} - * @api private - */ - -function fmtLong(ms) { - var msAbs = Math.abs(ms); - if (msAbs >= d) { - return plural(ms, msAbs, d, 'day'); - } - if (msAbs >= h) { - return plural(ms, msAbs, h, 'hour'); - } - if (msAbs >= m) { - return plural(ms, msAbs, m, 'minute'); - } - if (msAbs >= s) { - return plural(ms, msAbs, s, 'second'); - } - return ms + ' ms'; -} - -/** - * Pluralization helper. - */ - -function plural(ms, msAbs, n, name) { - var isPlural = msAbs >= n * 1.5; - return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); -} - -},{}],33:[function(require,module,exports){ -// shim for using process in browser -var process = module.exports = {}; - -// cached from whatever global is present so that test runners that stub it -// don't break things. But we need to wrap it in a try catch in case it is -// wrapped in strict mode code which doesn't define any globals. It's inside a -// function because try/catches deoptimize in certain engines. - -var cachedSetTimeout; -var cachedClearTimeout; - -function defaultSetTimout() { - throw new Error('setTimeout has not been defined'); -} -function defaultClearTimeout () { - throw new Error('clearTimeout has not been defined'); -} -(function () { - try { - if (typeof setTimeout === 'function') { - cachedSetTimeout = setTimeout; - } else { - cachedSetTimeout = defaultSetTimout; - } - } catch (e) { - cachedSetTimeout = defaultSetTimout; - } - try { - if (typeof clearTimeout === 'function') { - cachedClearTimeout = clearTimeout; - } else { - cachedClearTimeout = defaultClearTimeout; - } - } catch (e) { - cachedClearTimeout = defaultClearTimeout; - } -} ()) -function runTimeout(fun) { - if (cachedSetTimeout === setTimeout) { - //normal enviroments in sane situations - return setTimeout(fun, 0); - } - // if setTimeout wasn't available but was latter defined - if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { - cachedSetTimeout = setTimeout; - return setTimeout(fun, 0); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedSetTimeout(fun, 0); - } catch(e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedSetTimeout.call(null, fun, 0); - } catch(e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error - return cachedSetTimeout.call(this, fun, 0); - } - } - - -} -function runClearTimeout(marker) { - if (cachedClearTimeout === clearTimeout) { - //normal enviroments in sane situations - return clearTimeout(marker); - } - // if clearTimeout wasn't available but was latter defined - if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { - cachedClearTimeout = clearTimeout; - return clearTimeout(marker); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedClearTimeout(marker); - } catch (e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedClearTimeout.call(null, marker); - } catch (e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. - // Some versions of I.E. have different rules for clearTimeout vs setTimeout - return cachedClearTimeout.call(this, marker); - } - } - - - -} -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; - -function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } -} - -function drainQueue() { - if (draining) { - return; - } - var timeout = runTimeout(cleanUpNextTick); - draining = true; - - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - runClearTimeout(timeout); -} - -process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - runTimeout(drainQueue); - } -}; - -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; -} -Item.prototype.run = function () { - this.fun.apply(null, this.array); -}; -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; -process.version = ''; // empty string to avoid regexp issues -process.versions = {}; - -function noop() {} - -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; -process.prependListener = noop; -process.prependOnceListener = noop; - -process.listeners = function (name) { return [] } - -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; - -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; - -},{}],34:[function(require,module,exports){ -var grammar = module.exports = { - v: [{ - name: 'version', - reg: /^(\d*)$/ - }], - o: [{ - // o=- 20518 0 IN IP4 203.0.113.1 - // NB: sessionId will be a String in most cases because it is huge - 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' - }], - // default parsing of these only (though some of these feel outdated) - s: [{ name: 'name' }], - i: [{ name: 'description' }], - u: [{ name: 'uri' }], - e: [{ name: 'email' }], - p: [{ name: 'phone' }], - z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly... - r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly - // k: [{}], // outdated thing ignored - t: [{ - // t=0 0 - name: 'timing', - reg: /^(\d*) (\d*)/, - names: ['start', 'stop'], - format: '%d %d' - }], - c: [{ - // c=IN IP4 10.47.197.26 - name: 'connection', - reg: /^IN IP(\d) (\S*)/, - names: ['version', 'ip'], - format: 'IN IP%d %s' - }], - b: [{ - // b=AS:4000 - push: 'bandwidth', - reg: /^(TIAS|AS|CT|RR|RS):(\d*)/, - names: ['type', 'limit'], - format: '%s:%s' - }], - m: [{ - // m=video 51744 RTP/AVP 126 97 98 34 31 - // NB: special - pushes to session - // TODO: rtp/fmtp should be filtered by the payloads found here? - reg: /^(\w*) (\d*) ([\w/]*)(?: (.*))?/, - names: ['type', 'port', 'protocol', 'payloads'], - format: '%s %d %s %s' - }], - a: [ - { - // a=rtpmap:110 opus/48000/2 - push: 'rtp', - reg: /^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/, - names: ['payload', 'codec', 'rate', 'encoding'], - format: function (o) { - return (o.encoding) - ? 'rtpmap:%d %s/%s/%s' - : o.rate - ? 'rtpmap:%d %s/%s' - : 'rtpmap:%d %s'; - } - }, - { - // a=fmtp:108 profile-level-id=24;object=23;bitrate=64000 - // a=fmtp:111 minptime=10; useinbandfec=1 - push: 'fmtp', - reg: /^fmtp:(\d*) ([\S| ]*)/, - names: ['payload', 'config'], - format: 'fmtp:%d %s' - }, - { - // a=control:streamid=0 - name: 'control', - reg: /^control:(.*)/, - format: 'control:%s' - }, - { - // a=rtcp:65179 IN IP4 193.84.77.194 - name: 'rtcp', - reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/, - names: ['port', 'netType', 'ipVer', 'address'], - format: function (o) { - return (o.address != null) - ? 'rtcp:%d %s IP%d %s' - : 'rtcp:%d'; - } - }, - { - // a=rtcp-fb:98 trr-int 100 - push: 'rtcpFbTrrInt', - reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, - names: ['payload', 'value'], - format: 'rtcp-fb:%s trr-int %d' - }, - { - // a=rtcp-fb:98 nack rpsi - push: 'rtcpFb', - reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/, - names: ['payload', 'type', 'subtype'], - format: function (o) { - return (o.subtype != null) - ? 'rtcp-fb:%s %s %s' - : 'rtcp-fb:%s %s'; - } - }, - { - // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset - // a=extmap:1/recvonly URI-gps-string - // a=extmap:3 urn:ietf:params:rtp-hdrext:encrypt urn:ietf:params:rtp-hdrext:smpte-tc 25@600/24 - push: 'ext', - reg: /^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/, - names: ['value', 'direction', 'encrypt-uri', 'uri', 'config'], - format: function (o) { - return ( - 'extmap:%d' + - (o.direction ? '/%s' : '%v') + - (o['encrypt-uri'] ? ' %s' : '%v') + - ' %s' + - (o.config ? ' %s' : '') - ); - } - }, - { - // a=extmap-allow-mixed - name: 'extmapAllowMixed', - reg: /^(extmap-allow-mixed)/ - }, - { - // a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32 - push: 'crypto', - reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/, - names: ['id', 'suite', 'config', 'sessionConfig'], - format: function (o) { - return (o.sessionConfig != null) - ? 'crypto:%d %s %s %s' - : 'crypto:%d %s %s'; - } - }, - { - // a=setup:actpass - name: 'setup', - reg: /^setup:(\w*)/, - format: 'setup:%s' - }, - { - // a=connection:new - name: 'connectionType', - reg: /^connection:(new|existing)/, - format: 'connection:%s' - }, - { - // a=mid:1 - name: 'mid', - reg: /^mid:([^\s]*)/, - format: 'mid:%s' - }, - { - // a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a - name: 'msid', - reg: /^msid:(.*)/, - format: 'msid:%s' - }, - { - // a=ptime:20 - name: 'ptime', - reg: /^ptime:(\d*(?:\.\d*)*)/, - format: 'ptime:%d' - }, - { - // a=maxptime:60 - name: 'maxptime', - reg: /^maxptime:(\d*(?:\.\d*)*)/, - format: 'maxptime:%d' - }, - { - // a=sendrecv - name: 'direction', - reg: /^(sendrecv|recvonly|sendonly|inactive)/ - }, - { - // a=ice-lite - name: 'icelite', - reg: /^(ice-lite)/ - }, - { - // a=ice-ufrag:F7gI - name: 'iceUfrag', - reg: /^ice-ufrag:(\S*)/, - format: 'ice-ufrag:%s' - }, - { - // a=ice-pwd:x9cml/YzichV2+XlhiMu8g - name: 'icePwd', - reg: /^ice-pwd:(\S*)/, - format: 'ice-pwd:%s' - }, - { - // a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33 - name: 'fingerprint', - reg: /^fingerprint:(\S*) (\S*)/, - names: ['type', 'hash'], - format: 'fingerprint:%s %s' - }, - { - // a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host - // a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10 - // a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0 network-id 3 network-cost 10 - // a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10 - // a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0 network-id 3 network-cost 10 - 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 (o) { - var str = 'candidate:%s %d %s %d %s %d typ %s'; - - str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v'; - - // NB: candidate has three optional chunks, so %void middles one if it's missing - str += (o.tcptype != null) ? ' tcptype %s' : '%v'; - - if (o.generation != null) { - str += ' generation %d'; - } - - str += (o['network-id'] != null) ? ' network-id %d' : '%v'; - str += (o['network-cost'] != null) ? ' network-cost %d' : '%v'; - return str; - } - }, - { - // a=end-of-candidates (keep after the candidates line for readability) - name: 'endOfCandidates', - reg: /^(end-of-candidates)/ - }, - { - // a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ... - name: 'remoteCandidates', - reg: /^remote-candidates:(.*)/, - format: 'remote-candidates:%s' - }, - { - // a=ice-options:google-ice - name: 'iceOptions', - reg: /^ice-options:(\S*)/, - format: 'ice-options:%s' - }, - { - // a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1 - push: 'ssrcs', - reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/, - names: ['id', 'attribute', 'value'], - format: function (o) { - var str = 'ssrc:%d'; - if (o.attribute != null) { - str += ' %s'; - if (o.value != null) { - str += ':%s'; - } - } - return str; - } - }, - { - // a=ssrc-group:FEC 1 2 - // a=ssrc-group:FEC-FR 3004364195 1080772241 - push: 'ssrcGroups', - // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E - reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/, - names: ['semantics', 'ssrcs'], - format: 'ssrc-group:%s %s' - }, - { - // a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV - name: 'msidSemantic', - reg: /^msid-semantic:\s?(\w*) (\S*)/, - names: ['semantic', 'token'], - format: 'msid-semantic: %s %s' // space after ':' is not accidental - }, - { - // a=group:BUNDLE audio video - push: 'groups', - reg: /^group:(\w*) (.*)/, - names: ['type', 'mids'], - format: 'group:%s %s' - }, - { - // a=rtcp-mux - name: 'rtcpMux', - reg: /^(rtcp-mux)/ - }, - { - // a=rtcp-rsize - name: 'rtcpRsize', - reg: /^(rtcp-rsize)/ - }, - { - // a=sctpmap:5000 webrtc-datachannel 1024 - name: 'sctpmap', - reg: /^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/, - names: ['sctpmapNumber', 'app', 'maxMessageSize'], - format: function (o) { - return (o.maxMessageSize != null) - ? 'sctpmap:%s %s %s' - : 'sctpmap:%s %s'; - } - }, - { - // a=x-google-flag:conference - name: 'xGoogleFlag', - reg: /^x-google-flag:([^\s]*)/, - format: 'x-google-flag:%s' - }, - { - // a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0 - push: 'rids', - reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/, - names: ['id', 'direction', 'params'], - format: function (o) { - return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s'; - } - }, - { - // a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250] - // a=imageattr:* send [x=800,y=640] recv * - // a=imageattr:100 recv [x=320,y=240] - push: 'imageattrs', - reg: new RegExp( - // a=imageattr:97 - '^imageattr:(\\d+|\\*)' + - // send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] - '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' + - // recv [x=330,y=250] - '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?' - ), - names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'], - format: function (o) { - return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : ''); - } - }, - { - // a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8 - // a=simulcast:recv 1;4,5 send 6;7 - name: 'simulcast', - reg: new RegExp( - // a=simulcast: - '^simulcast:' + - // send 1,2,3;~4,~5 - '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' + - // space + recv 6;~7,~8 - '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' + - // end - '$' - ), - names: ['dir1', 'list1', 'dir2', 'list2'], - format: function (o) { - return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : ''); - } - }, - { - // old simulcast draft 03 (implemented by Firefox) - // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03 - // a=simulcast: recv pt=97;98 send pt=97 - // a=simulcast: send rid=5;6;7 paused=6,7 - name: 'simulcast_03', - reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/, - names: ['value'], - format: 'simulcast: %s' - }, - { - // a=framerate:25 - // a=framerate:29.97 - name: 'framerate', - reg: /^framerate:(\d+(?:$|\.\d+))/, - format: 'framerate:%s' - }, - { - // RFC4570 - // a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5 - 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' - }, - { - // a=bundle-only - name: 'bundleOnly', - reg: /^(bundle-only)/ - }, - { - // a=label:1 - name: 'label', - reg: /^label:(.+)/, - format: 'label:%s' - }, - { - // RFC version 26 for SCTP over DTLS - // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5 - name: 'sctpPort', - reg: /^sctp-port:(\d+)$/, - format: 'sctp-port:%s' - }, - { - // RFC version 26 for SCTP over DTLS - // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6 - name: 'maxMessageSize', - reg: /^max-message-size:(\d+)$/, - format: 'max-message-size:%s' - }, - { - // RFC7273 - // a=ts-refclk:ptp=IEEE1588-2008:39-A7-94-FF-FE-07-CB-D0:37 - push:'tsRefClocks', - reg: /^ts-refclk:([^\s=]*)(?:=(\S*))?/, - names: ['clksrc', 'clksrcExt'], - format: function (o) { - return 'ts-refclk:%s' + (o.clksrcExt != null ? '=%s' : ''); - } - }, - { - // RFC7273 - // a=mediaclk:direct=963214424 - name:'mediaClk', - reg: /^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/, - names: ['id', 'mediaClockName', 'mediaClockValue', 'rateNumerator', 'rateDenominator'], - format: function (o) { - var str = 'mediaclk:'; - str += (o.id != null ? 'id=%s %s' : '%v%s'); - str += (o.mediaClockValue != null ? '=%s' : ''); - str += (o.rateNumerator != null ? ' rate=%s' : ''); - str += (o.rateDenominator != null ? '/%s' : ''); - return str; - } - }, - { - // a=keywds:keywords - name: 'keywords', - reg: /^keywds:(.+)$/, - format: 'keywds:%s' - }, - { - // a=content:main - name: 'content', - reg: /^content:(.+)/, - format: 'content:%s' - }, - // BFCP https://tools.ietf.org/html/rfc4583 - { - // a=floorctrl:c-s - name: 'bfcpFloorCtrl', - reg: /^floorctrl:(c-only|s-only|c-s)/, - format: 'floorctrl:%s' - }, - { - // a=confid:1 - name: 'bfcpConfId', - reg: /^confid:(\d+)/, - format: 'confid:%s' - }, - { - // a=userid:1 - name: 'bfcpUserId', - reg: /^userid:(\d+)/, - format: 'userid:%s' - }, - { - // a=floorid:1 - name: 'bfcpFloorId', - reg: /^floorid:(.+) (?:m-stream|mstrm):(.+)/, - names: ['id', 'mStream'], - format: 'floorid:%s mstrm:%s' - }, - { - // any a= that we don't understand is kept verbatim on media.invalid - push: 'invalid', - names: ['value'] - } - ] -}; - -// set sensible defaults to avoid polluting the grammar with boring details -Object.keys(grammar).forEach(function (key) { - var objs = grammar[key]; - objs.forEach(function (obj) { - if (!obj.reg) { - obj.reg = /(.*)/; - } - if (!obj.format) { - obj.format = '%s'; - } - }); -}); - -},{}],35:[function(require,module,exports){ -var parser = require('./parser'); -var writer = require('./writer'); - -exports.write = writer; -exports.parse = parser.parse; -exports.parseParams = parser.parseParams; -exports.parseFmtpConfig = parser.parseFmtpConfig; // Alias of parseParams(). -exports.parsePayloads = parser.parsePayloads; -exports.parseRemoteCandidates = parser.parseRemoteCandidates; -exports.parseImageAttributes = parser.parseImageAttributes; -exports.parseSimulcastStreamList = parser.parseSimulcastStreamList; - -},{"./parser":36,"./writer":37}],36:[function(require,module,exports){ -var toIntIfInt = function (v) { - return String(Number(v)) === v ? Number(v) : v; -}; - -var attachProperties = function (match, location, names, rawName) { - if (rawName && !names) { - location[rawName] = toIntIfInt(match[1]); - } - else { - for (var i = 0; i < names.length; i += 1) { - if (match[i+1] != null) { - location[names[i]] = toIntIfInt(match[i+1]); - } - } - } -}; - -var parseReg = function (obj, location, content) { - var needsBlank = obj.name && obj.names; - if (obj.push && !location[obj.push]) { - location[obj.push] = []; - } - else if (needsBlank && !location[obj.name]) { - location[obj.name] = {}; - } - var keyLocation = obj.push ? - {} : // blank object that will be pushed - needsBlank ? location[obj.name] : location; // otherwise, named location or root - - attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name); - - if (obj.push) { - location[obj.push].push(keyLocation); - } -}; - -var grammar = require('./grammar'); -var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/); - -exports.parse = function (sdp) { - var session = {} - , media = [] - , location = session; // points at where properties go under (one of the above) - - // parse lines we understand - sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) { - var type = l[0]; - var content = l.slice(2); - if (type === 'm') { - media.push({rtp: [], fmtp: []}); - location = media[media.length-1]; // point at latest media line - } - - for (var j = 0; j < (grammar[type] || []).length; j += 1) { - var obj = grammar[type][j]; - if (obj.reg.test(content)) { - return parseReg(obj, location, content); - } - } - }); - - session.media = media; // link it up - return session; -}; - -var paramReducer = function (acc, expr) { - var s = expr.split(/=(.+)/, 2); - if (s.length === 2) { - acc[s[0]] = toIntIfInt(s[1]); - } else if (s.length === 1 && expr.length > 1) { - acc[s[0]] = undefined; - } - return acc; -}; - -exports.parseParams = function (str) { - return str.split(/;\s?/).reduce(paramReducer, {}); -}; - -// For backward compatibility - alias will be removed in 3.0.0 -exports.parseFmtpConfig = exports.parseParams; - -exports.parsePayloads = function (str) { - return str.toString().split(' ').map(Number); -}; - -exports.parseRemoteCandidates = function (str) { - var candidates = []; - var parts = str.split(' ').map(toIntIfInt); - for (var i = 0; i < parts.length; i += 3) { - candidates.push({ - component: parts[i], - ip: parts[i + 1], - port: parts[i + 2] - }); - } - return candidates; -}; - -exports.parseImageAttributes = function (str) { - return str.split(' ').map(function (item) { - return item.substring(1, item.length-1).split(',').reduce(paramReducer, {}); - }); -}; - -exports.parseSimulcastStreamList = function (str) { - return str.split(';').map(function (stream) { - return stream.split(',').map(function (format) { - var scid, paused = false; - - if (format[0] !== '~') { - scid = toIntIfInt(format); - } else { - scid = toIntIfInt(format.substring(1, format.length)); - paused = true; - } - - return { - scid: scid, - paused: paused - }; - }); - }); -}; - -},{"./grammar":34}],37:[function(require,module,exports){ -var grammar = require('./grammar'); - -// customized util.format - discards excess arguments and can void middle ones -var formatRegExp = /%[sdv%]/g; -var format = function (formatStr) { - var i = 1; - var args = arguments; - var len = args.length; - return formatStr.replace(formatRegExp, function (x) { - if (i >= len) { - return x; // missing argument - } - var arg = args[i]; - i += 1; - switch (x) { - case '%%': - return '%'; - case '%s': - return String(arg); - case '%d': - return Number(arg); - case '%v': - return ''; - } - }); - // NB: we discard excess arguments - they are typically undefined from makeLine -}; - -var makeLine = function (type, obj, location) { - var str = obj.format instanceof Function ? - (obj.format(obj.push ? location : location[obj.name])) : - obj.format; - - var args = [type + '=' + str]; - if (obj.names) { - for (var i = 0; i < obj.names.length; i += 1) { - var n = obj.names[i]; - if (obj.name) { - args.push(location[obj.name][n]); - } - else { // for mLine and push attributes - args.push(location[obj.names[i]]); - } - } - } - else { - args.push(location[obj.name]); - } - return format.apply(null, args); -}; - -// RFC specified order -// TODO: extend this with all the rest -var defaultOuterOrder = [ - 'v', 'o', 's', 'i', - 'u', 'e', 'p', 'c', - 'b', 't', 'r', 'z', 'a' -]; -var defaultInnerOrder = ['i', 'c', 'b', 'a']; - - -module.exports = function (session, opts) { - opts = opts || {}; - // ensure certain properties exist - if (session.version == null) { - session.version = 0; // 'v=0' must be there (only defined version atm) - } - if (session.name == null) { - session.name = ' '; // 's= ' must be there if no meaningful name set - } - session.media.forEach(function (mLine) { - if (mLine.payloads == null) { - mLine.payloads = ''; - } - }); - - var outerOrder = opts.outerOrder || defaultOuterOrder; - var innerOrder = opts.innerOrder || defaultInnerOrder; - var sdp = []; - - // loop through outerOrder for matching properties on session - outerOrder.forEach(function (type) { - grammar[type].forEach(function (obj) { - if (obj.name in session && session[obj.name] != null) { - sdp.push(makeLine(type, obj, session)); - } - else if (obj.push in session && session[obj.push] != null) { - session[obj.push].forEach(function (el) { - sdp.push(makeLine(type, obj, el)); - }); - } - }); - }); - - // then for each media line, follow the innerOrder - session.media.forEach(function (mLine) { - sdp.push(makeLine('m', grammar.m[0], mLine)); - - innerOrder.forEach(function (type) { - grammar[type].forEach(function (obj) { - if (obj.name in mLine && mLine[obj.name] != null) { - sdp.push(makeLine(type, obj, mLine)); - } - else if (obj.push in mLine && mLine[obj.push] != null) { - mLine[obj.push].forEach(function (el) { - sdp.push(makeLine(type, obj, el)); - }); - } - }); - }); - }); - - return sdp.join('\r\n') + '\r\n'; -}; - -},{"./grammar":34}],38:[function(require,module,exports){ -module.exports={ - "name": "jssip", - "title": "JsSIP", - "description": "the Javascript SIP library", - "version": "3.7.5", - "homepage": "https://jssip.net", - "author": "José Luis Millán (https://github.com/jmillan)", - "contributors": [ - "Iñaki Baz Castillo (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.14.34", - "debug": "^4.3.1", - "events": "^3.3.0", - "sdp-transform": "^2.14.1" - }, - "devDependencies": { - "@babel/core": "^7.13.10", - "@babel/preset-env": "^7.13.10", - "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) -}); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 46ae09bba..6d3fe9ca2 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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=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=n.call(e)},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);n0)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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":38}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),a("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,a("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){a("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=u.cloneArray(n.extraHeaders),s=u.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=u.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),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=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)}}])&&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;n2&&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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:N,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:k,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:x,STAR:D,SLASH:P,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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:z,qdtext:J,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:Ne,headers:ke,header:Ue,hname:xe,hvalue:De,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:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=D()))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;tl&&(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 N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){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 x(){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 D(){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 B(){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 W(){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 V(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 z(){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=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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 J(){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=ke())?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=k())))),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=k())),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=k())?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=Ne())&&null===(e=C())&&(e=E()),e}function Ne(){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 ke(){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=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=De())?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 xe(){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 De(){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=Je())?(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=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){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 Ve(){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=ze();null!==t;)e.push(t),t=ze();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=ze();null!==t;)e.push(t),t=ze();return e}function ze(){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 Je(){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=Be();null!==t;)e.push(t),t=Be();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=k()),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=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),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=k())?(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=k())&&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=k())))),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=k())),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=Dt())){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=Nt())&&(e=kt()),e}function Nt(){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 kt(){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=k())&&(e=xt()),e}function xt(){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=k())?e=[e,t]:(e=null,i=r),e}function Dt(){var e;return null===(e=Ut())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(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=k())?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=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(u=Wt())?l=[l,u]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(u=Wt())?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=k()))if(null!==(t=A()))if(null!==(n=Bt())){for(r=[],u=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=j())&&null!==(o=Bt())?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 Bt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=Y()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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=z())&&(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=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?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=zt())?u=[u,c]:(u=null,i=f)}null!==l&&null!==(u=V())?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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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=z())&&(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=z())?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=k())),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=W())){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=V())?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=k())),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=k()))),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=k()))))))),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=k())?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=k())&&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=k()),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=k())))),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=B())&&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=N())&&(t=A());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=A());return e}function Nn(){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=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(f=xn())?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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Dn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=k())?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=k())?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),Bn=Gn2&&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})}}])&&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"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":25}],11:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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=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=n.call(e)},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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;b("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=p.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!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new A("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new A("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,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;b("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||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===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};b('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(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===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};b("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(b("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(b("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(b("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(f.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]:{};b("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(b('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new T(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(b("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};b("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};b("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(b("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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(b("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;b("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;b("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 b("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(b("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};b('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){b("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){b("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||(b("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(b("_isReadyToReOffer() | session not established yet"),!1):(b("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(b("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(b("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(b("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),b('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(b("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 b('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};b('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(b(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(b(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;b("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 b("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;b("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return b("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;b("_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!==I.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};b('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===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(b("receiveRefer()"),!e.refer_to)return b("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return b("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);b('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new a(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(b("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;b("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new a(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){b("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,b('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(b("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void b(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){b("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};b('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};b('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};b('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};b('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),R('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]:{};b("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.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};b('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),R('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)};b('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.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(f.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){b("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){b("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!==I.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){b("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){b("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!==I.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 h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(b("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){b("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){b("session connecting"),b('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){b("session progress"),b('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){b("session accepted"),this._start_time=new Date,b('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){b("session confirmed"),this._is_confirmed=!0,b('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){b("session ended"),this._end_time=new Date,this._close(),b('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){b("session failed"),b('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),b('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){b("session onhold"),this._setLocalMediaStatus(),b('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){b("session onunhold"),this._setLocalMediaStatus(),b('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;b("session onmute"),this._setLocalMediaStatus(),b('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;b("session onunmute"),this._setLocalMediaStatus(),b('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),a}()},{"./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;n1&&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")}}])&&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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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})}}])&&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=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&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;n1&&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})}}])&&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"')}var t,n,a;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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})}}])&&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;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,u)Object.prototype.hasOwnProperty.call(u,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=u[o]));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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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")),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;r1&&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=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)}}}]),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:"C",get:function(){return C}},{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()}}]),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:"C",get:function(){return C}},{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:}}}]),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:"C",get:function(){return C}},{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())}}}]),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){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=u.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),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;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./RequestSender":18,"./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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var u in this._parameters={},this._headers={},this._scheme=t||o.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 l)Object.prototype.hasOwnProperty.call(l,a)&&this.setHeader(a,l[a])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=u.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 u=i.value;e.push("".concat(s,"=").concat(u))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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=n.call(e)},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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&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=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=n.call(e)},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);n1)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(e0&&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;t1&&(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=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=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){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":31,_process:33}],31:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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=[];++f1)for(var n=1;n1&&(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=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.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.data={},n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n.is_terminated=!1,n.terminated_reason=void 0,n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){"pending"===this._state&&(f('set "active" state'),this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=_,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,f||(f=[]),r.headers=f.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){this._dialogTerminated("send un-subscribe");var e=["Event: ".concat(this.event_name),"Expires: 0"];this._send(null,e)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Constants.js b/lib/Constants.js index 5cb3a88a4..bb10550d3 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -149,7 +149,7 @@ module.exports = { 606 : 'Not Acceptable' }, - ALLOWED_METHODS : 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY', + ALLOWED_METHODS : 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE', ACCEPTED_BODY_TYPES : 'application/sdp, application/dtmf-relay', MAX_FORWARDS : 69, SESSION_EXPIRES : 90, diff --git a/lib/Notifier.js b/lib/Notifier.js new file mode 100644 index 000000000..5b6490dd5 --- /dev/null +++ b/lib/Notifier.js @@ -0,0 +1,224 @@ +const EventEmitter = require('events').EventEmitter; +const JsSIP_C = require('./Constants'); +const Utils = require('./Utils'); +const debug = require('debug')('JsSIP:Notifier'); +const debugerror = require('debug')('JsSIP:ERROR:Notifier'); + +debugerror.log = console.warn.bind(console); + +module.exports = class Notifier extends EventEmitter +{ + constructor(ua, { subscribe, content_type, headers, credential, pending }) + { + super(); + this._ua = ua; + this.expires_timestamp = null; + this.expires_timer = null; + this._state = pending ? 'pending' : 'active'; + this.is_final_notify_sent = false; + this.is_first_notify_response = true; + this.id = null; + this.event_name = subscribe.getHeader('event'); + this.content_type = content_type; + if (!content_type) + throw new TypeError('content_type is undefined'); + this.expires = parseInt(subscribe.getHeader('expires')); + this.credential = credential; + const user = subscribe.to.uri.user; + const domain = subscribe.to.uri.host; + + this.contact = ``; + this.rcseq = subscribe.cseq; + this.data = {}; // Custom session empty object for high level use. + this.headers = headers ? headers : []; + this.target = subscribe.from.uri.user; + subscribe.to_tag = Utils.newTag(); + this.params = { + from : subscribe.to, + from_tag : subscribe.to_tag, + to : subscribe.from, + to_tag : subscribe.from_tag, + call_id : subscribe.call_id, + cseq : Math.floor((Math.random() * 10000) + 1) + }; + this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + debug('add dialog id=', this.id); + this._ua.newDialog(this); + this._setExpiresTimestamp(); + this._setExpiresTimer(); + subscribe.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); + this.is_terminated = false; + this.terminated_reason = undefined; + } + + /** + * Callbacks + */ + onAuthenticated() + { + this.params.cseq++; + } + + onRequestTimeout() + { + this._dialogTerminated('notify response timeout'); + } + + onTransportError() + { + this._dialogTerminated('notify transport error'); + } + + onReceiveResponse(response) + { + if (response.status_code >= 200 && response.status_code < 300) + { + if (this.is_first_notify_response) + { + this.is_first_notify_response = false; + this.route_set = response.getHeaders('record-route').reverse(); + if (this.route_set.length > 0) + this.params.route_set = this.route_set; + } + } + else if (response.status_code >= 300) + { + this._dialogTerminated('receive notify non-OK response'); + } + } + + receiveRequest(request) + { + if (request.method !== JsSIP_C.SUBSCRIBE) + { + request.reply(405); // Method Not Allowed + + return; + } + let h = request.getHeader('expires'); + + if (h === undefined || h === null) + { + h = '900'; // Missed header Expires. RFC 6665 3.1.1. Set default expires value + debug(`Missed expires header. Set by default ${h}`); + } + this.expires = parseInt(h); + request.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); + + const body = request.body; + const content_type = request.getHeader('content-type'); + const is_unsubscribe = this.expires === 0; + + debug('emit "subscribe"'); + this.emit('subscribe', is_unsubscribe, request, body, content_type); + + if (is_unsubscribe) + { + this._dialogTerminated('receive un-subscribe'); + } + else + { + this._setExpiresTimestamp(); + this._setExpiresTimer(); + } + } + + /** + * User API + */ + setActiveState() + { + if (this._state === 'pending') + { + debug('set "active" state'); + this._state = 'active'; + } + } + + sendNotify(body = null) + { + let subs_state = this._state; + + if (this._state !== 'terminated') + { + subs_state += `;expires=${this._getExpiresTimestamp()}`; + } + else if (this.terminated_reason) + { + subs_state += `;reason=${this.terminated_reason}`; + } + + const headers = this.headers.slice(); + + headers.push(`Subscription-State: ${subs_state}`); + headers.push(`Event: ${this.event_name}`); + if (body) + { + headers.push(`Content-Type: ${this.content_type}`); + } + this.params.cseq++; + this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, + this, this.credential); + } + + sendFinalNotify(body = null, reason = null) + { + if (this.is_final_notify_sent) + return; + this.is_final_notify_sent = true; + this._dialogTerminated('send final notify'); + this.terminated_reason = reason; + this.sendNotify(body); + } + + get state() + { + return this._state; + } + + /** + * Private API. + */ + _dialogTerminated(reason) + { + if (this.is_terminated) + return; + this.is_terminated = true; + this._state = 'terminated'; + clearTimeout(this.expires_timer); + // If delay needed ? + setTimeout(() => + { + debug('remove dialog id=', this.id); + this._ua.destroyDialog(this); + }, 32000); + debug(`emit "terminated" ${reason}"`); + this.emit('terminated', reason); + } + + _setExpiresTimestamp() + { + this.expires_timestamp = new Date().getTime() + (this.expires * 1000); + } + + _getExpiresTimestamp() + { + const delta = Math.floor((this.expires_timestamp - new Date().getTime()) / 1000); + + return delta >= 0 ? delta : 0; + } + + _setExpiresTimer() + { + clearTimeout(this.expires_timer); + setTimeout(() => + { + if (this.is_final_notify_sent) + return; + this.terminated_reason = 'timeout'; + this.is_final_notify_sent = true; + this.sendNotify(); + this._dialogTerminated('subscription expired'); + }, this.expires * 1000); + } +}; \ No newline at end of file diff --git a/lib/RequestSender.js b/lib/RequestSender.js index 725ff7d0a..aee9e25bf 100644 --- a/lib/RequestSender.js +++ b/lib/RequestSender.js @@ -93,7 +93,8 @@ module.exports = class RequestSender * Authenticate once. _challenged_ flag used to avoid infinite authentications. */ if ((status_code === 401 || status_code === 407) && - (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) + (this._config2 !== null || this._ua.configuration.password !== null + || this._ua.configuration.ha1 !== null)) { // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. @@ -121,13 +122,14 @@ module.exports = class RequestSender { if (!this._auth) { - let cnf = this._config2 ? this._config2 : this._ua.configuration; - this._auth = new DigestAuthentication({ - username : cnf.authorization_user, - password : cnf.password, - realm : cnf.realm, - ha1 : cnf.ha1 - }); + const cnf = this._config2 ? this._config2 : this._ua.configuration; + + this._auth = new DigestAuthentication({ + username : cnf.authorization_user, + password : cnf.password, + realm : cnf.realm, + ha1 : cnf.ha1 + }); } // Verify that the challenge is really valid. @@ -140,15 +142,15 @@ module.exports = class RequestSender this._challenged = true; // Update ha1 and realm in the UA or in alternative config. - if( !this._config2 ) + if (!this._config2) { - this._ua.set('realm', this._auth.get('realm')); - this._ua.set('ha1', this._auth.get('ha1')); + this._ua.set('realm', this._auth.get('realm')); + this._ua.set('ha1', this._auth.get('ha1')); } else { - this._config2.realm = this._auth.get('realm'); - this._config2.ha1 = this._auth.get('ha1'); + this._config2.realm = this._auth.get('realm'); + this._config2.ha1 = this._auth.get('ha1'); } if (challenge.stale) { diff --git a/lib/Subscriber.js b/lib/Subscriber.js new file mode 100644 index 000000000..c8bb0779a --- /dev/null +++ b/lib/Subscriber.js @@ -0,0 +1,260 @@ +const EventEmitter = require('events').EventEmitter; +const JsSIP_C = require('./Constants'); +const Utils = require('./Utils'); +const debug = require('debug')('JsSIP:Subscriber'); +const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); + +debugerror.log = console.warn.bind(console); + +module.exports = class Subscriber extends EventEmitter +{ + constructor(ua, target, { event_name, accept, expires, content_type, + allow_events, params, headers, credential }) + { + super(); + this._ua = ua; + if (!target) + throw new TypeError('target is undefined'); + this.target = target; + if (!event_name) + throw new TypeError('event_name is undefined'); + this.event_name = event_name; + if (!accept) + throw new TypeError('accept is undefined'); + this.accept = accept; + if (!expires) + expires = 900; + this.expires = expires; + this.allow_events = allow_events; // optional + this.content_type = content_type; // used to subscribe with body + if (!params) + throw new TypeError('params is undefined'); + if (!params.from_uri) + throw new TypeError('params.from_uri is undefined'); + if (!params.to_uri) + throw new TypeError('params.to_uri is undefined'); + this.params = params; + params.from_tag = Utils.newTag(); + params.to_tag = null; + params.call_id = Utils.createRandomToken(20); + params.cseq = Math.floor((Math.random() * 10000) + 1); + this.contact = ``; + // this.contact = ``; + this.credential = credential; // optional + this._state = 'init'; // init, notify_wait, pending, active, terminated + this.id = null; // dialog id + this.expires_timer = null; // to update subscription + this.expires_timestamp = null; + if (!headers) + headers = []; + this.headers = headers.concat([ + `Event: ${this.event_name}`, + `Accept: ${this.accept}`, + `Expires: ${this.expires}`, + `Contact: ${this.contact}` + ]); + if (this.allowEvents) + this.headers.push(`Allow-Events: ${this.allowEvents}`); + this.is_terminated = false; + this.route_set = null; + this.data = {}; // Custom session empty object for high level use. + } + + /** + * Callbacks + */ + onAuthenticated() + { + this.params.cseq++; + } + + onRequestTimeout() + { + this._dialogTerminated('subscribe response timeout'); + } + + onTransportError() + { + this._dialogTerminated('subscribe transport error'); + } + + onReceiveResponse(response) + { + if (response.status_code >= 200 && response.status_code < 300) + { + if (this.params.to_tag === null) + { + this.params.to_tag = response.to_tag; + this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + debug('added dialog id=', this.id); + this._ua.newDialog(this); + this.route_set = response.getHeaders('record-route').reverse(); + if (this.route_set.length > 0) + this.params.route_set = this.route_set; + } + const expires = this._getExpires(response); + + if (expires === -1) + { + debugerror('response without Expires header'); + + return; + } + if (expires > 0) + { + this.expires_timestamp = new Date().getTime() + (expires * 1000); + this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + } + } + else if (response.status_code >= 300) + { + this._dialogTerminated('receive subscribe non-OK response'); + } + } + + receiveRequest(request) + { + if (request.method !== JsSIP_C.NOTIFY) + { + request.reply(405); // Method Not Allowed + + return; + } + const subs_state = request.parseHeader('subscription-state'); + + if (!subs_state) + { + debugerror('missed header Subscription-State'); + request.reply(400); // Bad request + + return; + } + request.reply(200); + + const new_state = subs_state.state.toLowerCase(); + const prev_state = this._state; + + if (prev_state !== 'terminated' && new_state !== 'terminated') + { + this._state = new_state; + if (subs_state.expires !== undefined) + { + const expires = subs_state.expires; + const expires_timestamp = new Date().getTime() + (expires * 1000); + const max_time_deviation = 2000; + + // expiration shorter and the difference is not too small + if (this.expires_timestamp - expires_timestamp > max_time_deviation) + { + debug('update sending re-SUBSCRIBE time'); + clearTimeout(this.expires_timer); + this.expires_timestamp = expires_timestamp; + this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + } + } + } + if (prev_state !== 'active' && new_state === 'active') + { + debug('emit "active"'); + this.emit('active'); + } + + const body = request.body; + const is_final = new_state === 'terminated'; + + // notify event fired for NOTIFY with body + if (body) + { + const content_type = request.getHeader('content-type'); + + debug('emit "notify"'); + this.emit('notify', is_final, request, body, content_type); + } + if (is_final) + this._dialogTerminated('receive final notify'); + } + + /** + * User API + */ + subscribe(body = null) + { + if (this._state === 'init') + this._state = 'notify_wait'; + const headers = this.headers.slice(); + + if (body) + { + if (!this.content_type) + throw new TypeError('content_type is undefined'); + headers.push(`Content-Type: ${this.content_type}`); + } + this._send(body, headers); + } + + unsubscribe() + { + this._dialogTerminated('send un-subscribe'); + const headers = [ + `Event: ${this.event_name}`, + 'Expires: 0' + ]; + + this._send(null, headers); + } + + get state() + { + return this._state; + } + + /** + * Private API. + */ + _dialogTerminated(reason) + { + if (this.is_terminated) // to prevent duplicate call + return; + this.is_terminated = true; + this._state = 'terminated'; + clearTimeout(this.expires_timer); + // remove dialog from dialogs table with some delay, to allow receive end NOTIFY + setTimeout(() => + { + debug('removed dialog id=', this.id); + this._ua.destroyDialog(this); + }, 32000); + debug(`emit "terminated" ${reason}"`); + this.emit('terminated', reason); + } + + _send(body, headers) + { + this.params.cseq++; + this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this.target, this.params, headers, + body, this, this.credential); + } + + _getExpires(r) + { + const e = r.getHeader('expires'); + + return e ? parseInt(e) : -1; + } + + _calculateTimeoutMs(expires) + { + return expires >= 140 ? (expires * 1000 / 2) + + Math.floor(((expires / 2) - 70) * 1000 * Math.random()) : (expires * 1000) - 5000; + } + + _scheduleSubscribe(timeout) + { + debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); + this.expires_timer = setTimeout(() => + { + this.expires_timer = undefined; + this._send(null, this.headers); + }, timeout); + } +}; \ No newline at end of file diff --git a/lib/UA.js b/lib/UA.js index e9e6e0391..5e0aafdcb 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -2,6 +2,8 @@ const EventEmitter = require('events').EventEmitter; const JsSIP_C = require('./Constants'); const Registrator = require('./Registrator'); const RTCSession = require('./RTCSession'); +const Subscriber = require('./Subscriber'); +const Notifier = require('./Notifier'); const Message = require('./Message'); const Transactions = require('./Transactions'); const Transport = require('./Transport'); @@ -258,16 +260,39 @@ module.exports = class UA extends EventEmitter return message; } - - /* arbitrary client transaction */ + /** + * Arbitrary client transaction + */ sendRequest(method, target, params, headers, body, handlers, credential) { debug('sendRequest()'); - const request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); + const request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), + this, params, headers, body); const requestSender = new RequestSender(this, request, handlers, credential); + requestSender.send(); } - + + /** + * Create subscriber + */ + subscriber(target, options) + { + debug('subscriber()'); + + return new Subscriber(this, target, options); + } + + /** + * Create notifier + */ + notifier(options) + { + debug('notifier()'); + + return new Notifier(this, options); + } + /** * Terminate ongoing sessions. */ @@ -612,6 +637,7 @@ module.exports = class UA extends EventEmitter if (this.listeners('newSubscribe').length === 0) { request.reply(405); + return; } } From 2a8e0b1d7dff3e9d05444d3ecb5d2865eaf1e1f1 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 21 May 2021 13:54:21 +0300 Subject: [PATCH 05/70] style changed --- dist/jssip.js | 28594 ++++++++++++++++++++++++++++++++++++++++++ dist/jssip.min.js | 2 +- lib/Notifier.d.ts | 0 lib/Notifier.js | 50 +- lib/Subscriber.d.ts | 0 lib/Subscriber.js | 106 +- 6 files changed, 28732 insertions(+), 20 deletions(-) create mode 100644 dist/jssip.js create mode 100644 lib/Notifier.d.ts create mode 100644 lib/Subscriber.d.ts diff --git a/dist/jssip.js b/dist/jssip.js new file mode 100644 index 000000000..a741e02ef --- /dev/null +++ b/dist/jssip.js @@ -0,0 +1,28594 @@ +/* + * JsSIP v3.7.5 + * the Javascript SIP library + * Copyright: 2012-2021 José Luis Millán (https://github.com/jmillan) + * Homepage: https://jssip.net + * License: MIT + */ + +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var Utils = require('./Utils'); + +var JsSIP_C = require('./Constants'); + +var Grammar = require('./Grammar'); + +var URI = require('./URI'); + +var Socket = require('./Socket'); + +var Exceptions = require('./Exceptions'); // Default settings. + + +exports.settings = { + // SIP authentication. + authorization_user: null, + password: null, + realm: null, + ha1: null, + authorization_jwt: null, + // SIP account. + display_name: null, + uri: null, + contact_uri: null, + // SIP instance id (GRUU). + instance_id: null, + // Preloaded SIP Route header field. + use_preloaded_route: false, + // Session parameters. + session_timers: true, + session_timers_refresh_method: JsSIP_C.UPDATE, + session_timers_force_refresher: false, + no_answer_timeout: 60, + // Registration parameters. + register: true, + register_expires: 600, + registrar_server: null, + // Connection options. + sockets: null, + connection_recovery_max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL, + connection_recovery_min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL, + + /* + * Host address. + * Value to be set in Via sent_by and host part of Contact FQDN. + */ + via_host: "".concat(Utils.createRandomToken(12), ".invalid") +}; // Configuration checks. + +var checks = { + mandatory: { + sockets: function sockets(_sockets2) { + /* Allow defining sockets parameter as: + * Socket: socket + * Array of Socket: [socket1, socket2] + * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}] + * Array of Objects and Socket: [{socket: socket1}, socket2] + */ + var _sockets = []; + + if (Socket.isSocket(_sockets2)) { + _sockets.push({ + socket: _sockets2 + }); + } else if (Array.isArray(_sockets2) && _sockets2.length) { + var _iterator = _createForOfIteratorHelper(_sockets2), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var socket = _step.value; + + if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) { + _sockets.push(socket); + } else if (Socket.isSocket(socket)) { + _sockets.push({ + socket: socket + }); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } else { + return; + } + + return _sockets; + }, + uri: function uri(_uri) { + if (!/^sip:/i.test(_uri)) { + _uri = "".concat(JsSIP_C.SIP, ":").concat(_uri); + } + + var parsed = URI.parse(_uri); + + if (!parsed) { + return; + } else if (!parsed.user) { + return; + } else { + return parsed; + } + } + }, + optional: { + authorization_user: function authorization_user(_authorization_user) { + if (Grammar.parse("\"".concat(_authorization_user, "\""), 'quoted_string') === -1) { + return; + } else { + return _authorization_user; + } + }, + authorization_jwt: function authorization_jwt(_authorization_jwt) { + if (typeof _authorization_jwt === 'string') { + return _authorization_jwt; + } + }, + user_agent: function user_agent(_user_agent) { + if (typeof _user_agent === 'string') { + return _user_agent; + } + }, + connection_recovery_max_interval: function connection_recovery_max_interval(_connection_recovery_max_interval) { + if (Utils.isDecimal(_connection_recovery_max_interval)) { + var value = Number(_connection_recovery_max_interval); + + if (value > 0) { + return value; + } + } + }, + connection_recovery_min_interval: function connection_recovery_min_interval(_connection_recovery_min_interval) { + if (Utils.isDecimal(_connection_recovery_min_interval)) { + var value = Number(_connection_recovery_min_interval); + + if (value > 0) { + return value; + } + } + }, + contact_uri: function contact_uri(_contact_uri) { + if (typeof _contact_uri === 'string') { + var uri = Grammar.parse(_contact_uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } + } + }, + display_name: function display_name(_display_name) { + return _display_name; + }, + instance_id: function instance_id(_instance_id) { + if (/^uuid:/i.test(_instance_id)) { + _instance_id = _instance_id.substr(5); + } + + if (Grammar.parse(_instance_id, 'uuid') === -1) { + return; + } else { + return _instance_id; + } + }, + no_answer_timeout: function no_answer_timeout(_no_answer_timeout) { + if (Utils.isDecimal(_no_answer_timeout)) { + var value = Number(_no_answer_timeout); + + if (value > 0) { + return value; + } + } + }, + session_timers: function session_timers(_session_timers) { + if (typeof _session_timers === 'boolean') { + return _session_timers; + } + }, + session_timers_refresh_method: function session_timers_refresh_method(method) { + if (typeof method === 'string') { + method = method.toUpperCase(); + + if (method === JsSIP_C.INVITE || method === JsSIP_C.UPDATE) { + return method; + } + } + }, + session_timers_force_refresher: function session_timers_force_refresher(_session_timers_force_refresher) { + if (typeof _session_timers_force_refresher === 'boolean') { + return _session_timers_force_refresher; + } + }, + password: function password(_password) { + return String(_password); + }, + realm: function realm(_realm) { + return String(_realm); + }, + ha1: function ha1(_ha) { + return String(_ha); + }, + register: function register(_register) { + if (typeof _register === 'boolean') { + return _register; + } + }, + register_expires: function register_expires(_register_expires) { + if (Utils.isDecimal(_register_expires)) { + var value = Number(_register_expires); + + if (value > 0) { + return value; + } + } + }, + registrar_server: function registrar_server(_registrar_server) { + if (!/^sip:/i.test(_registrar_server)) { + _registrar_server = "".concat(JsSIP_C.SIP, ":").concat(_registrar_server); + } + + var parsed = URI.parse(_registrar_server); + + if (!parsed) { + return; + } else if (parsed.user) { + return; + } else { + return parsed; + } + }, + use_preloaded_route: function use_preloaded_route(_use_preloaded_route) { + if (typeof _use_preloaded_route === 'boolean') { + return _use_preloaded_route; + } + } + } +}; + +exports.load = function (dst, src) { + // Check Mandatory parameters. + for (var parameter in checks.mandatory) { + if (!src.hasOwnProperty(parameter)) { + throw new Exceptions.ConfigurationError(parameter); + } else { + var value = src[parameter]; + var checked_value = checks.mandatory[parameter](value); + + if (checked_value !== undefined) { + dst[parameter] = checked_value; + } else { + throw new Exceptions.ConfigurationError(parameter, value); + } + } + } // Check Optional parameters. + + + for (var _parameter in checks.optional) { + if (src.hasOwnProperty(_parameter)) { + var _value = src[_parameter]; + /* If the parameter value is null, empty string, undefined, empty array + * or it's a number with NaN value, then apply its default value. + */ + + if (Utils.isEmpty(_value)) { + continue; + } + + var _checked_value = checks.optional[_parameter](_value); + + if (_checked_value !== undefined) { + dst[_parameter] = _checked_value; + } else { + throw new Exceptions.ConfigurationError(_parameter, _value); + } + } + } +}; +},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],2:[function(require,module,exports){ +"use strict"; + +var pkg = require('../package.json'); + +module.exports = { + USER_AGENT: "".concat(pkg.title, " ").concat(pkg.version), + // SIP scheme. + SIP: 'sip', + SIPS: 'sips', + // End and Failure causes. + causes: { + // Generic error causes. + CONNECTION_ERROR: 'Connection Error', + REQUEST_TIMEOUT: 'Request Timeout', + SIP_FAILURE_CODE: 'SIP Failure Code', + INTERNAL_ERROR: 'Internal Error', + // SIP error causes. + BUSY: 'Busy', + REJECTED: 'Rejected', + REDIRECTED: 'Redirected', + UNAVAILABLE: 'Unavailable', + NOT_FOUND: 'Not Found', + ADDRESS_INCOMPLETE: 'Address Incomplete', + INCOMPATIBLE_SDP: 'Incompatible SDP', + MISSING_SDP: 'Missing SDP', + AUTHENTICATION_ERROR: 'Authentication Error', + // Session error causes. + BYE: 'Terminated', + WEBRTC_ERROR: 'WebRTC Error', + CANCELED: 'Canceled', + NO_ANSWER: 'No Answer', + EXPIRES: 'Expires', + NO_ACK: 'No ACK', + DIALOG_ERROR: 'Dialog Error', + USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access', + BAD_MEDIA_DESCRIPTION: 'Bad Media Description', + RTP_TIMEOUT: 'RTP Timeout' + }, + SIP_ERROR_CAUSES: { + REDIRECTED: [300, 301, 302, 305, 380], + BUSY: [486, 600], + REJECTED: [403, 603], + NOT_FOUND: [404, 604], + UNAVAILABLE: [480, 410, 408, 430], + ADDRESS_INCOMPLETE: [484, 424], + INCOMPATIBLE_SDP: [488, 606], + AUTHENTICATION_ERROR: [401, 407] + }, + // SIP Methods. + 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 methods. + DTMF_TRANSPORT: { + INFO: 'INFO', + RFC2833: 'RFC2833' + }, + + /* SIP Response Reasons + * DOC: https://www.iana.org/assignments/sip-parameters + * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7 + */ + REASON_PHRASE: { + 100: 'Trying', + 180: 'Ringing', + 181: 'Call Is Being Forwarded', + 182: 'Queued', + 183: 'Session Progress', + 199: 'Early Dialog Terminated', + // draft-ietf-sipcore-199 + 200: 'OK', + 202: 'Accepted', + // RFC 3265 + 204: 'No Notification', + // RFC 5839 + 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', + // RFC 3903 + 413: 'Request Entity Too Large', + 414: 'Request-URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Unsupported URI Scheme', + 417: 'Unknown Resource-Priority', + // RFC 4412 + 420: 'Bad Extension', + 421: 'Extension Required', + 422: 'Session Interval Too Small', + // RFC 4028 + 423: 'Interval Too Brief', + 424: 'Bad Location Information', + // RFC 6442 + 428: 'Use Identity Header', + // RFC 4474 + 429: 'Provide Referrer Identity', + // RFC 3892 + 430: 'Flow Failed', + // RFC 5626 + 433: 'Anonymity Disallowed', + // RFC 5079 + 436: 'Bad Identity-Info', + // RFC 4474 + 437: 'Unsupported Certificate', + // RFC 4744 + 438: 'Invalid Identity Header', + // RFC 4744 + 439: 'First Hop Lacks Outbound Support', + // RFC 5626 + 440: 'Max-Breadth Exceeded', + // RFC 5393 + 469: 'Bad Info Package', + // draft-ietf-sipcore-info-events + 470: 'Consent Needed', + // RFC 5360 + 478: 'Unresolvable Destination', + // Custom code copied from Kamailio. + 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', + // RFC 3265 + 491: 'Request Pending', + 493: 'Undecipherable', + 494: 'Security Agreement Required', + // RFC 3329 + 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', + // RFC 3312 + 600: 'Busy Everywhere', + 603: 'Decline', + 604: 'Does Not Exist Anywhere', + 606: 'Not Acceptable' + }, + ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE', + ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay', + MAX_FORWARDS: 69, + SESSION_EXPIRES: 90, + MIN_SESSION_EXPIRES: 60, + CONNECTION_RECOVERY_MAX_INTERVAL: 30, + CONNECTION_RECOVERY_MIN_INTERVAL: 2 +}; +},{"../package.json":40}],3:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var SIPMessage = require('./SIPMessage'); + +var JsSIP_C = require('./Constants'); + +var Transactions = require('./Transactions'); + +var Dialog_RequestSender = require('./Dialog/RequestSender'); + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:Dialog'); + +var C = { + // Dialog states. + STATUS_EARLY: 1, + STATUS_CONFIRMED: 2 +}; // RFC 3261 12.1. + +module.exports = /*#__PURE__*/function () { + function Dialog(owner, message, type) { + var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; + + _classCallCheck(this, Dialog); + + this._owner = owner; + this._ua = owner._ua; + this._uac_pending_reply = false; + this._uas_pending_reply = false; + + if (!message.hasHeader('contact')) { + return { + error: 'unable to create a Dialog without Contact header field' + }; + } + + if (message instanceof SIPMessage.IncomingResponse) { + state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED; + } + + var contact = message.parseHeader('contact'); // RFC 3261 12.1.1. + + if (type === 'UAS') { + this._id = { + call_id: message.call_id, + local_tag: message.to_tag, + remote_tag: message.from_tag, + toString: function toString() { + return this.call_id + this.local_tag + this.remote_tag; + } + }; + this._state = state; + this._remote_seqnum = message.cseq; + this._local_uri = message.parseHeader('to').uri; + this._remote_uri = message.parseHeader('from').uri; + this._remote_target = contact.uri; + this._route_set = message.getHeaders('record-route'); + this._ack_seqnum = this._remote_seqnum; + } // RFC 3261 12.1.2. + else if (type === 'UAC') { + this._id = { + call_id: message.call_id, + local_tag: message.from_tag, + remote_tag: message.to_tag, + toString: function toString() { + return this.call_id + this.local_tag + this.remote_tag; + } + }; + this._state = state; + this._local_seqnum = message.cseq; + this._local_uri = message.parseHeader('from').uri; + this._remote_uri = message.parseHeader('to').uri; + this._remote_target = contact.uri; + this._route_set = message.getHeaders('record-route').reverse(); + this._ack_seqnum = null; + } + + this._ua.newDialog(this); + + debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); + } + + _createClass(Dialog, [{ + key: "id", + get: function get() { + return this._id; + } + }, { + key: "local_seqnum", + get: function get() { + return this._local_seqnum; + }, + set: function set(num) { + this._local_seqnum = num; + } + }, { + key: "owner", + get: function get() { + return this._owner; + } + }, { + key: "uac_pending_reply", + get: function get() { + return this._uac_pending_reply; + }, + set: function set(pending) { + this._uac_pending_reply = pending; + } + }, { + key: "uas_pending_reply", + get: function get() { + return this._uas_pending_reply; + } + }, { + key: "update", + value: function update(message, type) { + this._state = C.STATUS_CONFIRMED; + debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); + + if (type === 'UAC') { + // RFC 3261 13.2.2.4. + this._route_set = message.getHeaders('record-route').reverse(); + } + } + }, { + key: "terminate", + value: function terminate() { + debug("dialog ".concat(this._id.toString(), " deleted")); + + this._ua.destroyDialog(this); + } + }, { + key: "sendRequest", + value: function sendRequest(method) { + var _this = this; + + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var body = options.body || null; + + var request = this._createRequest(method, extraHeaders, body); // Increase the local CSeq on authentication. + + + eventHandlers.onAuthenticated = function () { + _this._local_seqnum += 1; + }; + + var request_sender = new Dialog_RequestSender(this, request, eventHandlers); + request_sender.send(); // Return the instance of OutgoingRequest. + + return request; + } + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + // Check in-dialog request. + if (!this._checkInDialogRequest(request)) { + return; + } // ACK received. Cleanup this._ack_seqnum. + + + if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) { + this._ack_seqnum = null; + } // INVITE received. Set this._ack_seqnum. + else if (request.method === JsSIP_C.INVITE) { + this._ack_seqnum = request.cseq; + } + + this._owner.receiveRequest(request); + } // RFC 3261 12.2.1.1. + + }, { + key: "_createRequest", + value: function _createRequest(method, extraHeaders, body) { + extraHeaders = Utils.cloneArray(extraHeaders); + + if (!this._local_seqnum) { + this._local_seqnum = Math.floor(Math.random() * 10000); + } + + var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1; + var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, { + 'cseq': cseq, + '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 + }, extraHeaders, body); + return request; + } // RFC 3261 12.2.2. + + }, { + key: "_checkInDialogRequest", + value: function _checkInDialogRequest(request) { + var _this2 = this; + + if (!this._remote_seqnum) { + this._remote_seqnum = request.cseq; + } else if (request.cseq < this._remote_seqnum) { + if (request.method === JsSIP_C.ACK) { + // We are not expecting any ACK with lower seqnum than the current one. + // Or this is not the ACK we are waiting for. + if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) { + return false; + } + } else { + request.reply(500); + return false; + } + } else if (request.cseq > this._remote_seqnum) { + this._remote_seqnum = request.cseq; + } // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-. + + + if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) { + if (this._uac_pending_reply === true) { + request.reply(491); + } else if (this._uas_pending_reply === true) { + var retryAfter = (Math.random() * 10 | 0) + 1; + request.reply(500, null, ["Retry-After:".concat(retryAfter)]); + return false; + } else { + this._uas_pending_reply = true; + + var stateChanged = function stateChanged() { + if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED || request.server_transaction.state === Transactions.C.STATUS_COMPLETED || request.server_transaction.state === Transactions.C.STATUS_TERMINATED) { + request.server_transaction.removeListener('stateChanged', stateChanged); + _this2._uas_pending_reply = false; + } + }; + + request.server_transaction.on('stateChanged', stateChanged); + } // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted. + + + if (request.hasHeader('contact')) { + request.server_transaction.on('stateChanged', function () { + if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED) { + _this2._remote_target = request.parseHeader('contact').uri; + } + }); + } + } else if (request.method === JsSIP_C.NOTIFY) { + // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted. + if (request.hasHeader('contact')) { + request.server_transaction.on('stateChanged', function () { + if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) { + _this2._remote_target = request.parseHeader('contact').uri; + } + }); + } + } + + return true; + } + }], [{ + key: "C", + get: // Expose C object. + function get() { + return C; + } + }]); + + return Dialog; +}(); +},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,"debug":32}],4:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var JsSIP_C = require('../Constants'); + +var Transactions = require('../Transactions'); + +var RTCSession = require('../RTCSession'); + +var RequestSender = require('../RequestSender'); // Default event handlers. + + +var EventHandlers = { + onRequestTimeout: function onRequestTimeout() {}, + onTransportError: function onTransportError() {}, + onSuccessResponse: function onSuccessResponse() {}, + onErrorResponse: function onErrorResponse() {}, + onAuthenticated: function onAuthenticated() {}, + onDialogError: function onDialogError() {} +}; + +module.exports = /*#__PURE__*/function () { + function DialogRequestSender(dialog, request, eventHandlers) { + _classCallCheck(this, DialogRequestSender); + + this._dialog = dialog; + this._ua = dialog._ua; + this._request = request; + this._eventHandlers = eventHandlers; // RFC3261 14.1 Modifying an Existing Session. UAC Behavior. + + this._reattempt = false; + this._reattemptTimer = null; // Define the undefined handlers. + + for (var handler in EventHandlers) { + if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { + if (!this._eventHandlers[handler]) { + this._eventHandlers[handler] = EventHandlers[handler]; + } + } + } + } + + _createClass(DialogRequestSender, [{ + key: "request", + get: function get() { + return this._request; + } + }, { + key: "send", + value: function send() { + var _this = this; + + var request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout: function onRequestTimeout() { + _this._eventHandlers.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this._eventHandlers.onTransportError(); + }, + onAuthenticated: function onAuthenticated(request) { + _this._eventHandlers.onAuthenticated(request); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this._receiveResponse(response); + } + }); + request_sender.send(); // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-. + + if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) { + this._dialog.uac_pending_reply = true; + + var stateChanged = function stateChanged() { + if (request_sender.clientTransaction.state === Transactions.C.STATUS_ACCEPTED || request_sender.clientTransaction.state === Transactions.C.STATUS_COMPLETED || request_sender.clientTransaction.state === Transactions.C.STATUS_TERMINATED) { + request_sender.clientTransaction.removeListener('stateChanged', stateChanged); + _this._dialog.uac_pending_reply = false; + } + }; + + request_sender.clientTransaction.on('stateChanged', stateChanged); + } + } + }, { + key: "_receiveResponse", + value: function _receiveResponse(response) { + var _this2 = this; + + // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog. + if (response.status_code === 408 || response.status_code === 481) { + this._eventHandlers.onDialogError(response); + } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) { + if (this._reattempt) { + if (response.status_code >= 200 && response.status_code < 300) { + this._eventHandlers.onSuccessResponse(response); + } else if (response.status_code >= 300) { + this._eventHandlers.onErrorResponse(response); + } + } else { + this._request.cseq = this._dialog.local_seqnum += 1; + this._reattemptTimer = setTimeout(function () { + // TODO: look at dialog state instead. + if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) { + _this2._reattempt = true; + + _this2._request_sender.send(); + } + }, 1000); + } + } else if (response.status_code >= 200 && response.status_code < 300) { + this._eventHandlers.onSuccessResponse(response); + } else if (response.status_code >= 300) { + this._eventHandlers.onErrorResponse(response); + } + } + }]); + + return DialogRequestSender; +}(); +},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:DigestAuthentication'); + +var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); + +debugerror.log = console.warn.bind(console); + +module.exports = /*#__PURE__*/function () { + function DigestAuthentication(credentials) { + _classCallCheck(this, DigestAuthentication); + + this._credentials = credentials; + 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; + } + + _createClass(DigestAuthentication, [{ + key: "get", + value: function get(parameter) { + switch (parameter) { + case 'realm': + return this._realm; + + case 'ha1': + return this._ha1; + + default: + debugerror('get() | cannot get "%s" parameter', parameter); + return undefined; + } + } + /** + * Performs Digest authentication given a SIP request and the challenge + * received in a response to that request. + * Returns true if auth was successfully generated, false otherwise. + */ + + }, { + key: "authenticate", + value: function authenticate(_ref, challenge) + /* test interface */ + { + var method = _ref.method, + ruri = _ref.ruri, + body = _ref.body; + var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + this._algorithm = challenge.algorithm; + this._realm = challenge.realm; + this._nonce = challenge.nonce; + this._opaque = challenge.opaque; + this._stale = challenge.stale; + + if (this._algorithm) { + if (this._algorithm !== 'MD5') { + debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); + return false; + } + } else { + this._algorithm = 'MD5'; + } + + if (!this._nonce) { + debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); + return false; + } + + if (!this._realm) { + debugerror('authenticate() | challenge without Digest realm, authentication aborted'); + return false; + } // If no plain SIP password is provided. + + + if (!this._credentials.password) { + // If ha1 is not provided we cannot authenticate. + if (!this._credentials.ha1) { + debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); + return false; + } // If the realm does not match the stored realm we cannot authenticate. + + + if (this._credentials.realm !== this._realm) { + debugerror('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); + return false; + } + } // 'qop' can contain a list of values (Array). Let's choose just one. + + + if (challenge.qop) { + if (challenge.qop.indexOf('auth-int') > -1) { + this._qop = 'auth-int'; + } else if (challenge.qop.indexOf('auth') > -1) { + this._qop = 'auth'; + } else { + // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. + debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); + return false; + } + } else { + this._qop = null; + } // Fill other attributes. + + + this._method = method; + this._uri = ruri; + this._cnonce = cnonce || Utils.createRandomToken(12); + this._nc += 1; + var hex = Number(this._nc).toString(16); + this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex; // Nc-value = 8LHEX. Max value = 'FFFFFFFF'. + + if (this._nc === 4294967296) { + this._nc = 1; + this._ncHex = '00000001'; + } // Calculate the Digest "response" value. + // If we have plain SIP password then regenerate ha1. + + + if (this._credentials.password) { + // HA1 = MD5(A1) = MD5(username:realm:password). + this._ha1 = Utils.calculateMD5("".concat(this._credentials.username, ":").concat(this._realm, ":").concat(this._credentials.password)); + } // Otherwise reuse the stored ha1. + else { + this._ha1 = this._credentials.ha1; + } + + var a2; + var ha2; + + if (this._qop === 'auth') { + // HA2 = MD5(A2) = MD5(method:digestURI). + a2 = "".concat(this._method, ":").concat(this._uri); + ha2 = Utils.calculateMD5(a2); + debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + + this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2)); + } else if (this._qop === 'auth-int') { + // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)). + a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : '')); + ha2 = Utils.calculateMD5(a2); + debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + + this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2)); + } else if (this._qop === null) { + // HA2 = MD5(A2) = MD5(method:digestURI). + a2 = "".concat(this._method, ":").concat(this._uri); + ha2 = Utils.calculateMD5(a2); + debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). + + this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2)); + } + + debug('authenticate() | response generated'); + return true; + } + /** + * Return the Proxy-Authorization or WWW-Authorization header value. + */ + + }, { + key: "toString", + value: function toString() { + var auth_params = []; + + if (!this._response) { + throw new Error('response field does not exist, cannot generate Authorization header'); + } + + auth_params.push("algorithm=".concat(this._algorithm)); + auth_params.push("username=\"".concat(this._credentials.username, "\"")); + auth_params.push("realm=\"".concat(this._realm, "\"")); + auth_params.push("nonce=\"".concat(this._nonce, "\"")); + auth_params.push("uri=\"".concat(this._uri, "\"")); + auth_params.push("response=\"".concat(this._response, "\"")); + + if (this._opaque) { + auth_params.push("opaque=\"".concat(this._opaque, "\"")); + } + + if (this._qop) { + auth_params.push("qop=".concat(this._qop)); + auth_params.push("cnonce=\"".concat(this._cnonce, "\"")); + auth_params.push("nc=".concat(this._ncHex)); + } + + return "Digest ".concat(auth_params.join(', ')); + } + }]); + + return DigestAuthentication; +}(); +},{"./Utils":28,"debug":32}],6:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } + +function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var ConfigurationError = /*#__PURE__*/function (_Error) { + _inherits(ConfigurationError, _Error); + + var _super = _createSuper(ConfigurationError); + + function ConfigurationError(parameter, value) { + var _this; + + _classCallCheck(this, ConfigurationError); + + _this = _super.call(this); + _this.code = 1; + _this.name = 'CONFIGURATION_ERROR'; + _this.parameter = parameter; + _this.value = value; + _this.message = !_this.value ? "Missing parameter: ".concat(_this.parameter) : "Invalid value ".concat(JSON.stringify(_this.value), " for parameter \"").concat(_this.parameter, "\""); + return _this; + } + + return ConfigurationError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); + +var InvalidStateError = /*#__PURE__*/function (_Error2) { + _inherits(InvalidStateError, _Error2); + + var _super2 = _createSuper(InvalidStateError); + + function InvalidStateError(status) { + var _this2; + + _classCallCheck(this, InvalidStateError); + + _this2 = _super2.call(this); + _this2.code = 2; + _this2.name = 'INVALID_STATE_ERROR'; + _this2.status = status; + _this2.message = "Invalid status: ".concat(status); + return _this2; + } + + return InvalidStateError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); + +var NotSupportedError = /*#__PURE__*/function (_Error3) { + _inherits(NotSupportedError, _Error3); + + var _super3 = _createSuper(NotSupportedError); + + function NotSupportedError(message) { + var _this3; + + _classCallCheck(this, NotSupportedError); + + _this3 = _super3.call(this); + _this3.code = 3; + _this3.name = 'NOT_SUPPORTED_ERROR'; + _this3.message = message; + return _this3; + } + + return NotSupportedError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); + +var NotReadyError = /*#__PURE__*/function (_Error4) { + _inherits(NotReadyError, _Error4); + + var _super4 = _createSuper(NotReadyError); + + function NotReadyError(message) { + var _this4; + + _classCallCheck(this, NotReadyError); + + _this4 = _super4.call(this); + _this4.code = 4; + _this4.name = 'NOT_READY_ERROR'; + _this4.message = message; + return _this4; + } + + return NotReadyError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); + +module.exports = { + ConfigurationError: ConfigurationError, + InvalidStateError: InvalidStateError, + NotSupportedError: NotSupportedError, + NotReadyError: NotReadyError +}; +},{}],7:[function(require,module,exports){ +"use strict"; + +module.exports = function () { + /* + * Generated by PEG.js 0.7.0. + * + * http://pegjs.majda.cz/ + */ + function quote(s) { + /* + * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a + * string literal except for the closing quote character, backslash, + * carriage return, line separator, paragraph separator, and line feed. + * Any character may appear in the form of an escape sequence. + * + * For portability, we also escape escape all control and non-ASCII + * characters. Note that "\0" and "\v" escape sequences are not used + * because JSHint does not like the first and IE the second. + */ + return '"' + s.replace(/\\/g, '\\\\') // backslash + .replace(/"/g, '\\"') // closing quote character + .replace(/\x08/g, '\\b') // backspace + .replace(/\t/g, '\\t') // horizontal tab + .replace(/\n/g, '\\n') // line feed + .replace(/\f/g, '\\f') // form feed + .replace(/\r/g, '\\r') // carriage return + .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"'; + } + + var result = { + /* + * Parses the input with a generated parser. If the parsing is successfull, + * returns a value explicitly or implicitly specified by the grammar from + * which the parser was generated (see |PEG.buildParser|). If the parsing is + * unsuccessful, throws |PEG.parser.SyntaxError| describing the error. + */ + parse: function parse(input, startRule) { + var parseFunctions = { + "CRLF": parse_CRLF, + "DIGIT": parse_DIGIT, + "ALPHA": parse_ALPHA, + "HEXDIG": parse_HEXDIG, + "WSP": parse_WSP, + "OCTET": parse_OCTET, + "DQUOTE": parse_DQUOTE, + "SP": parse_SP, + "HTAB": parse_HTAB, + "alphanum": parse_alphanum, + "reserved": parse_reserved, + "unreserved": parse_unreserved, + "mark": parse_mark, + "escaped": parse_escaped, + "LWS": parse_LWS, + "SWS": parse_SWS, + "HCOLON": parse_HCOLON, + "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM, + "TEXT_UTF8char": parse_TEXT_UTF8char, + "UTF8_NONASCII": parse_UTF8_NONASCII, + "UTF8_CONT": parse_UTF8_CONT, + "LHEX": parse_LHEX, + "token": parse_token, + "token_nodot": parse_token_nodot, + "separators": parse_separators, + "word": parse_word, + "STAR": parse_STAR, + "SLASH": parse_SLASH, + "EQUAL": parse_EQUAL, + "LPAREN": parse_LPAREN, + "RPAREN": parse_RPAREN, + "RAQUOT": parse_RAQUOT, + "LAQUOT": parse_LAQUOT, + "COMMA": parse_COMMA, + "SEMI": parse_SEMI, + "COLON": parse_COLON, + "LDQUOT": parse_LDQUOT, + "RDQUOT": parse_RDQUOT, + "comment": parse_comment, + "ctext": parse_ctext, + "quoted_string": parse_quoted_string, + "quoted_string_clean": parse_quoted_string_clean, + "qdtext": parse_qdtext, + "quoted_pair": parse_quoted_pair, + "SIP_URI_noparams": parse_SIP_URI_noparams, + "SIP_URI": parse_SIP_URI, + "uri_scheme": parse_uri_scheme, + "uri_scheme_sips": parse_uri_scheme_sips, + "uri_scheme_sip": parse_uri_scheme_sip, + "userinfo": parse_userinfo, + "user": parse_user, + "user_unreserved": parse_user_unreserved, + "password": parse_password, + "hostport": parse_hostport, + "host": parse_host, + "hostname": parse_hostname, + "domainlabel": parse_domainlabel, + "toplabel": parse_toplabel, + "IPv6reference": parse_IPv6reference, + "IPv6address": parse_IPv6address, + "h16": parse_h16, + "ls32": parse_ls32, + "IPv4address": parse_IPv4address, + "dec_octet": parse_dec_octet, + "port": parse_port, + "uri_parameters": parse_uri_parameters, + "uri_parameter": parse_uri_parameter, + "transport_param": parse_transport_param, + "user_param": parse_user_param, + "method_param": parse_method_param, + "ttl_param": parse_ttl_param, + "maddr_param": parse_maddr_param, + "lr_param": parse_lr_param, + "other_param": parse_other_param, + "pname": parse_pname, + "pvalue": parse_pvalue, + "paramchar": parse_paramchar, + "param_unreserved": parse_param_unreserved, + "headers": parse_headers, + "header": parse_header, + "hname": parse_hname, + "hvalue": parse_hvalue, + "hnv_unreserved": parse_hnv_unreserved, + "Request_Response": parse_Request_Response, + "Request_Line": parse_Request_Line, + "Request_URI": parse_Request_URI, + "absoluteURI": parse_absoluteURI, + "hier_part": parse_hier_part, + "net_path": parse_net_path, + "abs_path": parse_abs_path, + "opaque_part": parse_opaque_part, + "uric": parse_uric, + "uric_no_slash": parse_uric_no_slash, + "path_segments": parse_path_segments, + "segment": parse_segment, + "param": parse_param, + "pchar": parse_pchar, + "scheme": parse_scheme, + "authority": parse_authority, + "srvr": parse_srvr, + "reg_name": parse_reg_name, + "query": parse_query, + "SIP_Version": parse_SIP_Version, + "INVITEm": parse_INVITEm, + "ACKm": parse_ACKm, + "OPTIONSm": parse_OPTIONSm, + "BYEm": parse_BYEm, + "CANCELm": parse_CANCELm, + "REGISTERm": parse_REGISTERm, + "SUBSCRIBEm": parse_SUBSCRIBEm, + "NOTIFYm": parse_NOTIFYm, + "REFERm": parse_REFERm, + "Method": parse_Method, + "Status_Line": parse_Status_Line, + "Status_Code": parse_Status_Code, + "extension_code": parse_extension_code, + "Reason_Phrase": parse_Reason_Phrase, + "Allow_Events": parse_Allow_Events, + "Call_ID": parse_Call_ID, + "Contact": parse_Contact, + "contact_param": parse_contact_param, + "name_addr": parse_name_addr, + "display_name": parse_display_name, + "contact_params": parse_contact_params, + "c_p_q": parse_c_p_q, + "c_p_expires": parse_c_p_expires, + "delta_seconds": parse_delta_seconds, + "qvalue": parse_qvalue, + "generic_param": parse_generic_param, + "gen_value": parse_gen_value, + "Content_Disposition": parse_Content_Disposition, + "disp_type": parse_disp_type, + "disp_param": parse_disp_param, + "handling_param": parse_handling_param, + "Content_Encoding": parse_Content_Encoding, + "Content_Length": parse_Content_Length, + "Content_Type": parse_Content_Type, + "media_type": parse_media_type, + "m_type": parse_m_type, + "discrete_type": parse_discrete_type, + "composite_type": parse_composite_type, + "extension_token": parse_extension_token, + "x_token": parse_x_token, + "m_subtype": parse_m_subtype, + "m_parameter": parse_m_parameter, + "m_value": parse_m_value, + "CSeq": parse_CSeq, + "CSeq_value": parse_CSeq_value, + "Expires": parse_Expires, + "Event": parse_Event, + "event_type": parse_event_type, + "From": parse_From, + "from_param": parse_from_param, + "tag_param": parse_tag_param, + "Max_Forwards": parse_Max_Forwards, + "Min_Expires": parse_Min_Expires, + "Name_Addr_Header": parse_Name_Addr_Header, + "Proxy_Authenticate": parse_Proxy_Authenticate, + "challenge": parse_challenge, + "other_challenge": parse_other_challenge, + "auth_param": parse_auth_param, + "digest_cln": parse_digest_cln, + "realm": parse_realm, + "realm_value": parse_realm_value, + "domain": parse_domain, + "URI": parse_URI, + "nonce": parse_nonce, + "nonce_value": parse_nonce_value, + "opaque": parse_opaque, + "stale": parse_stale, + "algorithm": parse_algorithm, + "qop_options": parse_qop_options, + "qop_value": parse_qop_value, + "Proxy_Require": parse_Proxy_Require, + "Record_Route": parse_Record_Route, + "rec_route": parse_rec_route, + "Reason": parse_Reason, + "reason_param": parse_reason_param, + "reason_cause": parse_reason_cause, + "Require": parse_Require, + "Route": parse_Route, + "route_param": parse_route_param, + "Subscription_State": parse_Subscription_State, + "substate_value": parse_substate_value, + "subexp_params": parse_subexp_params, + "event_reason_value": parse_event_reason_value, + "Subject": parse_Subject, + "Supported": parse_Supported, + "To": parse_To, + "to_param": parse_to_param, + "Via": parse_Via, + "via_param": parse_via_param, + "via_params": parse_via_params, + "via_ttl": parse_via_ttl, + "via_maddr": parse_via_maddr, + "via_received": parse_via_received, + "via_branch": parse_via_branch, + "response_port": parse_response_port, + "rport": parse_rport, + "sent_protocol": parse_sent_protocol, + "protocol_name": parse_protocol_name, + "transport": parse_transport, + "sent_by": parse_sent_by, + "via_host": parse_via_host, + "via_port": parse_via_port, + "ttl": parse_ttl, + "WWW_Authenticate": parse_WWW_Authenticate, + "Session_Expires": parse_Session_Expires, + "s_e_expires": parse_s_e_expires, + "s_e_params": parse_s_e_params, + "s_e_refresher": parse_s_e_refresher, + "extension_header": parse_extension_header, + "header_value": parse_header_value, + "message_body": parse_message_body, + "uuid_URI": parse_uuid_URI, + "uuid": parse_uuid, + "hex4": parse_hex4, + "hex8": parse_hex8, + "hex12": parse_hex12, + "Refer_To": parse_Refer_To, + "Replaces": parse_Replaces, + "call_id": parse_call_id, + "replaces_param": parse_replaces_param, + "to_tag": parse_to_tag, + "from_tag": parse_from_tag, + "early_flag": parse_early_flag + }; + + if (startRule !== undefined) { + if (parseFunctions[startRule] === undefined) { + throw new Error("Invalid rule name: " + quote(startRule) + "."); + } + } else { + startRule = "CRLF"; + } + + var pos = 0; + var reportFailures = 0; + var rightmostFailuresPos = 0; + var rightmostFailuresExpected = []; + + function padLeft(input, padding, length) { + var result = input; + var padLength = length - input.length; + + for (var i = 0; i < padLength; i++) { + result = padding + result; + } + + return result; + } + + function escape(ch) { + var charCode = ch.charCodeAt(0); + var escapeChar; + var length; + + if (charCode <= 0xFF) { + escapeChar = 'x'; + length = 2; + } else { + escapeChar = 'u'; + length = 4; + } + + return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); + } + + function matchFailed(failure) { + if (pos < rightmostFailuresPos) { + return; + } + + if (pos > rightmostFailuresPos) { + rightmostFailuresPos = pos; + rightmostFailuresExpected = []; + } + + rightmostFailuresExpected.push(failure); + } + + function parse_CRLF() { + var result0; + + if (input.substr(pos, 2) === "\r\n") { + result0 = "\r\n"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"\\r\\n\""); + } + } + + return result0; + } + + function parse_DIGIT() { + var result0; + + if (/^[0-9]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[0-9]"); + } + } + + return result0; + } + + function parse_ALPHA() { + var result0; + + if (/^[a-zA-Z]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[a-zA-Z]"); + } + } + + return result0; + } + + function parse_HEXDIG() { + var result0; + + if (/^[0-9a-fA-F]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[0-9a-fA-F]"); + } + } + + return result0; + } + + function parse_WSP() { + var result0; + result0 = parse_SP(); + + if (result0 === null) { + result0 = parse_HTAB(); + } + + return result0; + } + + function parse_OCTET() { + var result0; + + if (/^[\0-\xFF]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\0-\\xFF]"); + } + } + + return result0; + } + + function parse_DQUOTE() { + var result0; + + if (/^["]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\"]"); + } + } + + return result0; + } + + function parse_SP() { + var result0; + + if (input.charCodeAt(pos) === 32) { + result0 = " "; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\" \""); + } + } + + return result0; + } + + function parse_HTAB() { + var result0; + + if (input.charCodeAt(pos) === 9) { + result0 = "\t"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"\\t\""); + } + } + + return result0; + } + + function parse_alphanum() { + var result0; + + if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[a-zA-Z0-9]"); + } + } + + return result0; + } + + function parse_reserved() { + var result0; + + if (input.charCodeAt(pos) === 59) { + result0 = ";"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 64) { + result0 = "@"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_unreserved() { + var result0; + result0 = parse_alphanum(); + + if (result0 === null) { + result0 = parse_mark(); + } + + return result0; + } + + function parse_mark() { + var result0; + + if (input.charCodeAt(pos) === 45) { + result0 = "-"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 95) { + result0 = "_"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 46) { + result0 = "."; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 33) { + result0 = "!"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 126) { + result0 = "~"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 42) { + result0 = "*"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 39) { + result0 = "'"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 40) { + result0 = "("; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 41) { + result0 = ")"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_escaped() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.charCodeAt(pos) === 37) { + result0 = "%"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result0 !== null) { + result1 = parse_HEXDIG(); + + if (result1 !== null) { + result2 = parse_HEXDIG(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, escaped) { + return escaped.join(''); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_LWS() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + pos2 = pos; + result0 = []; + result1 = parse_WSP(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_WSP(); + } + + if (result0 !== null) { + result1 = parse_CRLF(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos2; + } + } else { + result0 = null; + pos = pos2; + } + + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result2 = parse_WSP(); + + if (result2 !== null) { + result1 = []; + + while (result2 !== null) { + result1.push(result2); + result2 = parse_WSP(); + } + } else { + result1 = null; + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return " "; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_SWS() { + var result0; + result0 = parse_LWS(); + result0 = result0 !== null ? result0 : ""; + return result0; + } + + function parse_HCOLON() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = []; + result1 = parse_SP(); + + if (result1 === null) { + result1 = parse_HTAB(); + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_SP(); + + if (result1 === null) { + result1 = parse_HTAB(); + } + } + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ':'; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_TEXT_UTF8_TRIM() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result1 = parse_TEXT_UTF8char(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_TEXT_UTF8char(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = []; + result3 = parse_LWS(); + + while (result3 !== null) { + result2.push(result3); + result3 = parse_LWS(); + } + + if (result2 !== null) { + result3 = parse_TEXT_UTF8char(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = []; + result3 = parse_LWS(); + + while (result3 !== null) { + result2.push(result3); + result3 = parse_LWS(); + } + + if (result2 !== null) { + result3 = parse_TEXT_UTF8char(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_TEXT_UTF8char() { + var result0; + + if (/^[!-~]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[!-~]"); + } + } + + if (result0 === null) { + result0 = parse_UTF8_NONASCII(); + } + + return result0; + } + + function parse_UTF8_NONASCII() { + var result0; + + if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\x80-\\uFFFF]"); + } + } + + return result0; + } + + function parse_UTF8_CONT() { + var result0; + + if (/^[\x80-\xBF]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\x80-\\xBF]"); + } + } + + return result0; + } + + function parse_LHEX() { + var result0; + result0 = parse_DIGIT(); + + if (result0 === null) { + if (/^[a-f]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[a-f]"); + } + } + } + + return result0; + } + + function parse_token() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + } + } + } + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + } + } + } + } + } + } + } + } + } + } + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_token_nodot() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + } + } + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + } + } + } + } + } + } + } + } + } + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_separators() { + var result0; + + if (input.charCodeAt(pos) === 40) { + result0 = "("; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 41) { + result0 = ")"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 60) { + result0 = "<"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"<\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 62) { + result0 = ">"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\">\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 64) { + result0 = "@"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 59) { + result0 = ";"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 92) { + result0 = "\\"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"\\\\\""); + } + } + + if (result0 === null) { + result0 = parse_DQUOTE(); + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 91) { + result0 = "["; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 93) { + result0 = "]"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 123) { + result0 = "{"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"{\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 125) { + result0 = "}"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"}\""); + } + } + + if (result0 === null) { + result0 = parse_SP(); + + if (result0 === null) { + result0 = parse_HTAB(); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_word() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 40) { + result1 = "("; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 41) { + result1 = ")"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 60) { + result1 = "<"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"<\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 62) { + result1 = ">"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\">\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 92) { + result1 = "\\"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"\\\\\""); + } + } + + if (result1 === null) { + result1 = parse_DQUOTE(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 47) { + result1 = "/"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 91) { + result1 = "["; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 93) { + result1 = "]"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 63) { + result1 = "?"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 123) { + result1 = "{"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"{\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 125) { + result1 = "}"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"}\""); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 40) { + result1 = "("; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 41) { + result1 = ")"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 60) { + result1 = "<"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"<\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 62) { + result1 = ">"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\">\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 92) { + result1 = "\\"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"\\\\\""); + } + } + + if (result1 === null) { + result1 = parse_DQUOTE(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 47) { + result1 = "/"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 91) { + result1 = "["; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 93) { + result1 = "]"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 63) { + result1 = "?"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 123) { + result1 = "{"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"{\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 125) { + result1 = "}"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"}\""); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_STAR() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "*"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_SLASH() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 47) { + result1 = "/"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "/"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_EQUAL() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "="; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_LPAREN() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 40) { + result1 = "("; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "("; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_RPAREN() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 41) { + result1 = ")"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ")"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_RAQUOT() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.charCodeAt(pos) === 62) { + result0 = ">"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\">\""); + } + } + + if (result0 !== null) { + result1 = parse_SWS(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ">"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_LAQUOT() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 60) { + result1 = "<"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"<\""); + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "<"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_COMMA() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ","; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_SEMI() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ";"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_COLON() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ":"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_LDQUOT() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + result1 = parse_DQUOTE(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "\""; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_RDQUOT() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DQUOTE(); + + if (result0 !== null) { + result1 = parse_SWS(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "\""; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_comment() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_LPAREN(); + + if (result0 !== null) { + result1 = []; + result2 = parse_ctext(); + + if (result2 === null) { + result2 = parse_quoted_pair(); + + if (result2 === null) { + result2 = parse_comment(); + } + } + + while (result2 !== null) { + result1.push(result2); + result2 = parse_ctext(); + + if (result2 === null) { + result2 = parse_quoted_pair(); + + if (result2 === null) { + result2 = parse_comment(); + } + } + } + + if (result1 !== null) { + result2 = parse_RPAREN(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_ctext() { + var result0; + + if (/^[!-']/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[!-']"); + } + } + + if (result0 === null) { + if (/^[*-[]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[*-[]"); + } + } + + if (result0 === null) { + if (/^[\]-~]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\]-~]"); + } + } + + if (result0 === null) { + result0 = parse_UTF8_NONASCII(); + + if (result0 === null) { + result0 = parse_LWS(); + } + } + } + } + + return result0; + } + + function parse_quoted_string() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + result1 = parse_DQUOTE(); + + if (result1 !== null) { + result2 = []; + result3 = parse_qdtext(); + + if (result3 === null) { + result3 = parse_quoted_pair(); + } + + while (result3 !== null) { + result2.push(result3); + result3 = parse_qdtext(); + + if (result3 === null) { + result3 = parse_quoted_pair(); + } + } + + if (result2 !== null) { + result3 = parse_DQUOTE(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_quoted_string_clean() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + result1 = parse_DQUOTE(); + + if (result1 !== null) { + result2 = []; + result3 = parse_qdtext(); + + if (result3 === null) { + result3 = parse_quoted_pair(); + } + + while (result3 !== null) { + result2.push(result3); + result3 = parse_qdtext(); + + if (result3 === null) { + result3 = parse_quoted_pair(); + } + } + + if (result2 !== null) { + result3 = parse_DQUOTE(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var trimmed = input.substring(pos, offset).trim(); + return trimmed.substring(1, trimmed.length - 1) // remove outer quotes + .replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g, '$1'); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_qdtext() { + var result0; + result0 = parse_LWS(); + + if (result0 === null) { + if (input.charCodeAt(pos) === 33) { + result0 = "!"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result0 === null) { + if (/^[#-[]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[#-[]"); + } + } + + if (result0 === null) { + if (/^[\]-~]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\]-~]"); + } + } + + if (result0 === null) { + result0 = parse_UTF8_NONASCII(); + } + } + } + } + + return result0; + } + + function parse_quoted_pair() { + var result0, result1; + var pos0; + pos0 = pos; + + if (input.charCodeAt(pos) === 92) { + result0 = "\\"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"\\\\\""); + } + } + + if (result0 !== null) { + if (/^[\0-\t]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[\\0-\\t]"); + } + } + + if (result1 === null) { + if (/^[\x0B-\f]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[\\x0B-\\f]"); + } + } + + if (result1 === null) { + if (/^[\x0E-]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[\\x0E-]"); + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_SIP_URI_noparams() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_uri_scheme(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_userinfo(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_hostport(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + try { + data.uri = new URI(data.scheme, data.user, data.host, data.port); + delete data.scheme; + delete data.user; + delete data.host; + delete data.host_type; + delete data.port; + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_SIP_URI() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_uri_scheme(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_userinfo(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_hostport(); + + if (result3 !== null) { + result4 = parse_uri_parameters(); + + if (result4 !== null) { + result5 = parse_headers(); + result5 = result5 !== null ? result5 : ""; + + if (result5 !== null) { + result0 = [result0, result1, result2, result3, result4, result5]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var header; + + try { + data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers); + delete data.scheme; + delete data.user; + delete data.host; + delete data.host_type; + delete data.port; + delete data.uri_params; + + if (startRule === 'SIP_URI') { + data = data.uri; + } + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_uri_scheme() { + var result0; + result0 = parse_uri_scheme_sips(); + + if (result0 === null) { + result0 = parse_uri_scheme_sip(); + } + + return result0; + } + + function parse_uri_scheme_sips() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 4).toLowerCase() === "sips") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"sips\""); + } + } + + if (result0 !== null) { + result0 = function (offset, scheme) { + data.scheme = scheme.toLowerCase(); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_uri_scheme_sip() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 3).toLowerCase() === "sip") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"sip\""); + } + } + + if (result0 !== null) { + result0 = function (offset, scheme) { + data.scheme = scheme.toLowerCase(); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_userinfo() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_user(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_password(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + if (input.charCodeAt(pos) === 64) { + result2 = "@"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.user = decodeURIComponent(input.substring(pos - 1, offset)); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_user() { + var result0, result1; + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + result1 = parse_user_unreserved(); + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + result1 = parse_user_unreserved(); + } + } + } + } else { + result0 = null; + } + + return result0; + } + + function parse_user_unreserved() { + var result0; + + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 59) { + result0 = ";"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_password() { + var result0, result1; + var pos0; + pos0 = pos; + result0 = []; + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 38) { + result1 = "&"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 36) { + result1 = "$"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 38) { + result1 = "&"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 36) { + result1 = "$"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.password = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_hostport() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + result0 = parse_host(); + + if (result0 !== null) { + pos1 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_port(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos1; + } + } else { + result1 = null; + pos = pos1; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_host() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_hostname(); + + if (result0 === null) { + result0 = parse_IPv4address(); + + if (result0 === null) { + result0 = parse_IPv6reference(); + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.host = input.substring(pos, offset).toLowerCase(); + return data.host; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_hostname() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = []; + pos2 = pos; + result1 = parse_domainlabel(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + while (result1 !== null) { + result0.push(result1); + pos2 = pos; + result1 = parse_domainlabel(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + } + + if (result0 !== null) { + result1 = parse_toplabel(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.host_type = 'domain'; + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_domainlabel() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_alphanum(); + + if (result0 !== null) { + result1 = []; + result2 = parse_alphanum(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + } + } + + while (result2 !== null) { + result1.push(result2); + result2 = parse_alphanum(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_toplabel() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_ALPHA(); + + if (result0 !== null) { + result1 = []; + result2 = parse_alphanum(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + } + } + + while (result2 !== null) { + result1.push(result2); + result2 = parse_alphanum(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_IPv6reference() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.charCodeAt(pos) === 91) { + result0 = "["; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result0 !== null) { + result1 = parse_IPv6address(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 93) { + result2 = "]"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.host_type = 'IPv6'; + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_IPv6address() { + var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + if (input.charCodeAt(pos) === 58) { + result7 = ":"; + pos++; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result7 !== null) { + result8 = parse_h16(); + + if (result8 !== null) { + if (input.charCodeAt(pos) === 58) { + result9 = ":"; + pos++; + } else { + result9 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result9 !== null) { + result10 = parse_h16(); + + if (result10 !== null) { + if (input.charCodeAt(pos) === 58) { + result11 = ":"; + pos++; + } else { + result11 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result11 !== null) { + result12 = parse_ls32(); + + if (result12 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + if (input.charCodeAt(pos) === 58) { + result8 = ":"; + pos++; + } else { + result8 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result8 !== null) { + result9 = parse_h16(); + + if (result9 !== null) { + if (input.charCodeAt(pos) === 58) { + result10 = ":"; + pos++; + } else { + result10 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result10 !== null) { + result11 = parse_ls32(); + + if (result11 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + if (input.charCodeAt(pos) === 58) { + result8 = ":"; + pos++; + } else { + result8 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result8 !== null) { + result9 = parse_ls32(); + + if (result9 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_ls32(); + + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_ls32(); + + if (result5 !== null) { + result0 = [result0, result1, result2, result3, result4, result5]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_ls32(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_ls32(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + if (input.substr(pos, 2) === "::") { + result1 = "::"; + pos += 2; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + if (input.charCodeAt(pos) === 58) { + result7 = ":"; + pos++; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result7 !== null) { + result8 = parse_h16(); + + if (result8 !== null) { + if (input.charCodeAt(pos) === 58) { + result9 = ":"; + pos++; + } else { + result9 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result9 !== null) { + result10 = parse_ls32(); + + if (result10 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + if (input.substr(pos, 2) === "::") { + result2 = "::"; + pos += 2; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + if (input.charCodeAt(pos) === 58) { + result8 = ":"; + pos++; + } else { + result8 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result8 !== null) { + result9 = parse_ls32(); + + if (result9 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + if (input.substr(pos, 2) === "::") { + result3 = "::"; + pos += 2; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + if (input.charCodeAt(pos) === 58) { + result7 = ":"; + pos++; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result7 !== null) { + result8 = parse_ls32(); + + if (result8 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + if (input.substr(pos, 2) === "::") { + result4 = "::"; + pos += 2; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_ls32(); + + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos2; + } + } else { + result4 = null; + pos = pos2; + } + + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + if (input.substr(pos, 2) === "::") { + result5 = "::"; + pos += 2; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result5 !== null) { + result6 = parse_ls32(); + + if (result6 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos2; + } + } else { + result4 = null; + pos = pos2; + } + + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + + result5 = result5 !== null ? result5 : ""; + + if (result5 !== null) { + if (input.substr(pos, 2) === "::") { + result6 = "::"; + pos += 2; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos2; + } + } else { + result4 = null; + pos = pos2; + } + + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + + result5 = result5 !== null ? result5 : ""; + + if (result5 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + result6 = [result6, result7]; + } else { + result6 = null; + pos = pos2; + } + } else { + result6 = null; + pos = pos2; + } + + result6 = result6 !== null ? result6 : ""; + + if (result6 !== null) { + if (input.substr(pos, 2) === "::") { + result7 = "::"; + pos += 2; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.host_type = 'IPv6'; + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_h16() { + var result0, result1, result2, result3; + var pos0; + pos0 = pos; + result0 = parse_HEXDIG(); + + if (result0 !== null) { + result1 = parse_HEXDIG(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_HEXDIG(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_HEXDIG(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_ls32() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + result0 = parse_IPv4address(); + } + + return result0; + } + + function parse_IPv4address() { + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_dec_octet(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 !== null) { + result2 = parse_dec_octet(); + + if (result2 !== null) { + if (input.charCodeAt(pos) === 46) { + result3 = "."; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result3 !== null) { + result4 = parse_dec_octet(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 46) { + result5 = "."; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result5 !== null) { + result6 = parse_dec_octet(); + + if (result6 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.host_type = 'IPv4'; + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_dec_octet() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 2) === "25") { + result0 = "25"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"25\""); + } + } + + if (result0 !== null) { + if (/^[0-5]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[0-5]"); + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + + if (input.charCodeAt(pos) === 50) { + result0 = "2"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"2\""); + } + } + + if (result0 !== null) { + if (/^[0-4]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[0-4]"); + } + } + + if (result1 !== null) { + result2 = parse_DIGIT(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + + if (input.charCodeAt(pos) === 49) { + result0 = "1"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"1\""); + } + } + + if (result0 !== null) { + result1 = parse_DIGIT(); + + if (result1 !== null) { + result2 = parse_DIGIT(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + + if (/^[1-9]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[1-9]"); + } + } + + if (result0 !== null) { + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + result0 = parse_DIGIT(); + } + } + } + } + + return result0; + } + + function parse_port() { + var result0, result1, result2, result3, result4; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DIGIT(); + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_DIGIT(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_DIGIT(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result4 = parse_DIGIT(); + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, port) { + port = parseInt(port.join('')); + data.port = port; + return port; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_uri_parameters() { + var result0, result1, result2; + var pos0; + result0 = []; + pos0 = pos; + + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 !== null) { + result2 = parse_uri_parameter(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos0; + } + } else { + result1 = null; + pos = pos0; + } + + while (result1 !== null) { + result0.push(result1); + pos0 = pos; + + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 !== null) { + result2 = parse_uri_parameter(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos0; + } + } else { + result1 = null; + pos = pos0; + } + } + + return result0; + } + + function parse_uri_parameter() { + var result0; + result0 = parse_transport_param(); + + if (result0 === null) { + result0 = parse_user_param(); + + if (result0 === null) { + result0 = parse_method_param(); + + if (result0 === null) { + result0 = parse_ttl_param(); + + if (result0 === null) { + result0 = parse_maddr_param(); + + if (result0 === null) { + result0 = parse_lr_param(); + + if (result0 === null) { + result0 = parse_other_param(); + } + } + } + } + } + } + + return result0; + } + + function parse_transport_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 10).toLowerCase() === "transport=") { + result0 = input.substr(pos, 10); + pos += 10; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"transport=\""); + } + } + + if (result0 !== null) { + if (input.substr(pos, 3).toLowerCase() === "udp") { + result1 = input.substr(pos, 3); + pos += 3; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"udp\""); + } + } + + if (result1 === null) { + if (input.substr(pos, 3).toLowerCase() === "tcp") { + result1 = input.substr(pos, 3); + pos += 3; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"tcp\""); + } + } + + if (result1 === null) { + if (input.substr(pos, 4).toLowerCase() === "sctp") { + result1 = input.substr(pos, 4); + pos += 4; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"sctp\""); + } + } + + if (result1 === null) { + if (input.substr(pos, 3).toLowerCase() === "tls") { + result1 = input.substr(pos, 3); + pos += 3; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"tls\""); + } + } + + if (result1 === null) { + result1 = parse_token(); + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, transport) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['transport'] = transport.toLowerCase(); + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_user_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 5).toLowerCase() === "user=") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"user=\""); + } + } + + if (result0 !== null) { + if (input.substr(pos, 5).toLowerCase() === "phone") { + result1 = input.substr(pos, 5); + pos += 5; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"phone\""); + } + } + + if (result1 === null) { + if (input.substr(pos, 2).toLowerCase() === "ip") { + result1 = input.substr(pos, 2); + pos += 2; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"ip\""); + } + } + + if (result1 === null) { + result1 = parse_token(); + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, user) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['user'] = user.toLowerCase(); + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_method_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 7).toLowerCase() === "method=") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"method=\""); + } + } + + if (result0 !== null) { + result1 = parse_Method(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, method) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['method'] = method; + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_ttl_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 4).toLowerCase() === "ttl=") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"ttl=\""); + } + } + + if (result0 !== null) { + result1 = parse_ttl(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, ttl) { + if (!data.params) data.params = {}; + data.params['ttl'] = ttl; + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_maddr_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6).toLowerCase() === "maddr=") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"maddr=\""); + } + } + + if (result0 !== null) { + result1 = parse_host(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, maddr) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['maddr'] = maddr; + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_lr_param() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 2).toLowerCase() === "lr") { + result0 = input.substr(pos, 2); + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"lr\""); + } + } + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['lr'] = undefined; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_other_param() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_pname(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 !== null) { + result2 = parse_pvalue(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, param, value) { + if (!data.uri_params) data.uri_params = {}; + + if (typeof value === 'undefined') { + value = undefined; + } else { + value = value[1]; + } + + data.uri_params[param.toLowerCase()] = value; + }(pos0, result0[0], result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_pname() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_paramchar(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_paramchar(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, pname) { + return pname.join(''); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_pvalue() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_paramchar(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_paramchar(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, pvalue) { + return pvalue.join(''); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_paramchar() { + var result0; + result0 = parse_param_unreserved(); + + if (result0 === null) { + result0 = parse_unreserved(); + + if (result0 === null) { + result0 = parse_escaped(); + } + } + + return result0; + } + + function parse_param_unreserved() { + var result0; + + if (input.charCodeAt(pos) === 91) { + result0 = "["; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 93) { + result0 = "]"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_headers() { + var result0, result1, result2, result3, result4; + var pos0, pos1; + pos0 = pos; + + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 !== null) { + result1 = parse_header(); + + if (result1 !== null) { + result2 = []; + pos1 = pos; + + if (input.charCodeAt(pos) === 38) { + result3 = "&"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result3 !== null) { + result4 = parse_header(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos1; + } + } else { + result3 = null; + pos = pos1; + } + + while (result3 !== null) { + result2.push(result3); + pos1 = pos; + + if (input.charCodeAt(pos) === 38) { + result3 = "&"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result3 !== null) { + result4 = parse_header(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos1; + } + } else { + result3 = null; + pos = pos1; + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_header() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_hname(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 !== null) { + result2 = parse_hvalue(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, hname, hvalue) { + hname = hname.join('').toLowerCase(); + hvalue = hvalue.join(''); + if (!data.uri_headers) data.uri_headers = {}; + + if (!data.uri_headers[hname]) { + data.uri_headers[hname] = [hvalue]; + } else { + data.uri_headers[hname].push(hvalue); + } + }(pos0, result0[0], result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_hname() { + var result0, result1; + result1 = parse_hnv_unreserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_hnv_unreserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + } + } + } + } else { + result0 = null; + } + + return result0; + } + + function parse_hvalue() { + var result0, result1; + result0 = []; + result1 = parse_hnv_unreserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + } + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_hnv_unreserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + } + } + } + + return result0; + } + + function parse_hnv_unreserved() { + var result0; + + if (input.charCodeAt(pos) === 91) { + result0 = "["; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 93) { + result0 = "]"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_Request_Response() { + var result0; + result0 = parse_Status_Line(); + + if (result0 === null) { + result0 = parse_Request_Line(); + } + + return result0; + } + + function parse_Request_Line() { + var result0, result1, result2, result3, result4; + var pos0; + pos0 = pos; + result0 = parse_Method(); + + if (result0 !== null) { + result1 = parse_SP(); + + if (result1 !== null) { + result2 = parse_Request_URI(); + + if (result2 !== null) { + result3 = parse_SP(); + + if (result3 !== null) { + result4 = parse_SIP_Version(); + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Request_URI() { + var result0; + result0 = parse_SIP_URI(); + + if (result0 === null) { + result0 = parse_absoluteURI(); + } + + return result0; + } + + function parse_absoluteURI() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_scheme(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_hier_part(); + + if (result2 === null) { + result2 = parse_opaque_part(); + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_hier_part() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + result0 = parse_net_path(); + + if (result0 === null) { + result0 = parse_abs_path(); + } + + if (result0 !== null) { + pos1 = pos; + + if (input.charCodeAt(pos) === 63) { + result1 = "?"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result1 !== null) { + result2 = parse_query(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos1; + } + } else { + result1 = null; + pos = pos1; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_net_path() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 2) === "//") { + result0 = "//"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"//\""); + } + } + + if (result0 !== null) { + result1 = parse_authority(); + + if (result1 !== null) { + result2 = parse_abs_path(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_abs_path() { + var result0, result1; + var pos0; + pos0 = pos; + + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 !== null) { + result1 = parse_path_segments(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_opaque_part() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_uric_no_slash(); + + if (result0 !== null) { + result1 = []; + result2 = parse_uric(); + + while (result2 !== null) { + result1.push(result2); + result2 = parse_uric(); + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_uric() { + var result0; + result0 = parse_reserved(); + + if (result0 === null) { + result0 = parse_unreserved(); + + if (result0 === null) { + result0 = parse_escaped(); + } + } + + return result0; + } + + function parse_uric_no_slash() { + var result0; + result0 = parse_unreserved(); + + if (result0 === null) { + result0 = parse_escaped(); + + if (result0 === null) { + if (input.charCodeAt(pos) === 59) { + result0 = ";"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 64) { + result0 = "@"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_path_segments() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_segment(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + + if (input.charCodeAt(pos) === 47) { + result2 = "/"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result2 !== null) { + result3 = parse_segment(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + + if (input.charCodeAt(pos) === 47) { + result2 = "/"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result2 !== null) { + result3 = parse_segment(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_segment() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = []; + result1 = parse_pchar(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_pchar(); + } + + if (result0 !== null) { + result1 = []; + pos1 = pos; + + if (input.charCodeAt(pos) === 59) { + result2 = ";"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result2 !== null) { + result3 = parse_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + + if (input.charCodeAt(pos) === 59) { + result2 = ";"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result2 !== null) { + result3 = parse_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_param() { + var result0, result1; + result0 = []; + result1 = parse_pchar(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_pchar(); + } + + return result0; + } + + function parse_pchar() { + var result0; + result0 = parse_unreserved(); + + if (result0 === null) { + result0 = parse_escaped(); + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 64) { + result0 = "@"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_scheme() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_ALPHA(); + + if (result0 !== null) { + result1 = []; + result2 = parse_ALPHA(); + + if (result2 === null) { + result2 = parse_DIGIT(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 43) { + result2 = "+"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + } + } + } + } + + while (result2 !== null) { + result1.push(result2); + result2 = parse_ALPHA(); + + if (result2 === null) { + result2 = parse_DIGIT(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 43) { + result2 = "+"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.scheme = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_authority() { + var result0; + result0 = parse_srvr(); + + if (result0 === null) { + result0 = parse_reg_name(); + } + + return result0; + } + + function parse_srvr() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_userinfo(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_hostport(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + result0 = result0 !== null ? result0 : ""; + return result0; + } + + function parse_reg_name() { + var result0, result1; + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 36) { + result1 = "$"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 38) { + result1 = "&"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + } + } + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 36) { + result1 = "$"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 38) { + result1 = "&"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + } + } + } + } + } + } + } + } + } + } + } else { + result0 = null; + } + + return result0; + } + + function parse_query() { + var result0, result1; + result0 = []; + result1 = parse_uric(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_uric(); + } + + return result0; + } + + function parse_SIP_Version() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 3).toLowerCase() === "sip") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SIP\""); + } + } + + if (result0 !== null) { + if (input.charCodeAt(pos) === 47) { + result1 = "/"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result1 !== null) { + result3 = parse_DIGIT(); + + if (result3 !== null) { + result2 = []; + + while (result3 !== null) { + result2.push(result3); + result3 = parse_DIGIT(); + } + } else { + result2 = null; + } + + if (result2 !== null) { + if (input.charCodeAt(pos) === 46) { + result3 = "."; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result3 !== null) { + result5 = parse_DIGIT(); + + if (result5 !== null) { + result4 = []; + + while (result5 !== null) { + result4.push(result5); + result5 = parse_DIGIT(); + } + } else { + result4 = null; + } + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.sip_version = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_INVITEm() { + var result0; + + if (input.substr(pos, 6) === "INVITE") { + result0 = "INVITE"; + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"INVITE\""); + } + } + + return result0; + } + + function parse_ACKm() { + var result0; + + if (input.substr(pos, 3) === "ACK") { + result0 = "ACK"; + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"ACK\""); + } + } + + return result0; + } + + function parse_OPTIONSm() { + var result0; + + if (input.substr(pos, 7) === "OPTIONS") { + result0 = "OPTIONS"; + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"OPTIONS\""); + } + } + + return result0; + } + + function parse_BYEm() { + var result0; + + if (input.substr(pos, 3) === "BYE") { + result0 = "BYE"; + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"BYE\""); + } + } + + return result0; + } + + function parse_CANCELm() { + var result0; + + if (input.substr(pos, 6) === "CANCEL") { + result0 = "CANCEL"; + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"CANCEL\""); + } + } + + return result0; + } + + function parse_REGISTERm() { + var result0; + + if (input.substr(pos, 8) === "REGISTER") { + result0 = "REGISTER"; + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"REGISTER\""); + } + } + + return result0; + } + + function parse_SUBSCRIBEm() { + var result0; + + if (input.substr(pos, 9) === "SUBSCRIBE") { + result0 = "SUBSCRIBE"; + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SUBSCRIBE\""); + } + } + + return result0; + } + + function parse_NOTIFYm() { + var result0; + + if (input.substr(pos, 6) === "NOTIFY") { + result0 = "NOTIFY"; + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"NOTIFY\""); + } + } + + return result0; + } + + function parse_REFERm() { + var result0; + + if (input.substr(pos, 5) === "REFER") { + result0 = "REFER"; + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"REFER\""); + } + } + + return result0; + } + + function parse_Method() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_INVITEm(); + + if (result0 === null) { + result0 = parse_ACKm(); + + if (result0 === null) { + result0 = parse_OPTIONSm(); + + if (result0 === null) { + result0 = parse_BYEm(); + + if (result0 === null) { + result0 = parse_CANCELm(); + + if (result0 === null) { + result0 = parse_REGISTERm(); + + if (result0 === null) { + result0 = parse_SUBSCRIBEm(); + + if (result0 === null) { + result0 = parse_NOTIFYm(); + + if (result0 === null) { + result0 = parse_REFERm(); + + if (result0 === null) { + result0 = parse_token(); + } + } + } + } + } + } + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.method = input.substring(pos, offset); + return data.method; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Status_Line() { + var result0, result1, result2, result3, result4; + var pos0; + pos0 = pos; + result0 = parse_SIP_Version(); + + if (result0 !== null) { + result1 = parse_SP(); + + if (result1 !== null) { + result2 = parse_Status_Code(); + + if (result2 !== null) { + result3 = parse_SP(); + + if (result3 !== null) { + result4 = parse_Reason_Phrase(); + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Status_Code() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_extension_code(); + + if (result0 !== null) { + result0 = function (offset, status_code) { + data.status_code = parseInt(status_code.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_extension_code() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_DIGIT(); + + if (result0 !== null) { + result1 = parse_DIGIT(); + + if (result1 !== null) { + result2 = parse_DIGIT(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Reason_Phrase() { + var result0, result1; + var pos0; + pos0 = pos; + result0 = []; + result1 = parse_reserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + result1 = parse_UTF8_NONASCII(); + + if (result1 === null) { + result1 = parse_UTF8_CONT(); + + if (result1 === null) { + result1 = parse_SP(); + + if (result1 === null) { + result1 = parse_HTAB(); + } + } + } + } + } + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_reserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + result1 = parse_UTF8_NONASCII(); + + if (result1 === null) { + result1 = parse_UTF8_CONT(); + + if (result1 === null) { + result1 = parse_SP(); + + if (result1 === null) { + result1 = parse_HTAB(); + } + } + } + } + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.reason_phrase = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Allow_Events() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_event_type(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_event_type(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_event_type(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Call_ID() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_word(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 !== null) { + result2 = parse_word(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Contact() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + result0 = parse_STAR(); + + if (result0 === null) { + pos1 = pos; + result0 = parse_contact_param(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_contact_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_contact_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } + + if (result0 !== null) { + result0 = function (offset) { + var idx, length; + length = data.multi_header.length; + + for (idx = 0; idx < length; idx++) { + if (data.multi_header[idx].parsed === null) { + data = null; + break; + } + } + + if (data !== null) { + data = data.multi_header; + } else { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_contact_param() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_SIP_URI_noparams(); + + if (result0 === null) { + result0 = parse_name_addr(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_contact_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_contact_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var header; + if (!data.multi_header) data.multi_header = []; + + try { + header = new NameAddrHeader(data.uri, data.display_name, data.params); + delete data.uri; + delete data.display_name; + delete data.params; + } catch (e) { + header = null; + } + + data.multi_header.push({ + 'possition': pos, + 'offset': offset, + 'parsed': header + }); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_name_addr() { + var result0, result1, result2, result3; + var pos0; + pos0 = pos; + result0 = parse_display_name(); + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_LAQUOT(); + + if (result1 !== null) { + result2 = parse_SIP_URI(); + + if (result2 !== null) { + result3 = parse_RAQUOT(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_display_name() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_LWS(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_LWS(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + result0 = parse_quoted_string_clean(); + } + + if (result0 !== null) { + result0 = function (offset, display_name) { + if (typeof display_name === 'string') { + // quoted_string_clean + data.display_name = display_name; + } else { + // token ( LWS token )* + data.display_name = display_name[1].reduce(function (acc, cur) { + return acc + cur[0] + cur[1]; + }, display_name[0]); + } + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_contact_params() { + var result0; + result0 = parse_c_p_q(); + + if (result0 === null) { + result0 = parse_c_p_expires(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + } + + return result0; + } + + function parse_c_p_q() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 1).toLowerCase() === "q") { + result0 = input.substr(pos, 1); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"q\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_qvalue(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, q) { + if (!data.params) data.params = {}; + data.params['q'] = q; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_c_p_expires() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 7).toLowerCase() === "expires") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"expires\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_delta_seconds(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, expires) { + if (!data.params) data.params = {}; + data.params['expires'] = expires; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_delta_seconds() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_DIGIT(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, delta_seconds) { + return parseInt(delta_seconds.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_qvalue() { + var result0, result1, result2, result3, result4; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + + if (input.charCodeAt(pos) === 48) { + result0 = "0"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"0\""); + } + } + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_DIGIT(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result4 = parse_DIGIT(); + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + result1 = [result1, result2, result3, result4]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return parseFloat(input.substring(pos, offset)); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_generic_param() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_token(); + + if (result0 !== null) { + pos2 = pos; + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_gen_value(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, param, value) { + if (!data.params) data.params = {}; + + if (typeof value === 'undefined') { + value = undefined; + } else { + value = value[1]; + } + + data.params[param.toLowerCase()] = value; + }(pos0, result0[0], result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_gen_value() { + var result0; + result0 = parse_token(); + + if (result0 === null) { + result0 = parse_host(); + + if (result0 === null) { + result0 = parse_quoted_string(); + } + } + + return result0; + } + + function parse_Content_Disposition() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_disp_type(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_disp_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_disp_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_disp_type() { + var result0; + + if (input.substr(pos, 6).toLowerCase() === "render") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"render\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 7).toLowerCase() === "session") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"session\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 4).toLowerCase() === "icon") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"icon\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 5).toLowerCase() === "alert") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"alert\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + } + } + + return result0; + } + + function parse_disp_param() { + var result0; + result0 = parse_handling_param(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_handling_param() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 8).toLowerCase() === "handling") { + result0 = input.substr(pos, 8); + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"handling\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + if (input.substr(pos, 8).toLowerCase() === "optional") { + result2 = input.substr(pos, 8); + pos += 8; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"optional\""); + } + } + + if (result2 === null) { + if (input.substr(pos, 8).toLowerCase() === "required") { + result2 = input.substr(pos, 8); + pos += 8; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"required\""); + } + } + + if (result2 === null) { + result2 = parse_token(); + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Content_Encoding() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Content_Length() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_DIGIT(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, length) { + data = parseInt(length.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Content_Type() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_media_type(); + + if (result0 !== null) { + result0 = function (offset) { + data = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_media_type() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + result0 = parse_m_type(); + + if (result0 !== null) { + result1 = parse_SLASH(); + + if (result1 !== null) { + result2 = parse_m_subtype(); + + if (result2 !== null) { + result3 = []; + pos1 = pos; + result4 = parse_SEMI(); + + if (result4 !== null) { + result5 = parse_m_parameter(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + + while (result4 !== null) { + result3.push(result4); + pos1 = pos; + result4 = parse_SEMI(); + + if (result4 !== null) { + result5 = parse_m_parameter(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + } + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_m_type() { + var result0; + result0 = parse_discrete_type(); + + if (result0 === null) { + result0 = parse_composite_type(); + } + + return result0; + } + + function parse_discrete_type() { + var result0; + + if (input.substr(pos, 4).toLowerCase() === "text") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"text\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 5).toLowerCase() === "image") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"image\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 5).toLowerCase() === "audio") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"audio\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 5).toLowerCase() === "video") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"video\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 11).toLowerCase() === "application") { + result0 = input.substr(pos, 11); + pos += 11; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"application\""); + } + } + + if (result0 === null) { + result0 = parse_extension_token(); + } + } + } + } + } + + return result0; + } + + function parse_composite_type() { + var result0; + + if (input.substr(pos, 7).toLowerCase() === "message") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"message\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 9).toLowerCase() === "multipart") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"multipart\""); + } + } + + if (result0 === null) { + result0 = parse_extension_token(); + } + } + + return result0; + } + + function parse_extension_token() { + var result0; + result0 = parse_token(); + + if (result0 === null) { + result0 = parse_x_token(); + } + + return result0; + } + + function parse_x_token() { + var result0, result1; + var pos0; + pos0 = pos; + + if (input.substr(pos, 2).toLowerCase() === "x-") { + result0 = input.substr(pos, 2); + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"x-\""); + } + } + + if (result0 !== null) { + result1 = parse_token(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_m_subtype() { + var result0; + result0 = parse_extension_token(); + + if (result0 === null) { + result0 = parse_token(); + } + + return result0; + } + + function parse_m_parameter() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_m_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_m_value() { + var result0; + result0 = parse_token(); + + if (result0 === null) { + result0 = parse_quoted_string(); + } + + return result0; + } + + function parse_CSeq() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_CSeq_value(); + + if (result0 !== null) { + result1 = parse_LWS(); + + if (result1 !== null) { + result2 = parse_Method(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_CSeq_value() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_DIGIT(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, cseq_value) { + data.value = parseInt(cseq_value.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Expires() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_delta_seconds(); + + if (result0 !== null) { + result0 = function (offset, expires) { + data = expires; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Event() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_event_type(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, event_type) { + data.event = event_type.join('').toLowerCase(); + }(pos0, result0[0]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_event_type() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token_nodot(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result2 !== null) { + result3 = parse_token_nodot(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result2 !== null) { + result3 = parse_token_nodot(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_From() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_SIP_URI_noparams(); + + if (result0 === null) { + result0 = parse_name_addr(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_from_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_from_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var tag = data.tag; + + try { + data = new NameAddrHeader(data.uri, data.display_name, data.params); + + if (tag) { + data.setParam('tag', tag); + } + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_from_param() { + var result0; + result0 = parse_tag_param(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_tag_param() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 3).toLowerCase() === "tag") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"tag\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, tag) { + data.tag = tag; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Max_Forwards() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_DIGIT(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, forwards) { + data = parseInt(forwards.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Min_Expires() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_delta_seconds(); + + if (result0 !== null) { + result0 = function (offset, min_expires) { + data = min_expires; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Name_Addr_Header() { + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = []; + result1 = parse_display_name(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_display_name(); + } + + if (result0 !== null) { + result1 = parse_LAQUOT(); + + if (result1 !== null) { + result2 = parse_SIP_URI(); + + if (result2 !== null) { + result3 = parse_RAQUOT(); + + if (result3 !== null) { + result4 = []; + pos2 = pos; + result5 = parse_SEMI(); + + if (result5 !== null) { + result6 = parse_generic_param(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + + while (result5 !== null) { + result4.push(result5); + pos2 = pos; + result5 = parse_SEMI(); + + if (result5 !== null) { + result6 = parse_generic_param(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + } + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + try { + data = new NameAddrHeader(data.uri, data.display_name, data.params); + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Proxy_Authenticate() { + var result0; + result0 = parse_challenge(); + return result0; + } + + function parse_challenge() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + + if (input.substr(pos, 6).toLowerCase() === "digest") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"Digest\""); + } + } + + if (result0 !== null) { + result1 = parse_LWS(); + + if (result1 !== null) { + result2 = parse_digest_cln(); + + if (result2 !== null) { + result3 = []; + pos1 = pos; + result4 = parse_COMMA(); + + if (result4 !== null) { + result5 = parse_digest_cln(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + + while (result4 !== null) { + result3.push(result4); + pos1 = pos; + result4 = parse_COMMA(); + + if (result4 !== null) { + result5 = parse_digest_cln(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + } + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + result0 = parse_other_challenge(); + } + + return result0; + } + + function parse_other_challenge() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = parse_LWS(); + + if (result1 !== null) { + result2 = parse_auth_param(); + + if (result2 !== null) { + result3 = []; + pos1 = pos; + result4 = parse_COMMA(); + + if (result4 !== null) { + result5 = parse_auth_param(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + + while (result4 !== null) { + result3.push(result4); + pos1 = pos; + result4 = parse_COMMA(); + + if (result4 !== null) { + result5 = parse_auth_param(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + } + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_auth_param() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 === null) { + result2 = parse_quoted_string(); + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_digest_cln() { + var result0; + result0 = parse_realm(); + + if (result0 === null) { + result0 = parse_domain(); + + if (result0 === null) { + result0 = parse_nonce(); + + if (result0 === null) { + result0 = parse_opaque(); + + if (result0 === null) { + result0 = parse_stale(); + + if (result0 === null) { + result0 = parse_algorithm(); + + if (result0 === null) { + result0 = parse_qop_options(); + + if (result0 === null) { + result0 = parse_auth_param(); + } + } + } + } + } + } + } + + return result0; + } + + function parse_realm() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 5).toLowerCase() === "realm") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"realm\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_realm_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_realm_value() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_quoted_string_clean(); + + if (result0 !== null) { + result0 = function (offset, realm) { + data.realm = realm; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_domain() { + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1; + pos0 = pos; + + if (input.substr(pos, 6).toLowerCase() === "domain") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"domain\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_LDQUOT(); + + if (result2 !== null) { + result3 = parse_URI(); + + if (result3 !== null) { + result4 = []; + pos1 = pos; + result6 = parse_SP(); + + if (result6 !== null) { + result5 = []; + + while (result6 !== null) { + result5.push(result6); + result6 = parse_SP(); + } + } else { + result5 = null; + } + + if (result5 !== null) { + result6 = parse_URI(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos1; + } + } else { + result5 = null; + pos = pos1; + } + + while (result5 !== null) { + result4.push(result5); + pos1 = pos; + result6 = parse_SP(); + + if (result6 !== null) { + result5 = []; + + while (result6 !== null) { + result5.push(result6); + result6 = parse_SP(); + } + } else { + result5 = null; + } + + if (result5 !== null) { + result6 = parse_URI(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos1; + } + } else { + result5 = null; + pos = pos1; + } + } + + if (result4 !== null) { + result5 = parse_RDQUOT(); + + if (result5 !== null) { + result0 = [result0, result1, result2, result3, result4, result5]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_URI() { + var result0; + result0 = parse_absoluteURI(); + + if (result0 === null) { + result0 = parse_abs_path(); + } + + return result0; + } + + function parse_nonce() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 5).toLowerCase() === "nonce") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"nonce\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_nonce_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_nonce_value() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_quoted_string_clean(); + + if (result0 !== null) { + result0 = function (offset, nonce) { + data.nonce = nonce; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_opaque() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6).toLowerCase() === "opaque") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"opaque\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_quoted_string_clean(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, opaque) { + data.opaque = opaque; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_stale() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + + if (input.substr(pos, 5).toLowerCase() === "stale") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"stale\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + pos1 = pos; + + if (input.substr(pos, 4).toLowerCase() === "true") { + result2 = input.substr(pos, 4); + pos += 4; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"true\""); + } + } + + if (result2 !== null) { + result2 = function (offset) { + data.stale = true; + }(pos1); + } + + if (result2 === null) { + pos = pos1; + } + + if (result2 === null) { + pos1 = pos; + + if (input.substr(pos, 5).toLowerCase() === "false") { + result2 = input.substr(pos, 5); + pos += 5; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"false\""); + } + } + + if (result2 !== null) { + result2 = function (offset) { + data.stale = false; + }(pos1); + } + + if (result2 === null) { + pos = pos1; + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_algorithm() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 9).toLowerCase() === "algorithm") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"algorithm\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + if (input.substr(pos, 3).toLowerCase() === "md5") { + result2 = input.substr(pos, 3); + pos += 3; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"MD5\""); + } + } + + if (result2 === null) { + if (input.substr(pos, 8).toLowerCase() === "md5-sess") { + result2 = input.substr(pos, 8); + pos += 8; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"MD5-sess\""); + } + } + + if (result2 === null) { + result2 = parse_token(); + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, algorithm) { + data.algorithm = algorithm.toUpperCase(); + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_qop_options() { + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1, pos2; + pos0 = pos; + + if (input.substr(pos, 3).toLowerCase() === "qop") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"qop\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_LDQUOT(); + + if (result2 !== null) { + pos1 = pos; + result3 = parse_qop_value(); + + if (result3 !== null) { + result4 = []; + pos2 = pos; + + if (input.charCodeAt(pos) === 44) { + result5 = ","; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result5 !== null) { + result6 = parse_qop_value(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + + while (result5 !== null) { + result4.push(result5); + pos2 = pos; + + if (input.charCodeAt(pos) === 44) { + result5 = ","; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result5 !== null) { + result6 = parse_qop_value(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + } + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos1; + } + } else { + result3 = null; + pos = pos1; + } + + if (result3 !== null) { + result4 = parse_RDQUOT(); + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_qop_value() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 8).toLowerCase() === "auth-int") { + result0 = input.substr(pos, 8); + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"auth-int\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 4).toLowerCase() === "auth") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"auth\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + + if (result0 !== null) { + result0 = function (offset, qop_value) { + data.qop || (data.qop = []); + data.qop.push(qop_value.toLowerCase()); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Proxy_Require() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Record_Route() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_rec_route(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_rec_route(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_rec_route(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var idx, length; + length = data.multi_header.length; + + for (idx = 0; idx < length; idx++) { + if (data.multi_header[idx].parsed === null) { + data = null; + break; + } + } + + if (data !== null) { + data = data.multi_header; + } else { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_rec_route() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_name_addr(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var header; + if (!data.multi_header) data.multi_header = []; + + try { + header = new NameAddrHeader(data.uri, data.display_name, data.params); + delete data.uri; + delete data.display_name; + delete data.params; + } catch (e) { + header = null; + } + + data.multi_header.push({ + 'possition': pos, + 'offset': offset, + 'parsed': header + }); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Reason() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 3).toLowerCase() === "sip") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SIP\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_reason_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_reason_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, protocol) { + data.protocol = protocol.toLowerCase(); + if (!data.params) data.params = {}; + + if (data.params.text && data.params.text[0] === '"') { + var text = data.params.text; + data.text = text.substring(1, text.length - 1); + delete data.params.text; + } + }(pos0, result0[0]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_reason_param() { + var result0; + result0 = parse_reason_cause(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_reason_cause() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 5).toLowerCase() === "cause") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"cause\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result3 = parse_DIGIT(); + + if (result3 !== null) { + result2 = []; + + while (result3 !== null) { + result2.push(result3); + result3 = parse_DIGIT(); + } + } else { + result2 = null; + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, cause) { + data.cause = parseInt(cause.join('')); + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Require() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Route() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_route_param(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_route_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_route_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_route_param() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_name_addr(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Subscription_State() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_substate_value(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_subexp_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_subexp_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_substate_value() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 6).toLowerCase() === "active") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"active\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 7).toLowerCase() === "pending") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"pending\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 10).toLowerCase() === "terminated") { + result0 = input.substr(pos, 10); + pos += 10; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"terminated\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.state = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_subexp_params() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6).toLowerCase() === "reason") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"reason\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_event_reason_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, reason) { + if (typeof reason !== 'undefined') data.reason = reason; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 7).toLowerCase() === "expires") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"expires\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_delta_seconds(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, expires) { + if (typeof expires !== 'undefined') data.expires = expires; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 11).toLowerCase() === "retry_after") { + result0 = input.substr(pos, 11); + pos += 11; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"retry_after\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_delta_seconds(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, retry_after) { + if (typeof retry_after !== 'undefined') data.retry_after = retry_after; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + if (result0 === null) { + result0 = parse_generic_param(); + } + } + } + + return result0; + } + + function parse_event_reason_value() { + var result0; + + if (input.substr(pos, 11).toLowerCase() === "deactivated") { + result0 = input.substr(pos, 11); + pos += 11; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"deactivated\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 9).toLowerCase() === "probation") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"probation\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 8).toLowerCase() === "rejected") { + result0 = input.substr(pos, 8); + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"rejected\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 7).toLowerCase() === "timeout") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"timeout\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 6).toLowerCase() === "giveup") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"giveup\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 10).toLowerCase() === "noresource") { + result0 = input.substr(pos, 10); + pos += 10; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"noresource\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 9).toLowerCase() === "invariant") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"invariant\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + } + } + } + } + } + + return result0; + } + + function parse_Subject() { + var result0; + result0 = parse_TEXT_UTF8_TRIM(); + result0 = result0 !== null ? result0 : ""; + return result0; + } + + function parse_Supported() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + result0 = result0 !== null ? result0 : ""; + return result0; + } + + function parse_To() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_SIP_URI_noparams(); + + if (result0 === null) { + result0 = parse_name_addr(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_to_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_to_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var tag = data.tag; + + try { + data = new NameAddrHeader(data.uri, data.display_name, data.params); + + if (tag) { + data.setParam('tag', tag); + } + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_to_param() { + var result0; + result0 = parse_tag_param(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_Via() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_via_param(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_via_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_via_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_via_param() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + result0 = parse_sent_protocol(); + + if (result0 !== null) { + result1 = parse_LWS(); + + if (result1 !== null) { + result2 = parse_sent_by(); + + if (result2 !== null) { + result3 = []; + pos1 = pos; + result4 = parse_SEMI(); + + if (result4 !== null) { + result5 = parse_via_params(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + + while (result4 !== null) { + result3.push(result4); + pos1 = pos; + result4 = parse_SEMI(); + + if (result4 !== null) { + result5 = parse_via_params(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + } + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_via_params() { + var result0; + result0 = parse_via_ttl(); + + if (result0 === null) { + result0 = parse_via_maddr(); + + if (result0 === null) { + result0 = parse_via_received(); + + if (result0 === null) { + result0 = parse_via_branch(); + + if (result0 === null) { + result0 = parse_response_port(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + } + } + } + } + + return result0; + } + + function parse_via_ttl() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 3).toLowerCase() === "ttl") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"ttl\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_ttl(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_ttl_value) { + data.ttl = via_ttl_value; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_via_maddr() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 5).toLowerCase() === "maddr") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"maddr\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_host(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_maddr) { + data.maddr = via_maddr; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_via_received() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 8).toLowerCase() === "received") { + result0 = input.substr(pos, 8); + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"received\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_IPv4address(); + + if (result2 === null) { + result2 = parse_IPv6address(); + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_received) { + data.received = via_received; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_via_branch() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6).toLowerCase() === "branch") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"branch\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_branch) { + data.branch = via_branch; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_response_port() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + + if (input.substr(pos, 5).toLowerCase() === "rport") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"rport\""); + } + } + + if (result0 !== null) { + pos1 = pos; + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_rport(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos1; + } + } else { + result1 = null; + pos = pos1; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_rport() { + var result0, result1, result2, result3, result4; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DIGIT(); + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_DIGIT(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_DIGIT(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result4 = parse_DIGIT(); + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, rport) { + data.rport = parseInt(rport.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_sent_protocol() { + var result0, result1, result2, result3, result4; + var pos0; + pos0 = pos; + result0 = parse_protocol_name(); + + if (result0 !== null) { + result1 = parse_SLASH(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result3 = parse_SLASH(); + + if (result3 !== null) { + result4 = parse_transport(); + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_protocol_name() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 3).toLowerCase() === "sip") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SIP\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + + if (result0 !== null) { + result0 = function (offset, via_protocol) { + data.protocol = via_protocol; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_transport() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 3).toLowerCase() === "udp") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"UDP\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 3).toLowerCase() === "tcp") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"TCP\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 3).toLowerCase() === "tls") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"TLS\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 4).toLowerCase() === "sctp") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SCTP\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + } + } + + if (result0 !== null) { + result0 = function (offset, via_transport) { + data.transport = via_transport; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_sent_by() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + result0 = parse_via_host(); + + if (result0 !== null) { + pos1 = pos; + result1 = parse_COLON(); + + if (result1 !== null) { + result2 = parse_via_port(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos1; + } + } else { + result1 = null; + pos = pos1; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_via_host() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_IPv4address(); + + if (result0 === null) { + result0 = parse_IPv6reference(); + + if (result0 === null) { + result0 = parse_hostname(); + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.host = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_via_port() { + var result0, result1, result2, result3, result4; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DIGIT(); + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_DIGIT(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_DIGIT(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result4 = parse_DIGIT(); + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_sent_by_port) { + data.port = parseInt(via_sent_by_port.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_ttl() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DIGIT(); + + if (result0 !== null) { + result1 = parse_DIGIT(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, ttl) { + return parseInt(ttl.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_WWW_Authenticate() { + var result0; + result0 = parse_challenge(); + return result0; + } + + function parse_Session_Expires() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_s_e_expires(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_s_e_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_s_e_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_s_e_expires() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_delta_seconds(); + + if (result0 !== null) { + result0 = function (offset, expires) { + data.expires = expires; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_s_e_params() { + var result0; + result0 = parse_s_e_refresher(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_s_e_refresher() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 9).toLowerCase() === "refresher") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"refresher\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + if (input.substr(pos, 3).toLowerCase() === "uac") { + result2 = input.substr(pos, 3); + pos += 3; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"uac\""); + } + } + + if (result2 === null) { + if (input.substr(pos, 3).toLowerCase() === "uas") { + result2 = input.substr(pos, 3); + pos += 3; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"uas\""); + } + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, s_e_refresher_value) { + data.refresher = s_e_refresher_value.toLowerCase(); + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_extension_header() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = parse_HCOLON(); + + if (result1 !== null) { + result2 = parse_header_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_header_value() { + var result0, result1; + result0 = []; + result1 = parse_TEXT_UTF8char(); + + if (result1 === null) { + result1 = parse_UTF8_CONT(); + + if (result1 === null) { + result1 = parse_LWS(); + } + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_TEXT_UTF8char(); + + if (result1 === null) { + result1 = parse_UTF8_CONT(); + + if (result1 === null) { + result1 = parse_LWS(); + } + } + } + + return result0; + } + + function parse_message_body() { + var result0, result1; + result0 = []; + result1 = parse_OCTET(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_OCTET(); + } + + return result0; + } + + function parse_uuid_URI() { + var result0, result1; + var pos0; + pos0 = pos; + + if (input.substr(pos, 5) === "uuid:") { + result0 = "uuid:"; + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"uuid:\""); + } + } + + if (result0 !== null) { + result1 = parse_uuid(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_uuid() { + var result0, result1, result2, result3, result4, result5, result6, result7, result8; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_hex8(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 !== null) { + result2 = parse_hex4(); + + if (result2 !== null) { + if (input.charCodeAt(pos) === 45) { + result3 = "-"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result3 !== null) { + result4 = parse_hex4(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 45) { + result5 = "-"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result5 !== null) { + result6 = parse_hex4(); + + if (result6 !== null) { + if (input.charCodeAt(pos) === 45) { + result7 = "-"; + pos++; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result7 !== null) { + result8 = parse_hex12(); + + if (result8 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, uuid) { + data = input.substring(pos + 5, offset); + }(pos0, result0[0]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_hex4() { + var result0, result1, result2, result3; + var pos0; + pos0 = pos; + result0 = parse_HEXDIG(); + + if (result0 !== null) { + result1 = parse_HEXDIG(); + + if (result1 !== null) { + result2 = parse_HEXDIG(); + + if (result2 !== null) { + result3 = parse_HEXDIG(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_hex8() { + var result0, result1; + var pos0; + pos0 = pos; + result0 = parse_hex4(); + + if (result0 !== null) { + result1 = parse_hex4(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_hex12() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_hex4(); + + if (result0 !== null) { + result1 = parse_hex4(); + + if (result1 !== null) { + result2 = parse_hex4(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Refer_To() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_SIP_URI_noparams(); + + if (result0 === null) { + result0 = parse_name_addr(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + try { + data = new NameAddrHeader(data.uri, data.display_name, data.params); + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Replaces() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_call_id(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_replaces_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_replaces_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_call_id() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_word(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 !== null) { + result2 = parse_word(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.call_id = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_replaces_param() { + var result0; + result0 = parse_to_tag(); + + if (result0 === null) { + result0 = parse_from_tag(); + + if (result0 === null) { + result0 = parse_early_flag(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + } + } + + return result0; + } + + function parse_to_tag() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6) === "to-tag") { + result0 = "to-tag"; + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"to-tag\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, to_tag) { + data.to_tag = to_tag; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_from_tag() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 8) === "from-tag") { + result0 = "from-tag"; + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"from-tag\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, from_tag) { + data.from_tag = from_tag; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_early_flag() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 10) === "early-only") { + result0 = "early-only"; + pos += 10; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"early-only\""); + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.early_only = true; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function cleanupExpected(expected) { + expected.sort(); + var lastExpected = null; + var cleanExpected = []; + + for (var i = 0; i < expected.length; i++) { + if (expected[i] !== lastExpected) { + cleanExpected.push(expected[i]); + lastExpected = expected[i]; + } + } + + return cleanExpected; + } + + function computeErrorPosition() { + /* + * The first idea was to use |String.split| to break the input up to the + * error position along newlines and derive the line and column from + * there. However IE's |split| implementation is so broken that it was + * enough to prevent it. + */ + var line = 1; + var column = 1; + var seenCR = false; + + for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) { + var ch = input.charAt(i); + + if (ch === "\n") { + if (!seenCR) { + line++; + } + + column = 1; + seenCR = false; + } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { + line++; + column = 1; + seenCR = true; + } else { + column++; + seenCR = false; + } + } + + return { + line: line, + column: column + }; + } + + var URI = require('./URI'); + + var NameAddrHeader = require('./NameAddrHeader'); + + var data = {}; + var result = parseFunctions[startRule](); + /* + * The parser is now in one of the following three states: + * + * 1. The parser successfully parsed the whole input. + * + * - |result !== null| + * - |pos === input.length| + * - |rightmostFailuresExpected| may or may not contain something + * + * 2. The parser successfully parsed only a part of the input. + * + * - |result !== null| + * - |pos < input.length| + * - |rightmostFailuresExpected| may or may not contain something + * + * 3. The parser did not successfully parse any part of the input. + * + * - |result === null| + * - |pos === 0| + * - |rightmostFailuresExpected| contains at least one failure + * + * All code following this comment (including called functions) must + * handle these states. + */ + + if (result === null || pos !== input.length) { + var offset = Math.max(pos, rightmostFailuresPos); + var found = offset < input.length ? input.charAt(offset) : null; + var errorPosition = computeErrorPosition(); + new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column); + return -1; + } + + return data; + }, + + /* Returns the parser source code. */ + toSource: function toSource() { + return this._source; + } + }; + /* Thrown when a parser encounters a syntax error. */ + + result.SyntaxError = function (expected, found, offset, line, column) { + function buildMessage(expected, found) { + var expectedHumanized, foundHumanized; + + switch (expected.length) { + case 0: + expectedHumanized = "end of input"; + break; + + case 1: + expectedHumanized = expected[0]; + break; + + default: + expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1]; + } + + foundHumanized = found ? quote(found) : "end of input"; + return "Expected " + expectedHumanized + " but " + foundHumanized + " found."; + } + + this.name = "SyntaxError"; + this.expected = expected; + this.found = found; + this.message = buildMessage(expected, found); + this.offset = offset; + this.line = line; + this.column = column; + }; + + result.SyntaxError.prototype = Error.prototype; + return result; +}(); +},{"./NameAddrHeader":10,"./URI":27}],8:[function(require,module,exports){ +"use strict"; + +var pkg = require('../package.json'); + +var C = require('./Constants'); + +var Exceptions = require('./Exceptions'); + +var Utils = require('./Utils'); + +var UA = require('./UA'); + +var URI = require('./URI'); + +var NameAddrHeader = require('./NameAddrHeader'); + +var Grammar = require('./Grammar'); + +var WebSocketInterface = require('./WebSocketInterface'); + +var debug = require('debug')('JsSIP'); + +debug('version %s', pkg.version); +/** + * Expose the JsSIP module. + */ + +module.exports = { + C: C, + Exceptions: Exceptions, + Utils: Utils, + UA: UA, + URI: URI, + NameAddrHeader: NameAddrHeader, + WebSocketInterface: WebSocketInterface, + Grammar: Grammar, + // Expose the debug module. + debug: require('debug'), + + get name() { + return pkg.title; + }, + + get version() { + return pkg.version; + } + +}; +},{"../package.json":40,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":26,"./URI":27,"./Utils":28,"./WebSocketInterface":29,"debug":32}],9:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var SIPMessage = require('./SIPMessage'); + +var Utils = require('./Utils'); + +var RequestSender = require('./RequestSender'); + +var Exceptions = require('./Exceptions'); + +var debug = require('debug')('JsSIP:Message'); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Message, _EventEmitter); + + var _super = _createSuper(Message); + + function Message(ua) { + var _this; + + _classCallCheck(this, Message); + + _this = _super.call(this); + _this._ua = ua; + _this._request = null; + _this._closed = false; + _this._direction = null; + _this._local_identity = null; + _this._remote_identity = null; // Whether an incoming message has been replied. + + _this._is_replied = false; // Custom message empty object for high level use. + + _this._data = {}; + return _this; + } + + _createClass(Message, [{ + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "send", + value: function send(target, body) { + var _this2 = this; + + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + var originalTarget = target; + + if (target === undefined || body === undefined) { + throw new TypeError('Not enough arguments'); + } // Check target validity. + + + target = this._ua.normalizeTarget(target); + + if (!target) { + throw new TypeError("Invalid target: ".concat(originalTarget)); + } // Get call options. + + + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var contentType = options.contentType || 'text/plain'; // Set event handlers. + + for (var event in eventHandlers) { + if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { + this.on(event, eventHandlers[event]); + } + } + + extraHeaders.push("Content-Type: ".concat(contentType)); + this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, null, extraHeaders); + + if (body) { + this._request.body = body; + } + + var request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout: function onRequestTimeout() { + _this2._onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this2._onTransportError(); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this2._receiveResponse(response); + } + }); + + this._newMessage('local', this._request); + + request_sender.send(); + } + }, { + key: "init_incoming", + value: function init_incoming(request) { + this._request = request; + + this._newMessage('remote', request); // Reply with a 200 OK if the user didn't reply. + + + if (!this._is_replied) { + this._is_replied = true; + request.reply(200); + } + + this._close(); + } + /** + * Accept the incoming Message + * Only valid for incoming Messages + */ + + }, { + key: "accept", + value: function accept() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var body = options.body; + + if (this._direction !== 'incoming') { + throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message'); + } + + if (this._is_replied) { + throw new Error('incoming Message already replied'); + } + + this._is_replied = true; + + this._request.reply(200, null, extraHeaders, body); + } + /** + * Reject the incoming Message + * Only valid for incoming Messages + */ + + }, { + key: "reject", + value: function reject() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var status_code = options.status_code || 480; + var reason_phrase = options.reason_phrase; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var body = options.body; + + if (this._direction !== 'incoming') { + throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message'); + } + + if (this._is_replied) { + throw new Error('incoming Message already replied'); + } + + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } + + this._is_replied = true; + + this._request.reply(status_code, reason_phrase, extraHeaders, body); + } + }, { + key: "_receiveResponse", + value: function _receiveResponse(response) { + if (this._closed) { + return; + } + + switch (true) { + case /^1[0-9]{2}$/.test(response.status_code): + // Ignore provisional responses. + break; + + case /^2[0-9]{2}$/.test(response.status_code): + this._succeeded('remote', response); + + break; + + default: + { + var cause = Utils.sipErrorCause(response.status_code); + + this._failed('remote', response, cause); + + break; + } + } + } + }, { + key: "_onRequestTimeout", + value: function _onRequestTimeout() { + if (this._closed) { + return; + } + + this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT); + } + }, { + key: "_onTransportError", + value: function _onTransportError() { + if (this._closed) { + return; + } + + this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); + } + }, { + key: "_close", + value: function _close() { + this._closed = true; + + this._ua.destroyMessage(this); + } + /** + * Internal Callbacks + */ + + }, { + key: "_newMessage", + value: function _newMessage(originator, request) { + if (originator === 'remote') { + this._direction = 'incoming'; + this._local_identity = request.to; + this._remote_identity = request.from; + } else if (originator === 'local') { + this._direction = 'outgoing'; + this._local_identity = request.from; + this._remote_identity = request.to; + } + + this._ua.newMessage(this, { + originator: originator, + message: this, + request: request + }); + } + }, { + key: "_failed", + value: function _failed(originator, response, cause) { + debug('MESSAGE failed'); + + this._close(); + + debug('emit "failed"'); + this.emit('failed', { + originator: originator, + response: response || null, + cause: cause + }); + } + }, { + key: "_succeeded", + value: function _succeeded(originator, response) { + debug('MESSAGE succeeded'); + + this._close(); + + debug('emit "succeeded"'); + this.emit('succeeded', { + originator: originator, + response: response + }); + } + }]); + + return Message; +}(EventEmitter); +},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],10:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var URI = require('./URI'); + +var Grammar = require('./Grammar'); + +module.exports = /*#__PURE__*/function () { + function NameAddrHeader(uri, display_name, parameters) { + _classCallCheck(this, NameAddrHeader); + + // Checks. + if (!uri || !(uri instanceof URI)) { + throw new TypeError('missing or invalid "uri" parameter'); + } // Initialize parameters. + + + this._uri = uri; + this._parameters = {}; + this.display_name = display_name; + + for (var param in parameters) { + if (Object.prototype.hasOwnProperty.call(parameters, param)) { + this.setParam(param, parameters[param]); + } + } + } + + _createClass(NameAddrHeader, [{ + key: "uri", + get: function get() { + return this._uri; + } + }, { + key: "display_name", + get: function get() { + return this._display_name; + }, + set: function set(value) { + this._display_name = value === 0 ? '0' : value; + } + }, { + key: "setParam", + value: function setParam(key, value) { + if (key) { + this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString(); + } + } + }, { + key: "getParam", + value: function getParam(key) { + if (key) { + return this._parameters[key.toLowerCase()]; + } + } + }, { + key: "hasParam", + value: function hasParam(key) { + if (key) { + return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false; + } + } + }, { + key: "deleteParam", + value: function deleteParam(parameter) { + parameter = parameter.toLowerCase(); + + if (this._parameters.hasOwnProperty(parameter)) { + var value = this._parameters[parameter]; + delete this._parameters[parameter]; + return value; + } + } + }, { + key: "clearParams", + value: function clearParams() { + this._parameters = {}; + } + }, { + key: "clone", + value: function clone() { + return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters))); + } + }, { + key: "_quote", + value: function _quote(str) { + return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + } + }, { + key: "toString", + value: function toString() { + var body = this._display_name ? "\"".concat(this._quote(this._display_name), "\" ") : ''; + body += "<".concat(this._uri.toString(), ">"); + + for (var parameter in this._parameters) { + if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) { + body += ";".concat(parameter); + + if (this._parameters[parameter] !== null) { + body += "=".concat(this._parameters[parameter]); + } + } + } + + return body; + } + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a NameAddrHeader instance or undefined if + * it is an invalid NameAddrHeader. + */ + function parse(name_addr_header) { + name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); + + if (name_addr_header !== -1) { + return name_addr_header; + } else { + return undefined; + } + } + }]); + + return NameAddrHeader; +}(); +},{"./Grammar":7,"./URI":27}],11:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:Notifier'); + +var debugerror = require('debug')('JsSIP:ERROR:Notifier'); + +debugerror.log = console.warn.bind(console); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Notifier, _EventEmitter); + + var _super = _createSuper(Notifier); + + function Notifier(ua, _ref) { + var _this; + + var subscribe = _ref.subscribe, + content_type = _ref.content_type, + headers = _ref.headers, + credential = _ref.credential, + pending = _ref.pending; + + _classCallCheck(this, Notifier); + + debug('new'); + _this = _super.call(this); + _this._ua = ua; + _this.expires_timestamp = null; + _this.expires_timer = null; + _this._state = pending ? 'pending' : 'active'; + _this.is_final_notify_sent = false; + _this.is_first_notify_response = true; + _this.id = null; + _this.event_name = subscribe.getHeader('event'); + + if (!content_type) { + throw new TypeError('content_type is undefined'); + } + + _this.content_type = content_type; + _this.expires = parseInt(subscribe.getHeader('expires')); + _this.credential = credential; + var user = subscribe.to.uri.user; + var domain = subscribe.to.uri.host; + _this.contact = ""); + _this.rcseq = subscribe.cseq; + _this.headers = headers ? headers : []; + _this.target = subscribe.from.uri.user; + subscribe.to_tag = Utils.newTag(); + _this.params = { + from: subscribe.to, + from_tag: subscribe.to_tag, + to: subscribe.from, + to_tag: subscribe.from_tag, + call_id: subscribe.call_id, + cseq: Math.floor(Math.random() * 10000 + 1) + }; + _this.id = "".concat(_this.params.call_id).concat(_this.params.from_tag).concat(_this.params.to_tag); + debug('add dialog id=', _this.id); + + _this._ua.newDialog(_assertThisInitialized(_this)); + + _this._setExpiresTimestamp(); + + _this._setExpiresTimer(); + + _this.is_terminated = false; + _this.terminated_reason = undefined; // Custom session empty object for high level use. + + _this.data = {}; + subscribe.reply(200, null, ["Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); + return _this; + } + /** + * Callbacks + */ + + + _createClass(Notifier, [{ + key: "onAuthenticated", + value: function onAuthenticated() { + this.params.cseq++; + } + }, { + key: "onRequestTimeout", + value: function onRequestTimeout() { + this._dialogTerminated('notify response timeout'); + } + }, { + key: "onTransportError", + value: function onTransportError() { + this._dialogTerminated('notify transport error'); + } + }, { + key: "onReceiveResponse", + value: function onReceiveResponse(response) { + if (response.status_code >= 200 && response.status_code < 300) { + if (this.is_first_notify_response) { + this.is_first_notify_response = false; + this.route_set = response.getHeaders('record-route').reverse(); + + if (this.route_set.length > 0) { + this.params.route_set = this.route_set; + } + } + } else if (response.status_code >= 300) { + this._dialogTerminated('receive notify non-OK response'); + } + } + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + if (request.method !== JsSIP_C.SUBSCRIBE) { + request.reply(405); + return; + } + + var h = request.getHeader('expires'); + + if (h === undefined || h === null) { + h = '900'; // Missed header Expires. RFC 6665 3.1.1. Set default expires value + + debug("Missed expires header. Set by default ".concat(h)); + } + + this.expires = parseInt(h); + request.reply(200, null, ["Expires: ".concat(this.expires), "Contact: ".concat(this.contact)]); + var body = request.body; + var content_type = request.getHeader('content-type'); + var is_unsubscribe = this.expires === 0; + debug('emit "subscribe"'); + this.emit('subscribe', is_unsubscribe, request, body, content_type); + + if (is_unsubscribe) { + this._dialogTerminated('receive un-subscribe'); + } else { + this._setExpiresTimestamp(); + + this._setExpiresTimer(); + } + } + /** + * User API + */ + + }, { + key: "setActiveState", + value: function setActiveState() { + debug('setActiveState()'); + + if (this._state === 'pending') { + this._state = 'active'; + } + } + }, { + key: "sendNotify", + value: function sendNotify() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + debug('sendNotify()'); + var subs_state = this._state; + + if (this._state !== 'terminated') { + subs_state += ";expires=".concat(this._getExpiresTimestamp()); + } else if (this.terminated_reason) { + subs_state += ";reason=".concat(this.terminated_reason); + } + + var headers = this.headers.slice(); + headers.push("Subscription-State: ".concat(subs_state)); + headers.push("Event: ".concat(this.event_name)); + + if (body) { + headers.push("Content-Type: ".concat(this.content_type)); + } + + this.params.cseq++; + + this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); + } + }, { + key: "sendFinalNotify", + value: function sendFinalNotify() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + debug('sendFinalNotify()'); + + if (this.is_final_notify_sent) { + return; + } + + this.is_final_notify_sent = true; + + this._dialogTerminated('send final notify'); + + this.terminated_reason = reason; + this.sendNotify(body); + } + }, { + key: "state", + get: function get() { + return this._state; + } + /** + * Private API. + */ + + }, { + key: "_dialogTerminated", + value: function _dialogTerminated(reason) { + var _this2 = this; + + if (this.is_terminated) { + return; + } + + this.is_terminated = true; + this._state = 'terminated'; + clearTimeout(this.expires_timer); // If delay needed ? + + setTimeout(function () { + debug('remove dialog id=', _this2.id); + + _this2._ua.destroyDialog(_this2); + }, 32000); + debug("emit \"terminated\" ".concat(reason, "\"")); + this.emit('terminated', reason); + } + }, { + key: "_setExpiresTimestamp", + value: function _setExpiresTimestamp() { + this.expires_timestamp = new Date().getTime() + this.expires * 1000; + } + }, { + key: "_getExpiresTimestamp", + value: function _getExpiresTimestamp() { + var delta = Math.floor((this.expires_timestamp - new Date().getTime()) / 1000); + return delta >= 0 ? delta : 0; + } + }, { + key: "_setExpiresTimer", + value: function _setExpiresTimer() { + var _this3 = this; + + clearTimeout(this.expires_timer); + setTimeout(function () { + if (_this3.is_final_notify_sent) { + return; + } + + _this3.terminated_reason = 'timeout'; + _this3.is_final_notify_sent = true; + + _this3.sendNotify(); + + _this3._dialogTerminated('subscription expired'); + }, this.expires * 1000); + } + }]); + + return Notifier; +}(EventEmitter); +},{"./Constants":2,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ +"use strict"; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var Grammar = require('./Grammar'); + +var SIPMessage = require('./SIPMessage'); + +var debugerror = require('debug')('JsSIP:ERROR:Parser'); + +debugerror.log = console.warn.bind(console); +/** + * Parse SIP Message + */ + +exports.parseMessage = function (data, ua) { + var message; + var bodyStart; + var headerEnd = data.indexOf('\r\n'); + + if (headerEnd === -1) { + debugerror('parseMessage() | no CRLF found, not a SIP message'); + return; + } // Parse first line. Check if it is a Request or a Reply. + + + var firstLine = data.substring(0, headerEnd); + var parsed = Grammar.parse(firstLine, 'Request_Response'); + + if (parsed === -1) { + debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); + return; + } else if (!parsed.status_code) { + message = new SIPMessage.IncomingRequest(ua); + message.method = parsed.method; + message.ruri = parsed.uri; + } else { + message = new SIPMessage.IncomingResponse(); + message.status_code = parsed.status_code; + message.reason_phrase = parsed.reason_phrase; + } + + message.data = data; + var headerStart = headerEnd + 2; + /* Loop over every line in data. Detect the end of each header and parse + * it or simply add to the headers collection. + */ + + while (true) { + headerEnd = getHeader(data, headerStart); // The SIP message has normally finished. + + if (headerEnd === -2) { + bodyStart = headerStart + 2; + break; + } // Data.indexOf returned -1 due to a malformed message. + else if (headerEnd === -1) { + debugerror('parseMessage() | malformed message'); + return; + } + + parsed = parseHeader(message, data, headerStart, headerEnd); + + if (parsed !== true) { + debugerror('parseMessage() |', parsed.error); + return; + } + + headerStart = headerEnd + 2; + } + /* RFC3261 18.3. + * If there are additional bytes in the transport packet + * beyond the end of the body, they MUST be discarded. + */ + + + if (message.hasHeader('content-length')) { + var contentLength = message.getHeader('content-length'); + message.body = data.substr(bodyStart, contentLength); + } else { + message.body = data.substring(bodyStart); + } + + return message; +}; +/** + * Extract and parse every header of a SIP message. + */ + + +function getHeader(data, headerStart) { + // 'start' position of the header. + var start = headerStart; // 'end' position of the header. + + var end = 0; // 'partial end' position of the header. + + var partialEnd = 0; // End of message. + + if (data.substring(start, start + 2).match(/(^\r\n)/)) { + return -2; + } + + while (end === 0) { + // Partial End of Header. + partialEnd = data.indexOf('\r\n', start); // 'indexOf' returns -1 if the value to be found never occurs. + + if (partialEnd === -1) { + return partialEnd; + } + + if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) { + // Not the end of the message. Continue from the next position. + start = partialEnd + 2; + } else { + end = partialEnd; + } + } + + return end; +} + +function parseHeader(message, data, headerStart, headerEnd) { + var parsed; + var hcolonIndex = data.indexOf(':', headerStart); + var headerName = data.substring(headerStart, hcolonIndex).trim(); + var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim(); // If header-field is well-known, parse it. + + switch (headerName.toLowerCase()) { + case 'via': + case 'v': + message.addHeader('via', headerValue); + + if (message.getHeaders('via').length === 1) { + parsed = message.parseHeader('Via'); + + if (parsed) { + message.via = parsed; + message.via_branch = parsed.branch; + } + } else { + parsed = 0; + } + + break; + + case 'from': + case 'f': + message.setHeader('from', headerValue); + parsed = message.parseHeader('from'); + + if (parsed) { + message.from = parsed; + message.from_tag = parsed.getParam('tag'); + } + + break; + + case 'to': + case 't': + message.setHeader('to', headerValue); + parsed = message.parseHeader('to'); + + if (parsed) { + message.to = parsed; + message.to_tag = parsed.getParam('tag'); + } + + break; + + case 'record-route': + parsed = Grammar.parse(headerValue, 'Record_Route'); + + if (parsed === -1) { + parsed = undefined; + } else { + var _iterator = _createForOfIteratorHelper(parsed), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var header = _step.value; + message.addHeader('record-route', headerValue.substring(header.possition, header.offset)); + message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed; + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + + break; + + case 'call-id': + case 'i': + message.setHeader('call-id', headerValue); + parsed = message.parseHeader('call-id'); + + if (parsed) { + message.call_id = headerValue; + } + + break; + + case 'contact': + case 'm': + parsed = Grammar.parse(headerValue, 'Contact'); + + if (parsed === -1) { + parsed = undefined; + } else { + var _iterator2 = _createForOfIteratorHelper(parsed), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var _header = _step2.value; + message.addHeader('contact', headerValue.substring(_header.possition, _header.offset)); + message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed; + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + + break; + + case 'content-length': + case 'l': + message.setHeader('content-length', headerValue); + parsed = message.parseHeader('content-length'); + break; + + case 'content-type': + case 'c': + message.setHeader('content-type', headerValue); + parsed = message.parseHeader('content-type'); + break; + + case 'cseq': + message.setHeader('cseq', headerValue); + parsed = message.parseHeader('cseq'); + + if (parsed) { + message.cseq = parsed.value; + } + + if (message instanceof SIPMessage.IncomingResponse) { + message.method = parsed.method; + } + + break; + + case 'max-forwards': + message.setHeader('max-forwards', headerValue); + parsed = message.parseHeader('max-forwards'); + break; + + case 'www-authenticate': + message.setHeader('www-authenticate', headerValue); + parsed = message.parseHeader('www-authenticate'); + break; + + case 'proxy-authenticate': + message.setHeader('proxy-authenticate', headerValue); + parsed = message.parseHeader('proxy-authenticate'); + break; + + case 'session-expires': + case 'x': + message.setHeader('session-expires', headerValue); + parsed = message.parseHeader('session-expires'); + + if (parsed) { + message.session_expires = parsed.expires; + message.session_expires_refresher = parsed.refresher; + } + + break; + + case 'refer-to': + case 'r': + message.setHeader('refer-to', headerValue); + parsed = message.parseHeader('refer-to'); + + if (parsed) { + message.refer_to = parsed; + } + + break; + + case 'replaces': + message.setHeader('replaces', headerValue); + parsed = message.parseHeader('replaces'); + + if (parsed) { + message.replaces = parsed; + } + + break; + + case 'event': + case 'o': + message.setHeader('event', headerValue); + parsed = message.parseHeader('event'); + + if (parsed) { + message.event = parsed; + } + + break; + + default: + // Do not parse this header. + message.addHeader(headerName, headerValue); + parsed = 0; + } + + if (parsed === undefined) { + return { + error: "error parsing header \"".concat(headerName, "\"") + }; + } else { + return true; + } +} +},{"./Grammar":7,"./SIPMessage":20,"debug":32}],13:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +/* globals RTCPeerConnection: false, RTCSessionDescription: false */ +var EventEmitter = require('events').EventEmitter; + +var sdp_transform = require('sdp-transform'); + +var JsSIP_C = require('./Constants'); + +var Exceptions = require('./Exceptions'); + +var Transactions = require('./Transactions'); + +var Utils = require('./Utils'); + +var Timers = require('./Timers'); + +var SIPMessage = require('./SIPMessage'); + +var Dialog = require('./Dialog'); + +var RequestSender = require('./RequestSender'); + +var RTCSession_DTMF = require('./RTCSession/DTMF'); + +var RTCSession_Info = require('./RTCSession/Info'); + +var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier'); + +var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); + +var URI = require('./URI'); + +var debug = require('debug')('JsSIP:RTCSession'); + +var debugerror = require('debug')('JsSIP:ERROR:RTCSession'); + +debugerror.log = console.warn.bind(console); +var C = { + // RTCSession states. + 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 +}; +/** + * Local variables. + */ + +var holdMediaTypes = ['audio', 'video']; + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(RTCSession, _EventEmitter); + + var _super = _createSuper(RTCSession); + + function RTCSession(ua) { + var _this; + + _classCallCheck(this, RTCSession); + + debug('new'); + _this = _super.call(this); + _this._id = null; + _this._ua = ua; + _this._status = C.STATUS_NULL; + _this._dialog = null; + _this._earlyDialogs = {}; + _this._contact = null; + _this._from_tag = null; + _this._to_tag = null; // The RTCPeerConnection instance (public attribute). + + _this._connection = null; // Prevent races on serial PeerConnction operations. + + _this._connectionPromiseQueue = Promise.resolve(); // Incoming/Outgoing request being currently processed. + + _this._request = null; // Cancel state for initial outgoing request. + + _this._is_canceled = false; + _this._cancel_reason = ''; // RTCSession confirmation flag. + + _this._is_confirmed = false; // Is late SDP being negotiated. + + _this._late_sdp = false; // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()). + + _this._rtcOfferConstraints = null; + _this._rtcAnswerConstraints = null; // Local MediaStream. + + _this._localMediaStream = null; + _this._localMediaStreamLocallyGenerated = false; // Flag to indicate PeerConnection ready for new actions. + + _this._rtcReady = true; // SIP Timers. + + _this._timers = { + ackTimer: null, + expiresTimer: null, + invite2xxTimer: null, + userNoAnswerTimer: null + }; // Session info. + + _this._direction = null; + _this._local_identity = null; + _this._remote_identity = null; + _this._start_time = null; + _this._end_time = null; + _this._tones = null; // Mute/Hold state. + + _this._audioMuted = false; + _this._videoMuted = false; + _this._localHold = false; + _this._remoteHold = false; // Session Timers (RFC 4028). + + _this._sessionTimers = { + enabled: _this._ua.configuration.session_timers, + refreshMethod: _this._ua.configuration.session_timers_refresh_method, + defaultExpires: JsSIP_C.SESSION_EXPIRES, + currentExpires: null, + running: false, + refresher: false, + timer: null // A setTimeout. + + }; // Map of ReferSubscriber instances indexed by the REFER's CSeq number. + + _this._referSubscribers = {}; // Custom session empty object for high level use. + + _this._data = {}; + return _this; + } + /** + * User API + */ + // Expose RTCSession constants as a property of the RTCSession instance. + + + _createClass(RTCSession, [{ + key: "C", + get: function get() { + return C; + } // Expose session failed/ended causes as a property of the RTCSession instance. + + }, { + key: "causes", + get: function get() { + return JsSIP_C.causes; + } + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "connection", + get: function get() { + return this._connection; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "start_time", + get: function get() { + return this._start_time; + } + }, { + key: "end_time", + get: function get() { + return this._end_time; + } + }, { + key: "data", + get: function get() { + return this._data; + }, + set: function set(_data) { + this._data = _data; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "isInProgress", + value: function isInProgress() { + switch (this._status) { + case C.STATUS_NULL: + case C.STATUS_INVITE_SENT: + case C.STATUS_1XX_RECEIVED: + case C.STATUS_INVITE_RECEIVED: + case C.STATUS_WAITING_FOR_ANSWER: + return true; + + default: + return false; + } + } + }, { + key: "isEstablished", + value: function isEstablished() { + switch (this._status) { + case C.STATUS_ANSWERED: + case C.STATUS_WAITING_FOR_ACK: + case C.STATUS_CONFIRMED: + return true; + + default: + return false; + } + } + }, { + key: "isEnded", + value: function isEnded() { + switch (this._status) { + case C.STATUS_CANCELED: + case C.STATUS_TERMINATED: + return true; + + default: + return false; + } + } + }, { + key: "isMuted", + value: function isMuted() { + return { + audio: this._audioMuted, + video: this._videoMuted + }; + } + }, { + key: "isOnHold", + value: function isOnHold() { + return { + local: this._localHold, + remote: this._remoteHold + }; + } + }, { + key: "connect", + value: function connect(target) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var initCallback = arguments.length > 2 ? arguments[2] : undefined; + debug('connect()'); + var originalTarget = target; + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var mediaConstraints = Utils.cloneObject(options.mediaConstraints, { + audio: true, + video: true + }); + var mediaStream = options.mediaStream || null; + var pcConfig = Utils.cloneObject(options.pcConfig, { + iceServers: [] + }); + var rtcConstraints = options.rtcConstraints || null; + var rtcOfferConstraints = options.rtcOfferConstraints || null; + this._rtcOfferConstraints = rtcOfferConstraints; + this._rtcAnswerConstraints = options.rtcAnswerConstraints || null; + this._data = options.data || this._data; // Check target. + + if (target === undefined) { + throw new TypeError('Not enough arguments'); + } // Check Session Status. + + + if (this._status !== C.STATUS_NULL) { + throw new Exceptions.InvalidStateError(this._status); + } // Check WebRTC support. + + + if (!window.RTCPeerConnection) { + throw new Exceptions.NotSupportedError('WebRTC not supported'); + } // Check target validity. + + + target = this._ua.normalizeTarget(target); + + if (!target) { + throw new TypeError("Invalid target: ".concat(originalTarget)); + } // Session Timers. + + + if (this._sessionTimers.enabled) { + if (Utils.isDecimal(options.sessionTimersExpires)) { + if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) { + this._sessionTimers.defaultExpires = options.sessionTimersExpires; + } else { + this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES; + } + } + } // Set event handlers. + + + for (var event in eventHandlers) { + if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { + this.on(event, eventHandlers[event]); + } + } // Session parameter initialization. + + + this._from_tag = Utils.newTag(); // Set anonymous property. + + var anonymous = options.anonymous || false; + var requestParams = { + from_tag: this._from_tag + }; + this._contact = this._ua.contact.toString({ + anonymous: anonymous, + outbound: true + }); + + if (anonymous) { + requestParams.from_display_name = 'Anonymous'; + requestParams.from_uri = new URI('sip', 'anonymous', 'anonymous.invalid'); + extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())); + extraHeaders.push('Privacy: id'); + } else if (options.fromUserName) { + requestParams.from_uri = new URI('sip', options.fromUserName, this._ua.configuration.uri.host); + extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())); + } + + if (options.fromDisplayName) { + requestParams.from_display_name = options.fromDisplayName; + } + + extraHeaders.push("Contact: ".concat(this._contact)); + extraHeaders.push('Content-Type: application/sdp'); + + if (this._sessionTimers.enabled) { + extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher ? ';refresher=uac' : '')); + } + + this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders); + this._id = this._request.call_id + this._from_tag; // Create a new RTCPeerConnection instance. + + this._createRTCConnection(pcConfig, rtcConstraints); // Set internal properties. + + + this._direction = 'outgoing'; + this._local_identity = this._request.from; + this._remote_identity = this._request.to; // User explicitly provided a newRTCSession callback for this session. + + if (initCallback) { + initCallback(this); + } + + this._newRTCSession('local', this._request); + + this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream); + } + }, { + key: "init_incoming", + value: function init_incoming(request, initCallback) { + var _this2 = this; + + debug('init_incoming()'); + var expires; + var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type. + + if (request.body && contentType !== 'application/sdp') { + request.reply(415); + return; + } // Session parameter initialization. + + + this._status = C.STATUS_INVITE_RECEIVED; + this._from_tag = request.from_tag; + this._id = request.call_id + this._from_tag; + this._request = request; + this._contact = this._ua.contact.toString(); // Get the Expires header value if exists. + + if (request.hasHeader('expires')) { + expires = request.getHeader('expires') * 1000; + } + /* Set the to_tag before + * replying a response code that will create a dialog. + */ + + + request.to_tag = Utils.newTag(); // An error on dialog creation will fire 'failed' event. + + if (!this._createDialog(request, 'UAS', true)) { + request.reply(500, 'Missing Contact header field'); + return; + } + + if (request.body) { + this._late_sdp = false; + } else { + this._late_sdp = true; + } + + this._status = C.STATUS_WAITING_FOR_ANSWER; // Set userNoAnswerTimer. + + this._timers.userNoAnswerTimer = setTimeout(function () { + request.reply(408); + + _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER); + }, this._ua.configuration.no_answer_timeout); + /* Set expiresTimer + * RFC3261 13.3.1 + */ + + if (expires) { + this._timers.expiresTimer = setTimeout(function () { + if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) { + request.reply(487); + + _this2._failed('system', null, JsSIP_C.causes.EXPIRES); + } + }, expires); + } // Set internal properties. + + + this._direction = 'incoming'; + this._local_identity = request.to; + this._remote_identity = request.from; // A init callback was specifically defined. + + if (initCallback) { + initCallback(this); + } // Fire 'newRTCSession' event. + + + this._newRTCSession('remote', request); // The user may have rejected the call in the 'newRTCSession' event. + + + if (this._status === C.STATUS_TERMINATED) { + return; + } // Reply 180. + + + request.reply(180, null, ["Contact: ".concat(this._contact)]); // Fire 'progress' event. + // TODO: Document that 'response' field in 'progress' event is null for incoming calls. + + this._progress('local', null); + } + /** + * Answer the call. + */ + + }, { + key: "answer", + value: function answer() { + var _this3 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + debug('answer()'); + var request = this._request; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var mediaConstraints = Utils.cloneObject(options.mediaConstraints); + var mediaStream = options.mediaStream || null; + var pcConfig = Utils.cloneObject(options.pcConfig, { + iceServers: [] + }); + var rtcConstraints = options.rtcConstraints || null; + var rtcAnswerConstraints = options.rtcAnswerConstraints || null; + var rtcOfferConstraints = Utils.cloneObject(options.rtcOfferConstraints); + var tracks; + var peerHasAudioLine = false; + var peerHasVideoLine = false; + var peerOffersFullAudio = false; + var peerOffersFullVideo = false; + this._rtcAnswerConstraints = rtcAnswerConstraints; + this._rtcOfferConstraints = options.rtcOfferConstraints || null; + this._data = options.data || this._data; // Check Session Direction and Status. + + if (this._direction !== 'incoming') { + throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession'); + } // Check Session status. + + + if (this._status !== C.STATUS_WAITING_FOR_ANSWER) { + throw new Exceptions.InvalidStateError(this._status); + } // Session Timers. + + + if (this._sessionTimers.enabled) { + if (Utils.isDecimal(options.sessionTimersExpires)) { + if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) { + this._sessionTimers.defaultExpires = options.sessionTimersExpires; + } else { + this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES; + } + } + } + + this._status = C.STATUS_ANSWERED; // An error on dialog creation will fire 'failed' event. + + if (!this._createDialog(request, 'UAS')) { + request.reply(500, 'Error creating dialog'); + return; + } + + clearTimeout(this._timers.userNoAnswerTimer); + extraHeaders.unshift("Contact: ".concat(this._contact)); // Determine incoming media from incoming SDP offer (if any). + + var sdp = request.parseSDP(); // Make sure sdp.media is an array, not the case if there is only one media. + + if (!Array.isArray(sdp.media)) { + sdp.media = [sdp.media]; + } // Go through all medias in SDP to find offered capabilities to answer with. + + + var _iterator = _createForOfIteratorHelper(sdp.media), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var m = _step.value; + + if (m.type === 'audio') { + peerHasAudioLine = true; + + if (!m.direction || m.direction === 'sendrecv') { + peerOffersFullAudio = true; + } + } + + if (m.type === 'video') { + peerHasVideoLine = true; + + if (!m.direction || m.direction === 'sendrecv') { + peerOffersFullVideo = true; + } + } + } // Remove audio from mediaStream if suggested by mediaConstraints. + + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + if (mediaStream && mediaConstraints.audio === false) { + tracks = mediaStream.getAudioTracks(); + + var _iterator2 = _createForOfIteratorHelper(tracks), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var track = _step2.value; + mediaStream.removeTrack(track); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } // Remove video from mediaStream if suggested by mediaConstraints. + + + if (mediaStream && mediaConstraints.video === false) { + tracks = mediaStream.getVideoTracks(); + + var _iterator3 = _createForOfIteratorHelper(tracks), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _track = _step3.value; + mediaStream.removeTrack(_track); + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } // Set audio constraints based on incoming stream if not supplied. + + + if (!mediaStream && mediaConstraints.audio === undefined) { + mediaConstraints.audio = peerOffersFullAudio; + } // Set video constraints based on incoming stream if not supplied. + + + if (!mediaStream && mediaConstraints.video === undefined) { + mediaConstraints.video = peerOffersFullVideo; + } // Don't ask for audio if the incoming offer has no audio section. + + + if (!mediaStream && !peerHasAudioLine && !rtcOfferConstraints.offerToReceiveAudio) { + mediaConstraints.audio = false; + } // Don't ask for video if the incoming offer has no video section. + + + if (!mediaStream && !peerHasVideoLine && !rtcOfferConstraints.offerToReceiveVideo) { + mediaConstraints.video = false; + } // Create a new RTCPeerConnection instance. + // TODO: This may throw an error, should react. + + + this._createRTCConnection(pcConfig, rtcConstraints); + + Promise.resolve() // Handle local MediaStream. + .then(function () { + // A local MediaStream is given, use it. + if (mediaStream) { + return mediaStream; + } // Audio and/or video requested, prompt getUserMedia. + else if (mediaConstraints.audio || mediaConstraints.video) { + _this3._localMediaStreamLocallyGenerated = true; + return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) { + if (_this3._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + request.reply(480); + + _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); + + debugerror('emit "getusermediafailed" [error:%o]', error); + + _this3.emit('getusermediafailed', error); + + throw new Error('getUserMedia() failed'); + }); + } + }) // Attach MediaStream to RTCPeerconnection. + .then(function (stream) { + if (_this3._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this3._localMediaStream = stream; + + if (stream) { + stream.getTracks().forEach(function (track) { + _this3._connection.addTrack(track, stream); + }); + } + }) // Set remote description. + .then(function () { + if (_this3._late_sdp) { + return; + } + + var e = { + originator: 'remote', + type: 'offer', + sdp: request.body + }; + debug('emit "sdp"'); + + _this3.emit('sdp', e); + + var offer = new RTCSessionDescription({ + type: 'offer', + sdp: e.sdp + }); + _this3._connectionPromiseQueue = _this3._connectionPromiseQueue.then(function () { + return _this3._connection.setRemoteDescription(offer); + })["catch"](function (error) { + request.reply(488); + + _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); + + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this3.emit('peerconnection:setremotedescriptionfailed', error); + + throw new Error('peerconnection.setRemoteDescription() failed'); + }); + return _this3._connectionPromiseQueue; + }) // Create local description. + .then(function () { + if (_this3._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } // TODO: Is this event already useful? + + + _this3._connecting(request); + + if (!_this3._late_sdp) { + return _this3._createLocalDescription('answer', rtcAnswerConstraints)["catch"](function () { + request.reply(500); + throw new Error('_createLocalDescription() failed'); + }); + } else { + return _this3._createLocalDescription('offer', _this3._rtcOfferConstraints)["catch"](function () { + request.reply(500); + throw new Error('_createLocalDescription() failed'); + }); + } + }) // Send reply. + .then(function (desc) { + if (_this3._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this3._handleSessionTimersInIncomingRequest(request, extraHeaders); + + request.reply(200, null, extraHeaders, desc, function () { + _this3._status = C.STATUS_WAITING_FOR_ACK; + + _this3._setInvite2xxTimer(request, desc); + + _this3._setACKTimer(); + + _this3._accepted('local'); + }, function () { + _this3._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); + }); + })["catch"](function (error) { + if (_this3._status === C.STATUS_TERMINATED) { + return; + } + + debugerror(error); + }); + } + /** + * Terminate the call. + */ + + }, { + key: "terminate", + value: function terminate() { + var _this4 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + debug('terminate()'); + var cause = options.cause || JsSIP_C.causes.BYE; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var body = options.body; + var cancel_reason; + var status_code = options.status_code; + var reason_phrase = options.reason_phrase; // Check Session Status. + + if (this._status === C.STATUS_TERMINATED) { + throw new Exceptions.InvalidStateError(this._status); + } + + switch (this._status) { + // - UAC - + case C.STATUS_NULL: + case C.STATUS_INVITE_SENT: + case C.STATUS_1XX_RECEIVED: + debug('canceling session'); + + if (status_code && (status_code < 200 || status_code >= 700)) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } else if (status_code) { + reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; + cancel_reason = "SIP ;cause=".concat(status_code, " ;text=\"").concat(reason_phrase, "\""); + } // Check Session Status. + + + if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) { + this._is_canceled = true; + this._cancel_reason = cancel_reason; + } else if (this._status === C.STATUS_1XX_RECEIVED) { + this._request.cancel(cancel_reason); + } + + this._status = C.STATUS_CANCELED; + + this._failed('local', null, JsSIP_C.causes.CANCELED); + + break; + // - UAS - + + case C.STATUS_WAITING_FOR_ANSWER: + case C.STATUS_ANSWERED: + debug('rejecting session'); + status_code = status_code || 480; + + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } + + this._request.reply(status_code, reason_phrase, extraHeaders, body); + + this._failed('local', null, JsSIP_C.causes.REJECTED); + + break; + + case C.STATUS_WAITING_FOR_ACK: + case C.STATUS_CONFIRMED: + debug('terminating session'); + reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; + + if (status_code && (status_code < 200 || status_code >= 700)) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } else if (status_code) { + extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\"")); + } + /* RFC 3261 section 15 (Terminating a session): + * + * "...the callee's UA MUST NOT send a BYE on a confirmed dialog + * until it has received an ACK for its 2xx response or until the server + * transaction times out." + */ + + + if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) { + // Save the dialog for later restoration. + var dialog = this._dialog; // Send the BYE as soon as the ACK is received... + + this.receiveRequest = function (_ref) { + var method = _ref.method; + + if (method === JsSIP_C.ACK) { + _this4.sendRequest(JsSIP_C.BYE, { + extraHeaders: extraHeaders, + body: body + }); + + dialog.terminate(); + } + }; // .., or when the INVITE transaction times out + + + this._request.server_transaction.on('stateChanged', function () { + if (_this4._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) { + _this4.sendRequest(JsSIP_C.BYE, { + extraHeaders: extraHeaders, + body: body + }); + + dialog.terminate(); + } + }); + + this._ended('local', null, cause); // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-). + + + this._dialog = dialog; // Restore the dialog into 'ua' so the ACK can reach 'this' session. + + this._ua.newDialog(dialog); + } else { + this.sendRequest(JsSIP_C.BYE, { + extraHeaders: extraHeaders, + body: body + }); + + this._ended('local', null, cause); + } + + } + } + }, { + key: "sendDTMF", + value: function sendDTMF(tones) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + debug('sendDTMF() | tones: %s', tones); + var position = 0; + var duration = options.duration || null; + var interToneGap = options.interToneGap || null; + var transportType = options.transportType || JsSIP_C.DTMF_TRANSPORT.INFO; + + if (tones === undefined) { + throw new TypeError('Not enough arguments'); + } // Check Session Status. + + + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { + throw new Exceptions.InvalidStateError(this._status); + } // Check Transport type. + + + if (transportType !== JsSIP_C.DTMF_TRANSPORT.INFO && transportType !== JsSIP_C.DTMF_TRANSPORT.RFC2833) { + throw new TypeError("invalid transportType: ".concat(transportType)); + } // Convert to string. + + + if (typeof tones === 'number') { + tones = tones.toString(); + } // Check tones. + + + if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) { + throw new TypeError("Invalid tones: ".concat(tones)); + } // Check duration. + + + if (duration && !Utils.isDecimal(duration)) { + throw new TypeError("Invalid tone duration: ".concat(duration)); + } else if (!duration) { + duration = RTCSession_DTMF.C.DEFAULT_DURATION; + } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { + debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); + duration = RTCSession_DTMF.C.MIN_DURATION; + } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { + debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); + duration = RTCSession_DTMF.C.MAX_DURATION; + } else { + duration = Math.abs(duration); + } + + options.duration = duration; // Check interToneGap. + + if (interToneGap && !Utils.isDecimal(interToneGap)) { + throw new TypeError("Invalid interToneGap: ".concat(interToneGap)); + } else if (!interToneGap) { + interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP; + } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { + debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); + interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; + } else { + interToneGap = Math.abs(interToneGap); + } // RFC2833. Let RTCDTMFSender enqueue the DTMFs. + + + if (transportType === JsSIP_C.DTMF_TRANSPORT.RFC2833) { + // Send DTMF in current audio RTP stream. + var sender = this._getDTMFRTPSender(); + + if (sender) { + // Add remaining buffered tones. + tones = sender.toneBuffer + tones; // Insert tones. + + sender.insertDTMF(tones, duration, interToneGap); + } + + return; + } + + if (this._tones) { + // Tones are already queued, just add to the queue. + this._tones += tones; + return; + } + + this._tones = tones; // Send the first tone. + + _sendDTMF.call(this); + + function _sendDTMF() { + var _this5 = this; + + var timeout; + + if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) { + // Stop sending DTMF. + this._tones = null; + return; + } + + var tone = this._tones[position]; + position += 1; + + if (tone === ',') { + timeout = 2000; + } else { + // Send DTMF via SIP INFO messages. + var dtmf = new RTCSession_DTMF(this); + options.eventHandlers = { + onFailed: function onFailed() { + _this5._tones = null; + } + }; + dtmf.send(tone, options); + timeout = duration + interToneGap; + } // Set timeout for the next tone. + + + setTimeout(_sendDTMF.bind(this), timeout); + } + } + }, { + key: "sendInfo", + value: function sendInfo(contentType, body) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + debug('sendInfo()'); // Check Session Status. + + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { + throw new Exceptions.InvalidStateError(this._status); + } + + var info = new RTCSession_Info(this); + info.send(contentType, body, options); + } + /** + * Mute + */ + + }, { + key: "mute", + value: function mute() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { + audio: true, + video: false + }; + debug('mute()'); + var audioMuted = false, + videoMuted = false; + + if (this._audioMuted === false && options.audio) { + audioMuted = true; + this._audioMuted = true; + + this._toggleMuteAudio(true); + } + + if (this._videoMuted === false && options.video) { + videoMuted = true; + this._videoMuted = true; + + this._toggleMuteVideo(true); + } + + if (audioMuted === true || videoMuted === true) { + this._onmute({ + audio: audioMuted, + video: videoMuted + }); + } + } + /** + * Unmute + */ + + }, { + key: "unmute", + value: function unmute() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { + audio: true, + video: true + }; + debug('unmute()'); + var audioUnMuted = false, + videoUnMuted = false; + + if (this._audioMuted === true && options.audio) { + audioUnMuted = true; + this._audioMuted = false; + + if (this._localHold === false) { + this._toggleMuteAudio(false); + } + } + + if (this._videoMuted === true && options.video) { + videoUnMuted = true; + this._videoMuted = false; + + if (this._localHold === false) { + this._toggleMuteVideo(false); + } + } + + if (audioUnMuted === true || videoUnMuted === true) { + this._onunmute({ + audio: audioUnMuted, + video: videoUnMuted + }); + } + } + /** + * Hold + */ + + }, { + key: "hold", + value: function hold() { + var _this6 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var done = arguments.length > 1 ? arguments[1] : undefined; + debug('hold()'); + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (this._localHold === true) { + return false; + } + + if (!this._isReadyToReOffer()) { + return false; + } + + this._localHold = true; + + this._onhold('local'); + + var eventHandlers = { + succeeded: function succeeded() { + if (done) { + done(); + } + }, + failed: function failed() { + _this6.terminate({ + cause: JsSIP_C.causes.WEBRTC_ERROR, + status_code: 500, + reason_phrase: 'Hold Failed' + }); + } + }; + + if (options.useUpdate) { + this._sendUpdate({ + sdpOffer: true, + eventHandlers: eventHandlers, + extraHeaders: options.extraHeaders + }); + } else { + this._sendReinvite({ + eventHandlers: eventHandlers, + extraHeaders: options.extraHeaders + }); + } + + return true; + } + }, { + key: "unhold", + value: function unhold() { + var _this7 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var done = arguments.length > 1 ? arguments[1] : undefined; + debug('unhold()'); + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (this._localHold === false) { + return false; + } + + if (!this._isReadyToReOffer()) { + return false; + } + + this._localHold = false; + + this._onunhold('local'); + + var eventHandlers = { + succeeded: function succeeded() { + if (done) { + done(); + } + }, + failed: function failed() { + _this7.terminate({ + cause: JsSIP_C.causes.WEBRTC_ERROR, + status_code: 500, + reason_phrase: 'Unhold Failed' + }); + } + }; + + if (options.useUpdate) { + this._sendUpdate({ + sdpOffer: true, + eventHandlers: eventHandlers, + extraHeaders: options.extraHeaders + }); + } else { + this._sendReinvite({ + eventHandlers: eventHandlers, + extraHeaders: options.extraHeaders + }); + } + + return true; + } + }, { + key: "renegotiate", + value: function renegotiate() { + var _this8 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var done = arguments.length > 1 ? arguments[1] : undefined; + debug('renegotiate()'); + var rtcOfferConstraints = options.rtcOfferConstraints || null; + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (!this._isReadyToReOffer()) { + return false; + } + + var eventHandlers = { + succeeded: function succeeded() { + if (done) { + done(); + } + }, + failed: function failed() { + _this8.terminate({ + cause: JsSIP_C.causes.WEBRTC_ERROR, + status_code: 500, + reason_phrase: 'Media Renegotiation Failed' + }); + } + }; + + this._setLocalMediaStatus(); + + if (options.useUpdate) { + this._sendUpdate({ + sdpOffer: true, + eventHandlers: eventHandlers, + rtcOfferConstraints: rtcOfferConstraints, + extraHeaders: options.extraHeaders + }); + } else { + this._sendReinvite({ + eventHandlers: eventHandlers, + rtcOfferConstraints: rtcOfferConstraints, + extraHeaders: options.extraHeaders + }); + } + + return true; + } + /** + * Refer + */ + + }, { + key: "refer", + value: function refer(target, options) { + var _this9 = this; + + debug('refer()'); + var originalTarget = target; + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } // Check target validity. + + + target = this._ua.normalizeTarget(target); + + if (!target) { + throw new TypeError("Invalid target: ".concat(originalTarget)); + } + + var referSubscriber = new RTCSession_ReferSubscriber(this); + referSubscriber.sendRefer(target, options); // Store in the map. + + var id = referSubscriber.id; + this._referSubscribers[id] = referSubscriber; // Listen for ending events so we can remove it from the map. + + referSubscriber.on('requestFailed', function () { + delete _this9._referSubscribers[id]; + }); + referSubscriber.on('accepted', function () { + delete _this9._referSubscribers[id]; + }); + referSubscriber.on('failed', function () { + delete _this9._referSubscribers[id]; + }); + return referSubscriber; + } + /** + * Send a generic in-dialog Request + */ + + }, { + key: "sendRequest", + value: function sendRequest(method, options) { + debug('sendRequest()'); + return this._dialog.sendRequest(method, options); + } + /** + * In dialog Request Reception + */ + + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + var _this10 = this; + + debug('receiveRequest()'); + + if (request.method === JsSIP_C.CANCEL) { + /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL + * was in progress and that the UAC MAY continue with the session established by + * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the + * established session. So the CANCEL is processed only if the session is not yet + * established. + */ + + /* + * Terminate the whole session in case the user didn't accept (or yet send the answer) + * nor reject the request opening the session. + */ + if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) { + this._status = C.STATUS_CANCELED; + + this._request.reply(487); + + this._failed('remote', request, JsSIP_C.causes.CANCELED); + } + } else { + // Requests arriving here are in-dialog requests. + switch (request.method) { + case JsSIP_C.ACK: + if (this._status !== C.STATUS_WAITING_FOR_ACK) { + return; + } // Update signaling status. + + + this._status = C.STATUS_CONFIRMED; + clearTimeout(this._timers.ackTimer); + clearTimeout(this._timers.invite2xxTimer); + + if (this._late_sdp) { + if (!request.body) { + this.terminate({ + cause: JsSIP_C.causes.MISSING_SDP, + status_code: 400 + }); + break; + } + + var e = { + originator: 'remote', + type: 'answer', + sdp: request.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var answer = new RTCSessionDescription({ + type: 'answer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this10._connection.setRemoteDescription(answer); + }).then(function () { + if (!_this10._is_confirmed) { + _this10._confirmed('remote', request); + } + })["catch"](function (error) { + _this10.terminate({ + cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION, + status_code: 488 + }); + + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this10.emit('peerconnection:setremotedescriptionfailed', error); + }); + } else if (!this._is_confirmed) { + this._confirmed('remote', request); + } + + break; + + case JsSIP_C.BYE: + if (this._status === C.STATUS_CONFIRMED || this._status === C.STATUS_WAITING_FOR_ACK) { + request.reply(200); + + this._ended('remote', request, JsSIP_C.causes.BYE); + } else if (this._status === C.STATUS_INVITE_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER) { + request.reply(200); + + this._request.reply(487, 'BYE Received'); + + this._ended('remote', request, JsSIP_C.causes.BYE); + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.INVITE: + if (this._status === C.STATUS_CONFIRMED) { + if (request.hasHeader('replaces')) { + this._receiveReplaces(request); + } else { + this._receiveReinvite(request); + } + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.INFO: + if (this._status === C.STATUS_1XX_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED || this._status === C.STATUS_WAITING_FOR_ACK || this._status === C.STATUS_CONFIRMED) { + var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; + + if (contentType && contentType.match(/^application\/dtmf-relay/i)) { + new RTCSession_DTMF(this).init_incoming(request); + } else if (contentType !== undefined) { + new RTCSession_Info(this).init_incoming(request); + } else { + request.reply(415); + } + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.UPDATE: + if (this._status === C.STATUS_CONFIRMED) { + this._receiveUpdate(request); + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.REFER: + if (this._status === C.STATUS_CONFIRMED) { + this._receiveRefer(request); + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.NOTIFY: + if (this._status === C.STATUS_CONFIRMED) { + this._receiveNotify(request); + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + default: + request.reply(501); + } + } + } + /** + * Session Callbacks + */ + + }, { + key: "onTransportError", + value: function onTransportError() { + debugerror('onTransportError()'); + + if (this._status !== C.STATUS_TERMINATED) { + this.terminate({ + status_code: 500, + reason_phrase: JsSIP_C.causes.CONNECTION_ERROR, + cause: JsSIP_C.causes.CONNECTION_ERROR + }); + } + } + }, { + key: "onRequestTimeout", + value: function onRequestTimeout() { + debugerror('onRequestTimeout()'); + + if (this._status !== C.STATUS_TERMINATED) { + this.terminate({ + status_code: 408, + reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT, + cause: JsSIP_C.causes.REQUEST_TIMEOUT + }); + } + } + }, { + key: "onDialogError", + value: function onDialogError() { + debugerror('onDialogError()'); + + if (this._status !== C.STATUS_TERMINATED) { + this.terminate({ + status_code: 500, + reason_phrase: JsSIP_C.causes.DIALOG_ERROR, + cause: JsSIP_C.causes.DIALOG_ERROR + }); + } + } // Called from DTMF handler. + + }, { + key: "newDTMF", + value: function newDTMF(data) { + debug('newDTMF()'); + this.emit('newDTMF', data); + } // Called from Info handler. + + }, { + key: "newInfo", + value: function newInfo(data) { + debug('newInfo()'); + this.emit('newInfo', data); + } + /** + * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP. + */ + + }, { + key: "_isReadyToReOffer", + value: function _isReadyToReOffer() { + if (!this._rtcReady) { + debug('_isReadyToReOffer() | internal WebRTC status not ready'); + return false; + } // No established yet. + + + if (!this._dialog) { + debug('_isReadyToReOffer() | session not established yet'); + return false; + } // Another INVITE transaction is in progress. + + + if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { + debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); + return false; + } + + return true; + } + }, { + key: "_close", + value: function _close() { + debug('close()'); // Close local MediaStream if it was not given by the user. + + if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { + debug('close() | closing local MediaStream'); + Utils.closeMediaStream(this._localMediaStream); + } + + if (this._status === C.STATUS_TERMINATED) { + return; + } + + this._status = C.STATUS_TERMINATED; // Terminate RTC. + + if (this._connection) { + try { + this._connection.close(); + } catch (error) { + debugerror('close() | error closing the RTCPeerConnection: %o', error); + } + } // Terminate signaling. + // Clear SIP timers. + + + for (var timer in this._timers) { + if (Object.prototype.hasOwnProperty.call(this._timers, timer)) { + clearTimeout(this._timers[timer]); + } + } // Clear Session Timers. + + + clearTimeout(this._sessionTimers.timer); // Terminate confirmed dialog. + + if (this._dialog) { + this._dialog.terminate(); + + delete this._dialog; + } // Terminate early dialogs. + + + for (var dialog in this._earlyDialogs) { + if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) { + this._earlyDialogs[dialog].terminate(); + + delete this._earlyDialogs[dialog]; + } + } // Terminate REFER subscribers. + + + for (var subscriber in this._referSubscribers) { + if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) { + delete this._referSubscribers[subscriber]; + } + } + + this._ua.destroyRTCSession(this); + } + /** + * Private API. + */ + + /** + * RFC3261 13.3.1.4 + * Response retransmissions cannot be accomplished by transaction layer + * since it is destroyed when receiving the first 2xx answer + */ + + }, { + key: "_setInvite2xxTimer", + value: function _setInvite2xxTimer(request, body) { + var timeout = Timers.T1; + + function invite2xxRetransmission() { + if (this._status !== C.STATUS_WAITING_FOR_ACK) { + return; + } + + request.reply(200, null, ["Contact: ".concat(this._contact)], body); + + if (timeout < Timers.T2) { + timeout = timeout * 2; + + if (timeout > Timers.T2) { + timeout = Timers.T2; + } + } + + this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout); + } + + this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout); + } + /** + * RFC3261 14.2 + * If a UAS generates a 2xx response and never receives an ACK, + * it SHOULD generate a BYE to terminate the dialog. + */ + + }, { + key: "_setACKTimer", + value: function _setACKTimer() { + var _this11 = this; + + this._timers.ackTimer = setTimeout(function () { + if (_this11._status === C.STATUS_WAITING_FOR_ACK) { + debug('no ACK received, terminating the session'); + clearTimeout(_this11._timers.invite2xxTimer); + + _this11.sendRequest(JsSIP_C.BYE); + + _this11._ended('remote', null, JsSIP_C.causes.NO_ACK); + } + }, Timers.TIMER_H); + } + }, { + key: "_createRTCConnection", + value: function _createRTCConnection(pcConfig, rtcConstraints) { + var _this12 = this; + + this._connection = new RTCPeerConnection(pcConfig, rtcConstraints); + + this._connection.addEventListener('iceconnectionstatechange', function () { + var state = _this12._connection.iceConnectionState; // TODO: Do more with different states. + + if (state === 'failed') { + _this12.terminate({ + cause: JsSIP_C.causes.RTP_TIMEOUT, + status_code: 408, + reason_phrase: JsSIP_C.causes.RTP_TIMEOUT + }); + } + }); + + debug('emit "peerconnection"'); + this.emit('peerconnection', { + peerconnection: this._connection + }); + } + }, { + key: "_createLocalDescription", + value: function _createLocalDescription(type, constraints) { + var _this13 = this; + + debug('createLocalDescription()'); + if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\"")); + var connection = this._connection; + this._rtcReady = false; + return Promise.resolve() // Create Offer or Answer. + .then(function () { + if (type === 'offer') { + return connection.createOffer(constraints)["catch"](function (error) { + debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); + + _this13.emit('peerconnection:createofferfailed', error); + + return Promise.reject(error); + }); + } else { + return connection.createAnswer(constraints)["catch"](function (error) { + debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); + + _this13.emit('peerconnection:createanswerfailed', error); + + return Promise.reject(error); + }); + } + }) // Set local description. + .then(function (desc) { + return connection.setLocalDescription(desc)["catch"](function (error) { + _this13._rtcReady = true; + debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); + + _this13.emit('peerconnection:setlocaldescriptionfailed', error); + + return Promise.reject(error); + }); + }).then(function () { + // Resolve right away if 'pc.iceGatheringState' is 'complete'. + if (connection.iceGatheringState === 'complete' && (!constraints || !constraints.iceRestart)) { + _this13._rtcReady = true; + var e = { + originator: 'local', + type: type, + sdp: connection.localDescription.sdp + }; + debug('emit "sdp"'); + + _this13.emit('sdp', e); + + return Promise.resolve(e.sdp); + } // Add 'pc.onicencandidate' event handler to resolve on last candidate. + + + return new Promise(function (resolve) { + var finished = false; + var iceCandidateListener; + var iceGatheringStateListener; + + var ready = function ready() { + connection.removeEventListener('icecandidate', iceCandidateListener); + connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener); + finished = true; + _this13._rtcReady = true; + var e = { + originator: 'local', + type: type, + sdp: connection.localDescription.sdp + }; + debug('emit "sdp"'); + + _this13.emit('sdp', e); + + resolve(e.sdp); + }; + + connection.addEventListener('icecandidate', iceCandidateListener = function iceCandidateListener(event) { + var candidate = event.candidate; + + if (candidate) { + _this13.emit('icecandidate', { + candidate: candidate, + ready: ready + }); + } else if (!finished) { + ready(); + } + }); + connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = function iceGatheringStateListener() { + if (connection.iceGatheringState === 'complete' && !finished) { + ready(); + } + }); + }); + }); + } + /** + * Dialog Management + */ + + }, { + key: "_createDialog", + value: function _createDialog(message, type, early) { + var local_tag = type === 'UAS' ? message.to_tag : message.from_tag; + var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag; + var id = message.call_id + local_tag + remote_tag; + var early_dialog = this._earlyDialogs[id]; // Early Dialog. + + if (early) { + if (early_dialog) { + return true; + } else { + early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created. + + if (early_dialog.error) { + debug(early_dialog.error); + + this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); + + return false; + } else { + this._earlyDialogs[id] = early_dialog; + return true; + } + } + } // Confirmed Dialog. + else { + this._from_tag = message.from_tag; + this._to_tag = message.to_tag; // In case the dialog is in _early_ state, update it. + + if (early_dialog) { + early_dialog.update(message, type); + this._dialog = early_dialog; + delete this._earlyDialogs[id]; + return true; + } // Otherwise, create a _confirmed_ dialog. + + + var dialog = new Dialog(this, message, type); + + if (dialog.error) { + debug(dialog.error); + + this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); + + return false; + } else { + this._dialog = dialog; + return true; + } + } + } + /** + * In dialog INVITE Reception + */ + + }, { + key: "_receiveReinvite", + value: function _receiveReinvite(request) { + var _this14 = this; + + debug('receiveReinvite()'); + var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; + var data = { + request: request, + callback: undefined, + reject: reject.bind(this) + }; + var rejected = false; + + function reject() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + rejected = true; + var status_code = options.status_code || 403; + var reason_phrase = options.reason_phrase || ''; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + + if (this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } + + request.reply(status_code, reason_phrase, extraHeaders); + } // Emit 'reinvite'. + + + this.emit('reinvite', data); + + if (rejected) { + return; + } + + this._late_sdp = false; // Request without SDP. + + if (!request.body) { + this._late_sdp = true; + + if (this._remoteHold) { + this._remoteHold = false; + + this._onunhold('remote'); + } + + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this14._createLocalDescription('offer', _this14._rtcOfferConstraints); + }).then(function (sdp) { + sendAnswer.call(_this14, sdp); + })["catch"](function () { + request.reply(500); + }); + return; + } // Request with SDP. + + + if (contentType !== 'application/sdp') { + debug('invalid Content-Type'); + request.reply(415); + return; + } + + this._processInDialogSdpOffer(request) // Send answer. + .then(function (desc) { + if (_this14._status === C.STATUS_TERMINATED) { + return; + } + + sendAnswer.call(_this14, desc); + })["catch"](function (error) { + debugerror(error); + }); + + function sendAnswer(desc) { + var _this15 = this; + + var extraHeaders = ["Contact: ".concat(this._contact)]; + + this._handleSessionTimersInIncomingRequest(request, extraHeaders); + + if (this._late_sdp) { + desc = this._mangleOffer(desc); + } + + request.reply(200, null, extraHeaders, desc, function () { + _this15._status = C.STATUS_WAITING_FOR_ACK; + + _this15._setInvite2xxTimer(request, desc); + + _this15._setACKTimer(); + }); // If callback is given execute it. + + if (typeof data.callback === 'function') { + data.callback(); + } + } + } + /** + * In dialog UPDATE Reception + */ + + }, { + key: "_receiveUpdate", + value: function _receiveUpdate(request) { + var _this16 = this; + + debug('receiveUpdate()'); + var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; + var data = { + request: request, + callback: undefined, + reject: reject.bind(this) + }; + var rejected = false; + + function reject() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + rejected = true; + var status_code = options.status_code || 403; + var reason_phrase = options.reason_phrase || ''; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + + if (this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } + + request.reply(status_code, reason_phrase, extraHeaders); + } // Emit 'update'. + + + this.emit('update', data); + + if (rejected) { + return; + } + + if (!request.body) { + sendAnswer.call(this, null); + return; + } + + if (contentType !== 'application/sdp') { + debug('invalid Content-Type'); + request.reply(415); + return; + } + + this._processInDialogSdpOffer(request) // Send answer. + .then(function (desc) { + if (_this16._status === C.STATUS_TERMINATED) { + return; + } + + sendAnswer.call(_this16, desc); + })["catch"](function (error) { + debugerror(error); + }); + + function sendAnswer(desc) { + var extraHeaders = ["Contact: ".concat(this._contact)]; + + this._handleSessionTimersInIncomingRequest(request, extraHeaders); + + request.reply(200, null, extraHeaders, desc); // If callback is given execute it. + + if (typeof data.callback === 'function') { + data.callback(); + } + } + } + }, { + key: "_processInDialogSdpOffer", + value: function _processInDialogSdpOffer(request) { + var _this17 = this; + + debug('_processInDialogSdpOffer()'); + var sdp = request.parseSDP(); + var hold = false; + + var _iterator4 = _createForOfIteratorHelper(sdp.media), + _step4; + + try { + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + var m = _step4.value; + + if (holdMediaTypes.indexOf(m.type) === -1) { + continue; + } + + var direction = m.direction || sdp.direction || 'sendrecv'; + + if (direction === 'sendonly' || direction === 'inactive') { + hold = true; + } // If at least one of the streams is active don't emit 'hold'. + else { + hold = false; + break; + } + } + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); + } + + var e = { + originator: 'remote', + type: 'offer', + sdp: request.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var offer = new RTCSessionDescription({ + type: 'offer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue // Set remote description. + .then(function () { + if (_this17._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + return _this17._connection.setRemoteDescription(offer)["catch"](function (error) { + request.reply(488); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this17.emit('peerconnection:setremotedescriptionfailed', error); + + throw error; + }); + }).then(function () { + if (_this17._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + if (_this17._remoteHold === true && hold === false) { + _this17._remoteHold = false; + + _this17._onunhold('remote'); + } else if (_this17._remoteHold === false && hold === true) { + _this17._remoteHold = true; + + _this17._onhold('remote'); + } + }) // Create local description. + .then(function () { + if (_this17._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) { + request.reply(500); + debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); + throw error; + }); + })["catch"](function (error) { + debugerror('_processInDialogSdpOffer() failed [error: %o]', error); + }); + return this._connectionPromiseQueue; + } + /** + * In dialog Refer Reception + */ + + }, { + key: "_receiveRefer", + value: function _receiveRefer(request) { + var _this18 = this; + + debug('receiveRefer()'); + + if (!request.refer_to) { + debug('no Refer-To header field present in REFER'); + request.reply(400); + return; + } + + if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { + debug('Refer-To header field points to a non-SIP URI scheme'); + request.reply(416); + return; + } // Reply before the transaction timer expires. + + + request.reply(202); + var notifier = new RTCSession_ReferNotifier(this, request.cseq); + debug('emit "refer"'); // Emit 'refer'. + + this.emit('refer', { + request: request, + accept: function accept(initCallback, options) { + _accept.call(_this18, initCallback, options); + }, + reject: function reject() { + _reject.call(_this18); + } + }); + + function _accept(initCallback) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + initCallback = typeof initCallback === 'function' ? initCallback : null; + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + var session = new RTCSession(this._ua); + session.on('progress', function (_ref2) { + var response = _ref2.response; + notifier.notify(response.status_code, response.reason_phrase); + }); + session.on('accepted', function (_ref3) { + var response = _ref3.response; + notifier.notify(response.status_code, response.reason_phrase); + }); + session.on('_failed', function (_ref4) { + var message = _ref4.message, + cause = _ref4.cause; + + if (message) { + notifier.notify(message.status_code, message.reason_phrase); + } else { + notifier.notify(487, cause); + } + }); // Consider the Replaces header present in the Refer-To URI. + + if (request.refer_to.uri.hasHeader('replaces')) { + var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces')); + options.extraHeaders = Utils.cloneArray(options.extraHeaders); + options.extraHeaders.push("Replaces: ".concat(replaces)); + } + + session.connect(request.refer_to.uri.toAor(), options, initCallback); + } + + function _reject() { + notifier.notify(603); + } + } + /** + * In dialog Notify Reception + */ + + }, { + key: "_receiveNotify", + value: function _receiveNotify(request) { + debug('receiveNotify()'); + + if (!request.event) { + request.reply(400); + } + + switch (request.event.event) { + case 'refer': + { + var id; + var referSubscriber; + + if (request.event.params && request.event.params.id) { + id = request.event.params.id; + referSubscriber = this._referSubscribers[id]; + } else if (Object.keys(this._referSubscribers).length === 1) { + referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]]; + } else { + request.reply(400, 'Missing event id parameter'); + return; + } + + if (!referSubscriber) { + request.reply(481, 'Subscription does not exist'); + return; + } + + referSubscriber.receiveNotify(request); + request.reply(200); + break; + } + + default: + { + request.reply(489); + } + } + } + /** + * INVITE with Replaces Reception + */ + + }, { + key: "_receiveReplaces", + value: function _receiveReplaces(request) { + var _this20 = this; + + debug('receiveReplaces()'); + + function _accept2(initCallback) { + var _this19 = this; + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + var session = new RTCSession(this._ua); // Terminate the current session when the new one is confirmed. + + session.on('confirmed', function () { + _this19.terminate(); + }); + session.init_incoming(request, initCallback); + } + + function _reject2() { + debug('Replaced INVITE rejected by the user'); + request.reply(486); + } // Emit 'replace'. + + + this.emit('replaces', { + request: request, + accept: function accept(initCallback) { + _accept2.call(_this20, initCallback); + }, + reject: function reject() { + _reject2.call(_this20); + } + }); + } + /** + * Initial Request Sender + */ + + }, { + key: "_sendInitialRequest", + value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) { + var _this21 = this; + + var request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout: function onRequestTimeout() { + _this21.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this21.onTransportError(); + }, + // Update the request on authentication. + onAuthenticated: function onAuthenticated(request) { + _this21._request = request; + }, + onReceiveResponse: function onReceiveResponse(response) { + _this21._receiveInviteResponse(response); + } + }); // This Promise is resolved within the next iteration, so the app has now + // a chance to set events such as 'peerconnection' and 'connecting'. + + Promise.resolve() // Get a stream if required. + .then(function () { + // A stream is given, let the app set events such as 'peerconnection' and 'connecting'. + if (mediaStream) { + return mediaStream; + } // Request for user media access. + else if (mediaConstraints.audio || mediaConstraints.video) { + _this21._localMediaStreamLocallyGenerated = true; + return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) { + if (_this21._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); + + debugerror('emit "getusermediafailed" [error:%o]', error); + + _this21.emit('getusermediafailed', error); + + throw error; + }); + } + }).then(function (stream) { + if (_this21._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this21._localMediaStream = stream; + + if (stream) { + stream.getTracks().forEach(function (track) { + _this21._connection.addTrack(track, stream); + }); + } // TODO: should this be triggered here? + + + _this21._connecting(_this21._request); + + return _this21._createLocalDescription('offer', rtcOfferConstraints)["catch"](function (error) { + _this21._failed('local', null, JsSIP_C.causes.WEBRTC_ERROR); + + throw error; + }); + }).then(function (desc) { + if (_this21._is_canceled || _this21._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this21._request.body = desc; + _this21._status = C.STATUS_INVITE_SENT; + debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. + + _this21.emit('sending', { + request: _this21._request + }); + + request_sender.send(); + })["catch"](function (error) { + if (_this21._status === C.STATUS_TERMINATED) { + return; + } + + debugerror(error); + }); + } + /** + * Get DTMF RTCRtpSender. + */ + + }, { + key: "_getDTMFRTPSender", + value: function _getDTMFRTPSender() { + var sender = this._connection.getSenders().find(function (rtpSender) { + return rtpSender.track && rtpSender.track.kind === 'audio'; + }); + + if (!(sender && sender.dtmf)) { + debugerror('sendDTMF() | no local audio track to send DTMF with'); + return; + } + + return sender.dtmf; + } + /** + * Reception of Response for Initial INVITE + */ + + }, { + key: "_receiveInviteResponse", + value: function _receiveInviteResponse(response) { + var _this22 = this; + + debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. + + if (this._dialog && response.status_code >= 200 && response.status_code <= 299) { + /* + * If it is a retransmission from the endpoint that established + * the dialog, send an ACK + */ + if (this._dialog.id.call_id === response.call_id && this._dialog.id.local_tag === response.from_tag && this._dialog.id.remote_tag === response.to_tag) { + this.sendRequest(JsSIP_C.ACK); + return; + } // If not, send an ACK and terminate. + else { + var dialog = new Dialog(this, response, 'UAC'); + + if (dialog.error !== undefined) { + debug(dialog.error); + return; + } + + this.sendRequest(JsSIP_C.ACK); + this.sendRequest(JsSIP_C.BYE); + return; + } + } // Proceed to cancellation if the user requested. + + + if (this._is_canceled) { + if (response.status_code >= 100 && response.status_code < 200) { + this._request.cancel(this._cancel_reason); + } else if (response.status_code >= 200 && response.status_code < 299) { + this._acceptAndTerminate(response); + } + + return; + } + + if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) { + return; + } + + switch (true) { + case /^100$/.test(response.status_code): + this._status = C.STATUS_1XX_RECEIVED; + break; + + case /^1[0-9]{2}$/.test(response.status_code): + { + // Do nothing with 1xx responses without To tag. + if (!response.to_tag) { + debug('1xx response received without to tag'); + break; + } // Create Early Dialog if 1XX comes with contact. + + + if (response.hasHeader('contact')) { + // An error on dialog creation will fire 'failed' event. + if (!this._createDialog(response, 'UAC', true)) { + break; + } + } + + this._status = C.STATUS_1XX_RECEIVED; + + if (!response.body) { + this._progress('remote', response); + + break; + } + + var e = { + originator: 'remote', + type: 'answer', + sdp: response.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var answer = new RTCSessionDescription({ + type: 'answer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this22._connection.setRemoteDescription(answer); + }).then(function () { + return _this22._progress('remote', response); + })["catch"](function (error) { + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this22.emit('peerconnection:setremotedescriptionfailed', error); + }); + break; + } + + case /^2[0-9]{2}$/.test(response.status_code): + { + this._status = C.STATUS_CONFIRMED; + + if (!response.body) { + this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP); + + this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); + + break; + } // An error on dialog creation will fire 'failed' event. + + + if (!this._createDialog(response, 'UAC')) { + break; + } + + var _e = { + originator: 'remote', + type: 'answer', + sdp: response.body + }; + debug('emit "sdp"'); + this.emit('sdp', _e); + + var _answer = new RTCSessionDescription({ + type: 'answer', + sdp: _e.sdp + }); + + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + // Be ready for 200 with SDP after a 180/183 with SDP. + // We created a SDP 'answer' for it, so check the current signaling state. + if (_this22._connection.signalingState === 'stable') { + return _this22._connection.createOffer(_this22._rtcOfferConstraints).then(function (offer) { + return _this22._connection.setLocalDescription(offer); + })["catch"](function (error) { + _this22._acceptAndTerminate(response, 500, error.toString()); + + _this22._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR); + }); + } + }).then(function () { + _this22._connection.setRemoteDescription(_answer).then(function () { + // Handle Session Timers. + _this22._handleSessionTimersInIncomingResponse(response); + + _this22._accepted('remote', response); + + _this22.sendRequest(JsSIP_C.ACK); + + _this22._confirmed('local', null); + })["catch"](function (error) { + _this22._acceptAndTerminate(response, 488, 'Not Acceptable Here'); + + _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); + + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this22.emit('peerconnection:setremotedescriptionfailed', error); + }); + }); + break; + } + + default: + { + var cause = Utils.sipErrorCause(response.status_code); + + this._failed('remote', response, cause); + } + } + } + /** + * Send Re-INVITE + */ + + }, { + key: "_sendReinvite", + value: function _sendReinvite() { + var _this23 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + debug('sendReinvite()'); + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; + var succeeded = false; + extraHeaders.push("Contact: ".concat(this._contact)); + extraHeaders.push('Content-Type: application/sdp'); // Session Timers. + + if (this._sessionTimers.running) { + extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas')); + } + + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this23._createLocalDescription('offer', rtcOfferConstraints); + }).then(function (sdp) { + sdp = _this23._mangleOffer(sdp); + var e = { + originator: 'local', + type: 'offer', + sdp: sdp + }; + debug('emit "sdp"'); + + _this23.emit('sdp', e); + + _this23.sendRequest(JsSIP_C.INVITE, { + extraHeaders: extraHeaders, + body: sdp, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + onSucceeded.call(_this23, response); + succeeded = true; + }, + onErrorResponse: function onErrorResponse(response) { + onFailed.call(_this23, response); + }, + onTransportError: function onTransportError() { + _this23.onTransportError(); // Do nothing because session ends. + + }, + onRequestTimeout: function onRequestTimeout() { + _this23.onRequestTimeout(); // Do nothing because session ends. + + }, + onDialogError: function onDialogError() { + _this23.onDialogError(); // Do nothing because session ends. + + } + } + }); + })["catch"](function () { + onFailed(); + }); + + function onSucceeded(response) { + var _this24 = this; + + if (this._status === C.STATUS_TERMINATED) { + return; + } + + this.sendRequest(JsSIP_C.ACK); // If it is a 2XX retransmission exit now. + + if (succeeded) { + return; + } // Handle Session Timers. + + + this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer. + + + if (!response.body) { + onFailed.call(this); + return; + } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') { + onFailed.call(this); + return; + } + + var e = { + originator: 'remote', + type: 'answer', + sdp: response.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var answer = new RTCSessionDescription({ + type: 'answer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this24._connection.setRemoteDescription(answer); + }).then(function () { + if (eventHandlers.succeeded) { + eventHandlers.succeeded(response); + } + })["catch"](function (error) { + onFailed.call(_this24); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this24.emit('peerconnection:setremotedescriptionfailed', error); + }); + } + + function onFailed(response) { + if (eventHandlers.failed) { + eventHandlers.failed(response); + } + } + } + /** + * Send UPDATE + */ + + }, { + key: "_sendUpdate", + value: function _sendUpdate() { + var _this25 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + debug('sendUpdate()'); + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; + var sdpOffer = options.sdpOffer || false; + var succeeded = false; + extraHeaders.push("Contact: ".concat(this._contact)); // Session Timers. + + if (this._sessionTimers.running) { + extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas')); + } + + if (sdpOffer) { + extraHeaders.push('Content-Type: application/sdp'); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this25._createLocalDescription('offer', rtcOfferConstraints); + }).then(function (sdp) { + sdp = _this25._mangleOffer(sdp); + var e = { + originator: 'local', + type: 'offer', + sdp: sdp + }; + debug('emit "sdp"'); + + _this25.emit('sdp', e); + + _this25.sendRequest(JsSIP_C.UPDATE, { + extraHeaders: extraHeaders, + body: sdp, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + onSucceeded.call(_this25, response); + succeeded = true; + }, + onErrorResponse: function onErrorResponse(response) { + onFailed.call(_this25, response); + }, + onTransportError: function onTransportError() { + _this25.onTransportError(); // Do nothing because session ends. + + }, + onRequestTimeout: function onRequestTimeout() { + _this25.onRequestTimeout(); // Do nothing because session ends. + + }, + onDialogError: function onDialogError() { + _this25.onDialogError(); // Do nothing because session ends. + + } + } + }); + })["catch"](function () { + onFailed.call(_this25); + }); + } // No SDP. + else { + this.sendRequest(JsSIP_C.UPDATE, { + extraHeaders: extraHeaders, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + onSucceeded.call(_this25, response); + }, + onErrorResponse: function onErrorResponse(response) { + onFailed.call(_this25, response); + }, + onTransportError: function onTransportError() { + _this25.onTransportError(); // Do nothing because session ends. + + }, + onRequestTimeout: function onRequestTimeout() { + _this25.onRequestTimeout(); // Do nothing because session ends. + + }, + onDialogError: function onDialogError() { + _this25.onDialogError(); // Do nothing because session ends. + + } + } + }); + } + + function onSucceeded(response) { + var _this26 = this; + + if (this._status === C.STATUS_TERMINATED) { + return; + } // If it is a 2XX retransmission exit now. + + + if (succeeded) { + return; + } // Handle Session Timers. + + + this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer. + + + if (sdpOffer) { + if (!response.body) { + onFailed.call(this); + return; + } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') { + onFailed.call(this); + return; + } + + var e = { + originator: 'remote', + type: 'answer', + sdp: response.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var answer = new RTCSessionDescription({ + type: 'answer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this26._connection.setRemoteDescription(answer); + }).then(function () { + if (eventHandlers.succeeded) { + eventHandlers.succeeded(response); + } + })["catch"](function (error) { + onFailed.call(_this26); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this26.emit('peerconnection:setremotedescriptionfailed', error); + }); + } // No SDP answer. + else if (eventHandlers.succeeded) { + eventHandlers.succeeded(response); + } + } + + function onFailed(response) { + if (eventHandlers.failed) { + eventHandlers.failed(response); + } + } + } + }, { + key: "_acceptAndTerminate", + value: function _acceptAndTerminate(response, status_code, reason_phrase) { + debug('acceptAndTerminate()'); + var extraHeaders = []; + + if (status_code) { + reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; + extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\"")); + } // An error on dialog creation will fire 'failed' event. + + + if (this._dialog || this._createDialog(response, 'UAC')) { + this.sendRequest(JsSIP_C.ACK); + this.sendRequest(JsSIP_C.BYE, { + extraHeaders: extraHeaders + }); + } // Update session status. + + + this._status = C.STATUS_TERMINATED; + } + /** + * Correctly set the SDP direction attributes if the call is on local hold + */ + + }, { + key: "_mangleOffer", + value: function _mangleOffer(sdp) { + if (!this._localHold && !this._remoteHold) { + return sdp; + } + + sdp = sdp_transform.parse(sdp); // Local hold. + + if (this._localHold && !this._remoteHold) { + debug('mangleOffer() | me on hold, mangling offer'); + + var _iterator5 = _createForOfIteratorHelper(sdp.media), + _step5; + + try { + for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { + var m = _step5.value; + + if (holdMediaTypes.indexOf(m.type) === -1) { + continue; + } + + if (!m.direction) { + m.direction = 'sendonly'; + } else if (m.direction === 'sendrecv') { + m.direction = 'sendonly'; + } else if (m.direction === 'recvonly') { + m.direction = 'inactive'; + } + } + } catch (err) { + _iterator5.e(err); + } finally { + _iterator5.f(); + } + } // Local and remote hold. + else if (this._localHold && this._remoteHold) { + debug('mangleOffer() | both on hold, mangling offer'); + + var _iterator6 = _createForOfIteratorHelper(sdp.media), + _step6; + + try { + for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { + var _m = _step6.value; + + if (holdMediaTypes.indexOf(_m.type) === -1) { + continue; + } + + _m.direction = 'inactive'; + } + } catch (err) { + _iterator6.e(err); + } finally { + _iterator6.f(); + } + } // Remote hold. + else if (this._remoteHold) { + debug('mangleOffer() | remote on hold, mangling offer'); + + var _iterator7 = _createForOfIteratorHelper(sdp.media), + _step7; + + try { + for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { + var _m2 = _step7.value; + + if (holdMediaTypes.indexOf(_m2.type) === -1) { + continue; + } + + if (!_m2.direction) { + _m2.direction = 'recvonly'; + } else if (_m2.direction === 'sendrecv') { + _m2.direction = 'recvonly'; + } else if (_m2.direction === 'recvonly') { + _m2.direction = 'inactive'; + } + } + } catch (err) { + _iterator7.e(err); + } finally { + _iterator7.f(); + } + } + + return sdp_transform.write(sdp); + } + }, { + key: "_setLocalMediaStatus", + value: function _setLocalMediaStatus() { + var enableAudio = true, + enableVideo = true; + + if (this._localHold || this._remoteHold) { + enableAudio = false; + enableVideo = false; + } + + if (this._audioMuted) { + enableAudio = false; + } + + if (this._videoMuted) { + enableVideo = false; + } + + this._toggleMuteAudio(!enableAudio); + + this._toggleMuteVideo(!enableVideo); + } + /** + * Handle SessionTimers for an incoming INVITE or UPDATE. + * @param {IncomingRequest} request + * @param {Array} responseExtraHeaders Extra headers for the 200 response. + */ + + }, { + key: "_handleSessionTimersInIncomingRequest", + value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) { + if (!this._sessionTimers.enabled) { + return; + } + + var session_expires_refresher; + + if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) { + this._sessionTimers.currentExpires = request.session_expires; + session_expires_refresher = request.session_expires_refresher || 'uas'; + } else { + this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires; + session_expires_refresher = 'uas'; + } + + responseExtraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(session_expires_refresher)); + this._sessionTimers.refresher = session_expires_refresher === 'uas'; + + this._runSessionTimer(); + } + /** + * Handle SessionTimers for an incoming response to INVITE or UPDATE. + * @param {IncomingResponse} response + */ + + }, { + key: "_handleSessionTimersInIncomingResponse", + value: function _handleSessionTimersInIncomingResponse(response) { + if (!this._sessionTimers.enabled) { + return; + } + + var session_expires_refresher; + + if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) { + this._sessionTimers.currentExpires = response.session_expires; + session_expires_refresher = response.session_expires_refresher || 'uac'; + } else { + this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires; + session_expires_refresher = 'uac'; + } + + this._sessionTimers.refresher = session_expires_refresher === 'uac'; + + this._runSessionTimer(); + } + }, { + key: "_runSessionTimer", + value: function _runSessionTimer() { + var _this27 = this; + + var expires = this._sessionTimers.currentExpires; + this._sessionTimers.running = true; + clearTimeout(this._sessionTimers.timer); // I'm the refresher. + + if (this._sessionTimers.refresher) { + this._sessionTimers.timer = setTimeout(function () { + if (_this27._status === C.STATUS_TERMINATED) { + return; + } + + debug('runSessionTimer() | sending session refresh request'); + + if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { + _this27._sendUpdate(); + } else { + _this27._sendReinvite(); + } + }, expires * 500); // Half the given interval (as the RFC states). + } // I'm not the refresher. + else { + this._sessionTimers.timer = setTimeout(function () { + if (_this27._status === C.STATUS_TERMINATED) { + return; + } + + debugerror('runSessionTimer() | timer expired, terminating the session'); + + _this27.terminate({ + cause: JsSIP_C.causes.REQUEST_TIMEOUT, + status_code: 408, + reason_phrase: 'Session Timer Expired' + }); + }, expires * 1100); + } + } + }, { + key: "_toggleMuteAudio", + value: function _toggleMuteAudio(mute) { + var senders = this._connection.getSenders().filter(function (sender) { + return sender.track && sender.track.kind === 'audio'; + }); + + var _iterator8 = _createForOfIteratorHelper(senders), + _step8; + + try { + for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { + var sender = _step8.value; + sender.track.enabled = !mute; + } + } catch (err) { + _iterator8.e(err); + } finally { + _iterator8.f(); + } + } + }, { + key: "_toggleMuteVideo", + value: function _toggleMuteVideo(mute) { + var senders = this._connection.getSenders().filter(function (sender) { + return sender.track && sender.track.kind === 'video'; + }); + + var _iterator9 = _createForOfIteratorHelper(senders), + _step9; + + try { + for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { + var sender = _step9.value; + sender.track.enabled = !mute; + } + } catch (err) { + _iterator9.e(err); + } finally { + _iterator9.f(); + } + } + }, { + key: "_newRTCSession", + value: function _newRTCSession(originator, request) { + debug('newRTCSession()'); + + this._ua.newRTCSession(this, { + originator: originator, + session: this, + request: request + }); + } + }, { + key: "_connecting", + value: function _connecting(request) { + debug('session connecting'); + debug('emit "connecting"'); + this.emit('connecting', { + request: request + }); + } + }, { + key: "_progress", + value: function _progress(originator, response) { + debug('session progress'); + debug('emit "progress"'); + this.emit('progress', { + originator: originator, + response: response || null + }); + } + }, { + key: "_accepted", + value: function _accepted(originator, message) { + debug('session accepted'); + this._start_time = new Date(); + debug('emit "accepted"'); + this.emit('accepted', { + originator: originator, + response: message || null + }); + } + }, { + key: "_confirmed", + value: function _confirmed(originator, ack) { + debug('session confirmed'); + this._is_confirmed = true; + debug('emit "confirmed"'); + this.emit('confirmed', { + originator: originator, + ack: ack || null + }); + } + }, { + key: "_ended", + value: function _ended(originator, message, cause) { + debug('session ended'); + this._end_time = new Date(); + + this._close(); + + debug('emit "ended"'); + this.emit('ended', { + originator: originator, + message: message || null, + cause: cause + }); + } + }, { + key: "_failed", + value: function _failed(originator, message, cause) { + debug('session failed'); // Emit private '_failed' event first. + + debug('emit "_failed"'); + this.emit('_failed', { + originator: originator, + message: message || null, + cause: cause + }); + + this._close(); + + debug('emit "failed"'); + this.emit('failed', { + originator: originator, + message: message || null, + cause: cause + }); + } + }, { + key: "_onhold", + value: function _onhold(originator) { + debug('session onhold'); + + this._setLocalMediaStatus(); + + debug('emit "hold"'); + this.emit('hold', { + originator: originator + }); + } + }, { + key: "_onunhold", + value: function _onunhold(originator) { + debug('session onunhold'); + + this._setLocalMediaStatus(); + + debug('emit "unhold"'); + this.emit('unhold', { + originator: originator + }); + } + }, { + key: "_onmute", + value: function _onmute(_ref5) { + var audio = _ref5.audio, + video = _ref5.video; + debug('session onmute'); + + this._setLocalMediaStatus(); + + debug('emit "muted"'); + this.emit('muted', { + audio: audio, + video: video + }); + } + }, { + key: "_onunmute", + value: function _onunmute(_ref6) { + var audio = _ref6.audio, + video = _ref6.video; + debug('session onunmute'); + + this._setLocalMediaStatus(); + + debug('emit "unmuted"'); + this.emit('unmuted', { + audio: audio, + video: video + }); + } + }], [{ + key: "C", + get: + /** + * Expose C object. + */ + function get() { + return C; + } + }]); + + return RTCSession; +}(EventEmitter); +},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,"debug":32,"events":31,"sdp-transform":37}],14:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('../Constants'); + +var Exceptions = require('../Exceptions'); + +var Utils = require('../Utils'); + +var debug = require('debug')('JsSIP:RTCSession:DTMF'); + +var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); + +debugerror.log = console.warn.bind(console); +var C = { + MIN_DURATION: 70, + MAX_DURATION: 6000, + DEFAULT_DURATION: 100, + MIN_INTER_TONE_GAP: 50, + DEFAULT_INTER_TONE_GAP: 500 +}; + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(DTMF, _EventEmitter); + + var _super = _createSuper(DTMF); + + function DTMF(session) { + var _this; + + _classCallCheck(this, DTMF); + + _this = _super.call(this); + _this._session = session; + _this._direction = null; + _this._tone = null; + _this._duration = null; + _this._request = null; + return _this; + } + + _createClass(DTMF, [{ + key: "tone", + get: function get() { + return this._tone; + } + }, { + key: "duration", + get: function get() { + return this._duration; + } + }, { + key: "send", + value: function send(tone) { + var _this2 = this; + + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if (tone === undefined) { + throw new TypeError('Not enough arguments'); + } + + this._direction = 'outgoing'; // Check RTCSession Status. + + if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) { + throw new Exceptions.InvalidStateError(this._session.status); + } + + var extraHeaders = Utils.cloneArray(options.extraHeaders); + this.eventHandlers = Utils.cloneObject(options.eventHandlers); // Check tone type. + + if (typeof tone === 'string') { + tone = tone.toUpperCase(); + } else if (typeof tone === 'number') { + tone = tone.toString(); + } else { + throw new TypeError("Invalid tone: ".concat(tone)); + } // Check tone value. + + + if (!tone.match(/^[0-9A-DR#*]$/)) { + throw new TypeError("Invalid tone: ".concat(tone)); + } else { + this._tone = tone; + } // Duration is checked/corrected in RTCSession. + + + this._duration = options.duration; + extraHeaders.push('Content-Type: application/dtmf-relay'); + var body = "Signal=".concat(this._tone, "\r\n"); + body += "Duration=".concat(this._duration); + + this._session.newDTMF({ + originator: 'local', + dtmf: this, + request: this._request + }); + + this._session.sendRequest(JsSIP_C.INFO, { + extraHeaders: extraHeaders, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + _this2.emit('succeeded', { + originator: 'remote', + response: response + }); + }, + onErrorResponse: function onErrorResponse(response) { + if (_this2.eventHandlers.onFailed) { + _this2.eventHandlers.onFailed(); + } + + _this2.emit('failed', { + originator: 'remote', + response: response + }); + }, + onRequestTimeout: function onRequestTimeout() { + _this2._session.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this2._session.onTransportError(); + }, + onDialogError: function onDialogError() { + _this2._session.onDialogError(); + } + }, + body: body + }); + } + }, { + key: "init_incoming", + value: function init_incoming(request) { + var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/; + var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/; + this._direction = 'incoming'; + this._request = request; + request.reply(200); + + if (request.body) { + var body = request.body.split('\n'); + + if (body.length >= 1) { + if (reg_tone.test(body[0])) { + this._tone = body[0].replace(reg_tone, '$2'); + } + } + + if (body.length >= 2) { + if (reg_duration.test(body[1])) { + this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10); + } + } + } + + if (!this._duration) { + this._duration = C.DEFAULT_DURATION; + } + + if (!this._tone) { + debug('invalid INFO DTMF received, discarded'); + } else { + this._session.newDTMF({ + originator: 'remote', + dtmf: this, + request: request + }); + } + } + }]); + + return DTMF; +}(EventEmitter); +/** + * Expose C object. + */ + + +module.exports.C = C; +},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],15:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); + +debugerror.log = console.warn.bind(console); + +var JsSIP_C = require('../Constants'); + +var Exceptions = require('../Exceptions'); + +var Utils = require('../Utils'); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Info, _EventEmitter); + + var _super = _createSuper(Info); + + function Info(session) { + var _this; + + _classCallCheck(this, Info); + + _this = _super.call(this); + _this._session = session; + _this._direction = null; + _this._contentType = null; + _this._body = null; + return _this; + } + + _createClass(Info, [{ + key: "contentType", + get: function get() { + return this._contentType; + } + }, { + key: "body", + get: function get() { + return this._body; + } + }, { + key: "send", + value: function send(contentType, body) { + var _this2 = this; + + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + this._direction = 'outgoing'; + + if (contentType === undefined) { + throw new TypeError('Not enough arguments'); + } // Check RTCSession Status. + + + if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) { + throw new Exceptions.InvalidStateError(this._session.status); + } + + this._contentType = contentType; + this._body = body; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + extraHeaders.push("Content-Type: ".concat(contentType)); + + this._session.newInfo({ + originator: 'local', + info: this, + request: this.request + }); + + this._session.sendRequest(JsSIP_C.INFO, { + extraHeaders: extraHeaders, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + _this2.emit('succeeded', { + originator: 'remote', + response: response + }); + }, + onErrorResponse: function onErrorResponse(response) { + _this2.emit('failed', { + originator: 'remote', + response: response + }); + }, + onTransportError: function onTransportError() { + _this2._session.onTransportError(); + }, + onRequestTimeout: function onRequestTimeout() { + _this2._session.onRequestTimeout(); + }, + onDialogError: function onDialogError() { + _this2._session.onDialogError(); + } + }, + body: body + }); + } + }, { + key: "init_incoming", + value: function init_incoming(request) { + this._direction = 'incoming'; + this.request = request; + request.reply(200); + this._contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; + this._body = request.body; + + this._session.newInfo({ + originator: 'remote', + info: this, + request: request + }); + } + }]); + + return Info; +}(EventEmitter); +},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],16:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var JsSIP_C = require('../Constants'); + +var debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); + +var C = { + event_type: 'refer', + body_type: 'message/sipfrag;version=2.0', + expires: 300 +}; + +module.exports = /*#__PURE__*/function () { + function ReferNotifier(session, id, expires) { + _classCallCheck(this, ReferNotifier); + + this._session = session; + this._id = id; + this._expires = expires || C.expires; + this._active = true; // The creation of a Notifier results in an immediate NOTIFY. + + this.notify(100); + } + + _createClass(ReferNotifier, [{ + key: "notify", + value: function notify(code, reason) { + debug('notify()'); + + if (this._active === false) { + return; + } + + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + var state; + + if (code >= 200) { + state = 'terminated;reason=noresource'; + } else { + state = "active;expires=".concat(this._expires); + } // Put this in a try/catch block. + + + this._session.sendRequest(JsSIP_C.NOTIFY, { + extraHeaders: ["Event: ".concat(C.event_type, ";id=").concat(this._id), "Subscription-State: ".concat(state), "Content-Type: ".concat(C.body_type)], + body: "SIP/2.0 ".concat(code, " ").concat(reason), + eventHandlers: { + // If a negative response is received, subscription is canceled. + onErrorResponse: function onErrorResponse() { + this._active = false; + } + } + }); + } + }]); + + return ReferNotifier; +}(); +},{"../Constants":2,"debug":32}],17:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('../Constants'); + +var Grammar = require('../Grammar'); + +var Utils = require('../Utils'); + +var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(ReferSubscriber, _EventEmitter); + + var _super = _createSuper(ReferSubscriber); + + function ReferSubscriber(session) { + var _this; + + _classCallCheck(this, ReferSubscriber); + + _this = _super.call(this); + _this._id = null; + _this._session = session; + return _this; + } + + _createClass(ReferSubscriber, [{ + key: "id", + get: function get() { + return this._id; + } + }, { + key: "sendRefer", + value: function sendRefer(target) { + var _this2 = this; + + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + debug('sendRefer()'); + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers. + + for (var event in eventHandlers) { + if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { + this.on(event, eventHandlers[event]); + } + } // Replaces URI header field. + + + var replaces = null; + + if (options.replaces) { + replaces = options.replaces._request.call_id; + replaces += ";to-tag=".concat(options.replaces._to_tag); + replaces += ";from-tag=".concat(options.replaces._from_tag); + replaces = encodeURIComponent(replaces); + } // Refer-To header field. + + + var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">"); + extraHeaders.push(referTo); // Referred-By header field. + + var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); + extraHeaders.push(referredBy); + extraHeaders.push("Contact: ".concat(this._session.contact)); + + var request = this._session.sendRequest(JsSIP_C.REFER, { + extraHeaders: extraHeaders, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + _this2._requestSucceeded(response); + }, + onErrorResponse: function onErrorResponse(response) { + _this2._requestFailed(response, JsSIP_C.causes.REJECTED); + }, + onTransportError: function onTransportError() { + _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR); + }, + onRequestTimeout: function onRequestTimeout() { + _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT); + }, + onDialogError: function onDialogError() { + _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR); + } + } + }); + + this._id = request.cseq; + } + }, { + key: "receiveNotify", + value: function receiveNotify(request) { + debug('receiveNotify()'); + + if (!request.body) { + return; + } + + var status_line = Grammar.parse(request.body.trim(), 'Status_Line'); + + if (status_line === -1) { + debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); + return; + } + + switch (true) { + case /^100$/.test(status_line.status_code): + this.emit('trying', { + request: request, + status_line: status_line + }); + break; + + case /^1[0-9]{2}$/.test(status_line.status_code): + this.emit('progress', { + request: request, + status_line: status_line + }); + break; + + case /^2[0-9]{2}$/.test(status_line.status_code): + this.emit('accepted', { + request: request, + status_line: status_line + }); + break; + + default: + this.emit('failed', { + request: request, + status_line: status_line + }); + break; + } + } + }, { + key: "_requestSucceeded", + value: function _requestSucceeded(response) { + debug('REFER succeeded'); + debug('emit "requestSucceeded"'); + this.emit('requestSucceeded', { + response: response + }); + } + }, { + key: "_requestFailed", + value: function _requestFailed(response, cause) { + debug('REFER failed'); + debug('emit "requestFailed"'); + this.emit('requestFailed', { + response: response || null, + cause: cause + }); + } + }]); + + return ReferSubscriber; +}(EventEmitter); +},{"../Constants":2,"../Grammar":7,"../Utils":28,"debug":32,"events":31}],18:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var Utils = require('./Utils'); + +var JsSIP_C = require('./Constants'); + +var SIPMessage = require('./SIPMessage'); + +var RequestSender = require('./RequestSender'); + +var debug = require('debug')('JsSIP:Registrator'); + +var MIN_REGISTER_EXPIRES = 10; // In seconds. + +module.exports = /*#__PURE__*/function () { + function Registrator(ua, transport) { + _classCallCheck(this, Registrator); + + var reg_id = 1; // Force reg_id to 1. + + this._ua = ua; + this._transport = transport; + this._registrar = ua.configuration.registrar_server; + this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2. + + this._call_id = Utils.createRandomToken(22); + this._cseq = 0; + this._to_uri = ua.configuration.uri; + this._registrationTimer = null; // Ongoing Register request. + + this._registering = false; // Set status. + + this._registered = false; // Contact header. + + this._contact = this._ua.contact.toString(); // Sip.ice media feature tag (RFC 5768). + + this._contact += ';+sip.ice'; // Custom headers for REGISTER and un-REGISTER. + + this._extraHeaders = []; // Custom Contact header params for REGISTER and un-REGISTER. + + this._extraContactParams = ''; + + if (reg_id) { + this._contact += ";reg-id=".concat(reg_id); + this._contact += ";+sip.instance=\"\""); + } + } + + _createClass(Registrator, [{ + key: "registered", + get: function get() { + return this._registered; + } + }, { + key: "setExtraHeaders", + value: function setExtraHeaders(extraHeaders) { + if (!Array.isArray(extraHeaders)) { + extraHeaders = []; + } + + this._extraHeaders = extraHeaders.slice(); + } + }, { + key: "setExtraContactParams", + value: function setExtraContactParams(extraContactParams) { + if (!(extraContactParams instanceof Object)) { + extraContactParams = {}; + } // Reset it. + + + this._extraContactParams = ''; + + for (var param_key in extraContactParams) { + if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) { + var param_value = extraContactParams[param_key]; + this._extraContactParams += ";".concat(param_key); + + if (param_value) { + this._extraContactParams += "=".concat(param_value); + } + } + } + } + }, { + key: "register", + value: function register() { + var _this = this; + + if (this._registering) { + debug('Register request in progress...'); + return; + } + + var extraHeaders = this._extraHeaders.slice(); + + extraHeaders.push("Contact: ".concat(this._contact, ";expires=").concat(this._expires).concat(this._extraContactParams)); + extraHeaders.push("Expires: ".concat(this._expires)); + var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, { + 'to_uri': this._to_uri, + 'call_id': this._call_id, + 'cseq': this._cseq += 1 + }, extraHeaders); + var request_sender = new RequestSender(this._ua, request, { + onRequestTimeout: function onRequestTimeout() { + _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT); + }, + onTransportError: function onTransportError() { + _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR); + }, + // Increase the CSeq on authentication. + onAuthenticated: function onAuthenticated() { + _this._cseq += 1; + }, + onReceiveResponse: function onReceiveResponse(response) { + // Discard responses to older REGISTER/un-REGISTER requests. + if (response.cseq !== _this._cseq) { + return; + } // Clear registration timer. + + + if (_this._registrationTimer !== null) { + clearTimeout(_this._registrationTimer); + _this._registrationTimer = null; + } + + switch (true) { + case /^1[0-9]{2}$/.test(response.status_code): + { + // Ignore provisional responses. + break; + } + + case /^2[0-9]{2}$/.test(response.status_code): + { + _this._registering = false; + + if (!response.hasHeader('Contact')) { + debug('no Contact header in response to REGISTER, response ignored'); + break; + } + + var contacts = response.headers['Contact'].reduce(function (a, b) { + return a.concat(b.parsed); + }, []); // Get the Contact pointing to us and update the expires value accordingly. + + var contact = contacts.find(function (element) { + return element.uri.user === _this._ua.contact.uri.user; + }); + + if (!contact) { + debug('no Contact header pointing to us, response ignored'); + break; + } + + var expires = contact.getParam('expires'); + + if (!expires && response.hasHeader('expires')) { + expires = response.getHeader('expires'); + } + + if (!expires) { + expires = _this._expires; + } + + expires = Number(expires); + if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES; + var timeout = expires > 64 ? expires * 1000 / 2 + Math.floor((expires / 2 - 32) * 1000 * Math.random()) : expires * 1000 - 5000; // Re-Register or emit an event before the expiration interval has elapsed. + // For that, decrease the expires value. ie: 3 seconds. + + _this._registrationTimer = setTimeout(function () { + _this._registrationTimer = null; // If there are no listeners for registrationExpiring, renew registration. + // If there are listeners, let the function listening do the register call. + + if (_this._ua.listeners('registrationExpiring').length === 0) { + _this.register(); + } else { + _this._ua.emit('registrationExpiring'); + } + }, timeout); // Save gruu values. + + if (contact.hasParam('temp-gruu')) { + _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, ''); + } + + if (contact.hasParam('pub-gruu')) { + _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, ''); + } + + if (!_this._registered) { + _this._registered = true; + + _this._ua.registered({ + response: response + }); + } + + break; + } + // Interval too brief RFC3261 10.2.8. + + case /^423$/.test(response.status_code): + { + if (response.hasHeader('min-expires')) { + // Increase our registration interval to the suggested minimum. + _this._expires = Number(response.getHeader('min-expires')); + if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES; // Attempt the registration again immediately. + + _this.register(); + } else { + // This response MUST contain a Min-Expires header field. + debug('423 response received for REGISTER without Min-Expires'); + + _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); + } + + break; + } + + default: + { + var cause = Utils.sipErrorCause(response.status_code); + + _this._registrationFailure(response, cause); + } + } + } + }); + this._registering = true; + request_sender.send(); + } + }, { + key: "unregister", + value: function unregister() { + var _this2 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + if (!this._registered) { + debug('already unregistered'); + return; + } + + this._registered = false; // Clear the registration timer. + + if (this._registrationTimer !== null) { + clearTimeout(this._registrationTimer); + this._registrationTimer = null; + } + + var extraHeaders = this._extraHeaders.slice(); + + if (options.all) { + extraHeaders.push("Contact: *".concat(this._extraContactParams)); + } else { + extraHeaders.push("Contact: ".concat(this._contact, ";expires=0").concat(this._extraContactParams)); + } + + extraHeaders.push('Expires: 0'); + var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, { + 'to_uri': this._to_uri, + 'call_id': this._call_id, + 'cseq': this._cseq += 1 + }, extraHeaders); + var request_sender = new RequestSender(this._ua, request, { + onRequestTimeout: function onRequestTimeout() { + _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT); + }, + onTransportError: function onTransportError() { + _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR); + }, + // Increase the CSeq on authentication. + onAuthenticated: function onAuthenticated() { + _this2._cseq += 1; + }, + onReceiveResponse: function onReceiveResponse(response) { + switch (true) { + case /^1[0-9]{2}$/.test(response.status_code): + // Ignore provisional responses. + break; + + case /^2[0-9]{2}$/.test(response.status_code): + _this2._unregistered(response); + + break; + + default: + { + var cause = Utils.sipErrorCause(response.status_code); + + _this2._unregistered(response, cause); + } + } + } + }); + request_sender.send(); + } + }, { + key: "close", + value: function close() { + if (this._registered) { + this.unregister(); + } + } + }, { + key: "onTransportClosed", + value: function onTransportClosed() { + this._registering = false; + + if (this._registrationTimer !== null) { + clearTimeout(this._registrationTimer); + this._registrationTimer = null; + } + + if (this._registered) { + this._registered = false; + + this._ua.unregistered({}); + } + } + }, { + key: "_registrationFailure", + value: function _registrationFailure(response, cause) { + this._registering = false; + + this._ua.registrationFailed({ + response: response || null, + cause: cause + }); + + if (this._registered) { + this._registered = false; + + this._ua.unregistered({ + response: response || null, + cause: cause + }); + } + } + }, { + key: "_unregistered", + value: function _unregistered(response, cause) { + this._registering = false; + this._registered = false; + + this._ua.unregistered({ + response: response || null, + cause: cause || null + }); + } + }]); + + return Registrator; +}(); +},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32}],19:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var JsSIP_C = require('./Constants'); + +var DigestAuthentication = require('./DigestAuthentication'); + +var Transactions = require('./Transactions'); + +var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers. + + +var EventHandlers = { + onRequestTimeout: function onRequestTimeout() {}, + onTransportError: function onTransportError() {}, + onReceiveResponse: function onReceiveResponse() {}, + onAuthenticated: function onAuthenticated() {} +}; + +module.exports = /*#__PURE__*/function () { + function RequestSender(ua, request, eventHandlers) { + var config2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + + _classCallCheck(this, RequestSender); + + this._ua = ua; + this._eventHandlers = eventHandlers; + this._method = request.method; + this._request = request; + this._auth = null; + this._challenged = false; + this._staled = false; + this._config2 = config2; // Define the undefined handlers. + + for (var handler in EventHandlers) { + if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { + if (!this._eventHandlers[handler]) { + this._eventHandlers[handler] = EventHandlers[handler]; + } + } + } // If ua is in closing process or even closed just allow sending Bye and ACK. + + + if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) { + this._eventHandlers.onTransportError(); + } + } + /** + * Create the client transaction and send the message. + */ + + + _createClass(RequestSender, [{ + key: "send", + value: function send() { + var _this = this; + + var eventHandlers = { + onRequestTimeout: function onRequestTimeout() { + _this._eventHandlers.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this._eventHandlers.onTransportError(); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this._receiveResponse(response); + } + }; + + switch (this._method) { + case 'INVITE': + this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); + break; + + case 'ACK': + this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); + break; + + default: + this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); + } // If authorization JWT is present, use it. + + + if (this._ua._configuration.authorization_jwt) { + this._request.setHeader('Authorization', this._ua._configuration.authorization_jwt); + } + + this.clientTransaction.send(); + } + /** + * Called from client transaction when receiving a correct response to the request. + * Authenticate request if needed or pass the response back to the applicant. + */ + + }, { + key: "_receiveResponse", + value: function _receiveResponse(response) { + var challenge; + var authorization_header_name; + var status_code = response.status_code; + /* + * Authentication + * Authenticate once. _challenged_ flag used to avoid infinite authentications. + */ + + if ((status_code === 401 || status_code === 407) && (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { + // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. + if (response.status_code === 401) { + challenge = response.parseHeader('www-authenticate'); + authorization_header_name = 'authorization'; + } else { + challenge = response.parseHeader('proxy-authenticate'); + authorization_header_name = 'proxy-authorization'; + } // Verify it seems a valid challenge. + + + if (!challenge) { + debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); + + this._eventHandlers.onReceiveResponse(response); + + return; + } + + if (!this._challenged || !this._staled && challenge.stale === true) { + if (!this._auth) { + var cnf = this._config2 ? this._config2 : this._ua.configuration; + this._auth = new DigestAuthentication({ + username: cnf.authorization_user, + password: cnf.password, + realm: cnf.realm, + ha1: cnf.ha1 + }); + } // Verify that the challenge is really valid. + + + if (!this._auth.authenticate(this._request, challenge)) { + this._eventHandlers.onReceiveResponse(response); + + return; + } + + this._challenged = true; // Update ha1 and realm in the UA or in alternative config. + + if (!this._config2) { + this._ua.set('realm', this._auth.get('realm')); + + this._ua.set('ha1', this._auth.get('ha1')); + } else { + this._config2.realm = this._auth.get('realm'); + this._config2.ha1 = this._auth.get('ha1'); + } + + if (challenge.stale) { + this._staled = true; + } + + this._request = this._request.clone(); + this._request.cseq += 1; + + this._request.setHeader('cseq', "".concat(this._request.cseq, " ").concat(this._method)); + + this._request.setHeader(authorization_header_name, this._auth.toString()); + + this._eventHandlers.onAuthenticated(this._request); + + this.send(); + } else { + this._eventHandlers.onReceiveResponse(response); + } + } else { + this._eventHandlers.onReceiveResponse(response); + } + } + }]); + + return RequestSender; +}(); +},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,"debug":32}],20:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var sdp_transform = require('sdp-transform'); + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var NameAddrHeader = require('./NameAddrHeader'); + +var Grammar = require('./Grammar'); + +var debug = require('debug')('JsSIP:SIPMessage'); +/** + * -param {String} method request method + * -param {String} ruri request uri + * -param {UA} ua + * -param {Object} params parameters that will have priority over ua.configuration parameters: + *
+ * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set + * -param {Object} [headers] extra headers + * -param {String} [body] + */ + + +var OutgoingRequest = /*#__PURE__*/function () { + function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) { + _classCallCheck(this, OutgoingRequest); + + // Mandatory parameters check. + if (!method || !ruri || !ua) { + return null; + } + + params = params || {}; + this.ua = ua; + this.headers = {}; + this.method = method; + this.ruri = ruri; + this.body = body; + this.extraHeaders = Utils.cloneArray(extraHeaders); // Fill the Common SIP Request Headers. + // Route. + + if (params.route_set) { + this.setHeader('route', params.route_set); + } else if (ua.configuration.use_preloaded_route) { + this.setHeader('route', "<".concat(ua.transport.sip_uri, ";lr>")); + } // Via. + // Empty Via header. Will be filled by the client transaction. + + + this.setHeader('via', ''); // Max-Forwards. + + this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS); // To + + var to_uri = params.to_uri || ruri; + var to_params = params.to_tag ? { + tag: params.to_tag + } : null; + var to_display_name = typeof params.to_display_name !== 'undefined' ? params.to_display_name : null; + this.to = new NameAddrHeader(to_uri, to_display_name, to_params); + this.setHeader('to', this.to.toString()); // From. + + var from_uri = params.from_uri || ua.configuration.uri; + var from_params = { + tag: params.from_tag || Utils.newTag() + }; + var display_name; + + if (typeof params.from_display_name !== 'undefined') { + display_name = params.from_display_name; + } else if (ua.configuration.display_name) { + display_name = ua.configuration.display_name; + } else { + display_name = null; + } + + this.from = new NameAddrHeader(from_uri, display_name, from_params); + this.setHeader('from', this.from.toString()); // Call-ID. + + var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15); + this.call_id = call_id; + this.setHeader('call-id', call_id); // CSeq. + + var cseq = params.cseq || Math.floor(Math.random() * 10000); + this.cseq = cseq; + this.setHeader('cseq', "".concat(cseq, " ").concat(method)); + } + /** + * Replace the the given header by the given value. + * -param {String} name header name + * -param {String | Array} value header value + */ + + + _createClass(OutgoingRequest, [{ + key: "setHeader", + value: function setHeader(name, value) { + // Remove the header from extraHeaders if present. + var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); + + for (var idx = 0; idx < this.extraHeaders.length; idx++) { + if (regexp.test(this.extraHeaders[idx])) { + this.extraHeaders.splice(idx, 1); + } + } + + this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value]; + } + /** + * Get the value of the given header name at the given position. + * -param {String} name header name + * -returns {String|undefined} Returns the specified header, null if header doesn't exist. + */ + + }, { + key: "getHeader", + value: function getHeader(name) { + var headers = this.headers[Utils.headerize(name)]; + + if (headers) { + if (headers[0]) { + return headers[0]; + } + } else { + var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); + + var _iterator = _createForOfIteratorHelper(this.extraHeaders), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var header = _step.value; + + if (regexp.test(header)) { + return header.substring(header.indexOf(':') + 1).trim(); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + + return; + } + /** + * Get the header/s of the given name. + * -param {String} name header name + * -returns {Array} Array with all the headers of the specified name. + */ + + }, { + key: "getHeaders", + value: function getHeaders(name) { + var headers = this.headers[Utils.headerize(name)]; + var result = []; + + if (headers) { + var _iterator2 = _createForOfIteratorHelper(headers), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var header = _step2.value; + result.push(header); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + + return result; + } else { + var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); + + var _iterator3 = _createForOfIteratorHelper(this.extraHeaders), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _header = _step3.value; + + if (regexp.test(_header)) { + result.push(_header.substring(_header.indexOf(':') + 1).trim()); + } + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + + return result; + } + } + /** + * Verify the existence of the given header. + * -param {String} name header name + * -returns {boolean} true if header with given name exists, false otherwise + */ + + }, { + key: "hasHeader", + value: function hasHeader(name) { + if (this.headers[Utils.headerize(name)]) { + return true; + } else { + var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); + + var _iterator4 = _createForOfIteratorHelper(this.extraHeaders), + _step4; + + try { + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + var header = _step4.value; + + if (regexp.test(header)) { + return true; + } + } + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); + } + } + + return false; + } + /** + * Parse the current body as a SDP and store the resulting object + * into this.sdp. + * -param {Boolean} force: Parse even if this.sdp already exists. + * + * Returns this.sdp. + */ + + }, { + key: "parseSDP", + value: function parseSDP(force) { + if (!force && this.sdp) { + return this.sdp; + } else { + this.sdp = sdp_transform.parse(this.body || ''); + return this.sdp; + } + } + }, { + key: "toString", + value: function toString() { + var msg = "".concat(this.method, " ").concat(this.ruri, " SIP/2.0\r\n"); + + for (var headerName in this.headers) { + if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) { + var _iterator5 = _createForOfIteratorHelper(this.headers[headerName]), + _step5; + + try { + for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { + var headerValue = _step5.value; + msg += "".concat(headerName, ": ").concat(headerValue, "\r\n"); + } + } catch (err) { + _iterator5.e(err); + } finally { + _iterator5.f(); + } + } + } + + var _iterator6 = _createForOfIteratorHelper(this.extraHeaders), + _step6; + + try { + for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { + var header = _step6.value; + msg += "".concat(header.trim(), "\r\n"); + } // Supported. + + } catch (err) { + _iterator6.e(err); + } finally { + _iterator6.f(); + } + + var supported = []; + + switch (this.method) { + case JsSIP_C.REGISTER: + supported.push('path', 'gruu'); + break; + + case JsSIP_C.INVITE: + if (this.ua.configuration.session_timers) { + supported.push('timer'); + } + + if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) { + supported.push('gruu'); + } + + supported.push('ice', 'replaces'); + break; + + case JsSIP_C.UPDATE: + if (this.ua.configuration.session_timers) { + supported.push('timer'); + } + + supported.push('ice'); + break; + } + + supported.push('outbound'); + var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT; // Allow. + + msg += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); + msg += "Supported: ".concat(supported, "\r\n"); + msg += "User-Agent: ".concat(userAgent, "\r\n"); + + if (this.body) { + var length = Utils.str_utf8_length(this.body); + msg += "Content-Length: ".concat(length, "\r\n\r\n"); + msg += this.body; + } else { + msg += 'Content-Length: 0\r\n\r\n'; + } + + return msg; + } + }, { + key: "clone", + value: function clone() { + var request = new OutgoingRequest(this.method, this.ruri, this.ua); + Object.keys(this.headers).forEach(function (name) { + request.headers[name] = this.headers[name].slice(); + }, this); + request.body = this.body; + request.extraHeaders = Utils.cloneArray(this.extraHeaders); + request.to = this.to; + request.from = this.from; + request.call_id = this.call_id; + request.cseq = this.cseq; + return request; + } + }]); + + return OutgoingRequest; +}(); + +var InitialOutgoingInviteRequest = /*#__PURE__*/function (_OutgoingRequest) { + _inherits(InitialOutgoingInviteRequest, _OutgoingRequest); + + var _super = _createSuper(InitialOutgoingInviteRequest); + + function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) { + var _this; + + _classCallCheck(this, InitialOutgoingInviteRequest); + + _this = _super.call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body); + _this.transaction = null; + return _this; + } + + _createClass(InitialOutgoingInviteRequest, [{ + key: "cancel", + value: function cancel(reason) { + this.transaction.cancel(reason); + } + }, { + key: "clone", + value: function clone() { + var request = new InitialOutgoingInviteRequest(this.ruri, this.ua); + Object.keys(this.headers).forEach(function (name) { + request.headers[name] = this.headers[name].slice(); + }, this); + request.body = this.body; + request.extraHeaders = Utils.cloneArray(this.extraHeaders); + request.to = this.to; + request.from = this.from; + request.call_id = this.call_id; + request.cseq = this.cseq; + request.transaction = this.transaction; + return request; + } + }]); + + return InitialOutgoingInviteRequest; +}(OutgoingRequest); + +var IncomingMessage = /*#__PURE__*/function () { + function IncomingMessage() { + _classCallCheck(this, IncomingMessage); + + 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; + } + /** + * Insert a header of the given name and value into the last position of the + * header array. + */ + + + _createClass(IncomingMessage, [{ + key: "addHeader", + value: function addHeader(name, value) { + var header = { + raw: value + }; + name = Utils.headerize(name); + + if (this.headers[name]) { + this.headers[name].push(header); + } else { + this.headers[name] = [header]; + } + } + /** + * Get the value of the given header name at the given position. + */ + + }, { + key: "getHeader", + value: function getHeader(name) { + var header = this.headers[Utils.headerize(name)]; + + if (header) { + if (header[0]) { + return header[0].raw; + } + } else { + return; + } + } + /** + * Get the header/s of the given name. + */ + + }, { + key: "getHeaders", + value: function getHeaders(name) { + var headers = this.headers[Utils.headerize(name)]; + var result = []; + + if (!headers) { + return []; + } + + var _iterator7 = _createForOfIteratorHelper(headers), + _step7; + + try { + for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { + var header = _step7.value; + result.push(header.raw); + } + } catch (err) { + _iterator7.e(err); + } finally { + _iterator7.f(); + } + + return result; + } + /** + * Verify the existence of the given header. + */ + + }, { + key: "hasHeader", + value: function hasHeader(name) { + return this.headers[Utils.headerize(name)] ? true : false; + } + /** + * Parse the given header on the given index. + * -param {String} name header name + * -param {Number} [idx=0] header index + * -returns {Object|undefined} Parsed header object, undefined if the header + * is not present or in case of a parsing error. + */ + + }, { + key: "parseHeader", + value: function parseHeader(name) { + var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + name = Utils.headerize(name); + + if (!this.headers[name]) { + debug("header \"".concat(name, "\" not present")); + return; + } else if (idx >= this.headers[name].length) { + debug("not so many \"".concat(name, "\" headers present")); + return; + } + + var header = this.headers[name][idx]; + var value = header.raw; + + if (header.parsed) { + return header.parsed; + } // Substitute '-' by '_' for grammar rule matching. + + + var parsed = Grammar.parse(value, name.replace(/-/g, '_')); + + if (parsed === -1) { + this.headers[name].splice(idx, 1); // delete from headers + + debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); + return; + } else { + header.parsed = parsed; + return parsed; + } + } + /** + * Message Header attribute selector. Alias of parseHeader. + * -param {String} name header name + * -param {Number} [idx=0] header index + * -returns {Object|undefined} Parsed header object, undefined if the header + * is not present or in case of a parsing error. + * + * -example + * message.s('via',3).port + */ + + }, { + key: "s", + value: function s(name, idx) { + return this.parseHeader(name, idx); + } + /** + * Replace the value of the given header by the value. + * -param {String} name header name + * -param {String} value header value + */ + + }, { + key: "setHeader", + value: function setHeader(name, value) { + var header = { + raw: value + }; + this.headers[Utils.headerize(name)] = [header]; + } + /** + * Parse the current body as a SDP and store the resulting object + * into this.sdp. + * -param {Boolean} force: Parse even if this.sdp already exists. + * + * Returns this.sdp. + */ + + }, { + key: "parseSDP", + value: function parseSDP(force) { + if (!force && this.sdp) { + return this.sdp; + } else { + this.sdp = sdp_transform.parse(this.body || ''); + return this.sdp; + } + } + }, { + key: "toString", + value: function toString() { + return this.data; + } + }]); + + return IncomingMessage; +}(); + +var IncomingRequest = /*#__PURE__*/function (_IncomingMessage) { + _inherits(IncomingRequest, _IncomingMessage); + + var _super2 = _createSuper(IncomingRequest); + + function IncomingRequest(ua) { + var _this2; + + _classCallCheck(this, IncomingRequest); + + _this2 = _super2.call(this); + _this2.ua = ua; + _this2.headers = {}; + _this2.ruri = null; + _this2.transport = null; + _this2.server_transaction = null; + return _this2; + } + /** + * Stateful reply. + * -param {Number} code status code + * -param {String} reason reason phrase + * -param {Object} headers extra headers + * -param {String} body body + * -param {Function} [onSuccess] onSuccess callback + * -param {Function} [onFailure] onFailure callback + */ + + + _createClass(IncomingRequest, [{ + key: "reply", + value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) { + var supported = []; + var to = this.getHeader('To'); + code = code || null; + reason = reason || null; // Validate code and reason values. + + if (!code || code < 100 || code > 699) { + throw new TypeError("Invalid status_code: ".concat(code)); + } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { + throw new TypeError("Invalid reason_phrase: ".concat(reason)); + } + + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + extraHeaders = Utils.cloneArray(extraHeaders); + var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); + + if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) { + var headers = this.getHeaders('record-route'); + + var _iterator8 = _createForOfIteratorHelper(headers), + _step8; + + try { + for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { + var header = _step8.value; + response += "Record-Route: ".concat(header, "\r\n"); + } + } catch (err) { + _iterator8.e(err); + } finally { + _iterator8.f(); + } + } + + var vias = this.getHeaders('via'); + + var _iterator9 = _createForOfIteratorHelper(vias), + _step9; + + try { + for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { + var via = _step9.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator9.e(err); + } finally { + _iterator9.f(); + } + + if (!this.to_tag && code > 100) { + to += ";tag=".concat(Utils.newTag()); + } else if (this.to_tag && !this.s('to').hasParam('tag')) { + to += ";tag=".concat(this.to_tag); + } + + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(this.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(this.call_id, "\r\n"); + response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); + + var _iterator10 = _createForOfIteratorHelper(extraHeaders), + _step10; + + try { + for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { + var _header2 = _step10.value; + response += "".concat(_header2.trim(), "\r\n"); + } // Supported. + + } catch (err) { + _iterator10.e(err); + } finally { + _iterator10.f(); + } + + switch (this.method) { + case JsSIP_C.INVITE: + if (this.ua.configuration.session_timers) { + supported.push('timer'); + } + + if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) { + supported.push('gruu'); + } + + supported.push('ice', 'replaces'); + break; + + case JsSIP_C.UPDATE: + if (this.ua.configuration.session_timers) { + supported.push('timer'); + } + + if (body) { + supported.push('ice'); + } + + supported.push('replaces'); + } + + supported.push('outbound'); // Allow and Accept. + + if (this.method === JsSIP_C.OPTIONS) { + response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); + response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n"); + } else if (code === 405) { + response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); + } else if (code === 415) { + response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n"); + } + + response += "Supported: ".concat(supported, "\r\n"); + + if (body) { + var length = Utils.str_utf8_length(body); + response += 'Content-Type: application/sdp\r\n'; + response += "Content-Length: ".concat(length, "\r\n\r\n"); + response += body; + } else { + response += "Content-Length: ".concat(0, "\r\n\r\n"); + } + + this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); + } + /** + * Stateless reply. + * -param {Number} code status code + * -param {String} reason reason phrase + */ + + }, { + key: "reply_sl", + value: function reply_sl() { + var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var vias = this.getHeaders('via'); // Validate code and reason values. + + if (!code || code < 100 || code > 699) { + throw new TypeError("Invalid status_code: ".concat(code)); + } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { + throw new TypeError("Invalid reason_phrase: ".concat(reason)); + } + + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); + + var _iterator11 = _createForOfIteratorHelper(vias), + _step11; + + try { + for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { + var via = _step11.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator11.e(err); + } finally { + _iterator11.f(); + } + + var to = this.getHeader('To'); + + if (!this.to_tag && code > 100) { + to += ";tag=".concat(Utils.newTag()); + } else if (this.to_tag && !this.s('to').hasParam('tag')) { + to += ";tag=".concat(this.to_tag); + } + + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(this.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(this.call_id, "\r\n"); + response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); + response += "Content-Length: ".concat(0, "\r\n\r\n"); + this.transport.send(response); + } + }]); + + return IncomingRequest; +}(IncomingMessage); + +var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { + _inherits(IncomingResponse, _IncomingMessage2); + + var _super3 = _createSuper(IncomingResponse); + + function IncomingResponse() { + var _this3; + + _classCallCheck(this, IncomingResponse); + + _this3 = _super3.call(this); + _this3.headers = {}; + _this3.status_code = null; + _this3.reason_phrase = null; + return _this3; + } + + return IncomingResponse; +}(IncomingMessage); + +module.exports = { + OutgoingRequest: OutgoingRequest, + InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, + IncomingRequest: IncomingRequest, + IncomingResponse: IncomingResponse +}; +},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,"debug":32,"sdp-transform":37}],21:[function(require,module,exports){ +"use strict"; + +var Utils = require('./Utils'); + +var Grammar = require('./Grammar'); + +var debugerror = require('debug')('JsSIP:ERROR:Socket'); + +debugerror.log = console.warn.bind(console); +/** + * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ + * + * interface Socket { + * attribute String via_transport + * attribute String url + * attribute String sip_uri + * + * method connect(); + * method disconnect(); + * method send(data); + * + * attribute EventHandler onconnect + * attribute EventHandler ondisconnect + * attribute EventHandler ondata + * } + * + */ + +exports.isSocket = function (socket) { + // Ignore if an array is given. + if (Array.isArray(socket)) { + return false; + } + + if (typeof socket === 'undefined') { + debugerror('undefined JsSIP.Socket instance'); + return false; + } // Check Properties. + + + try { + if (!Utils.isString(socket.url)) { + debugerror('missing or invalid JsSIP.Socket url property'); + throw new Error(); + } + + if (!Utils.isString(socket.via_transport)) { + debugerror('missing or invalid JsSIP.Socket via_transport property'); + throw new Error(); + } + + if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { + debugerror('missing or invalid JsSIP.Socket sip_uri property'); + throw new Error(); + } + } catch (e) { + return false; + } // Check Methods. + + + try { + ['connect', 'disconnect', 'send'].forEach(function (method) { + if (!Utils.isFunction(socket[method])) { + debugerror("missing or invalid JsSIP.Socket method: ".concat(method)); + throw new Error(); + } + }); + } catch (e) { + return false; + } + + return true; +}; +},{"./Grammar":7,"./Utils":28,"debug":32}],22:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:Subscriber'); + +var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); + +debugerror.log = console.warn.bind(console); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Subscriber, _EventEmitter); + + var _super = _createSuper(Subscriber); + + function Subscriber(ua, target, _ref) { + var _this; + + var event_name = _ref.event_name, + accept = _ref.accept, + expires = _ref.expires, + content_type = _ref.content_type, + allow_events = _ref.allow_events, + params = _ref.params, + headers = _ref.headers, + credential = _ref.credential; + + _classCallCheck(this, Subscriber); + + debug('new'); + _this = _super.call(this); + _this._ua = ua; + + if (!target) { + throw new TypeError('target is undefined'); + } + + _this.target = target; + + if (!event_name) { + throw new TypeError('event_name is undefined'); + } + + _this.event_name = event_name; + + if (!accept) { + throw new TypeError('accept is undefined'); + } + + _this.accept = accept; + + if (!expires) { + expires = 900; + } + + _this.expires = expires; + _this.allow_events = allow_events; // used to subscribe with body + + _this.content_type = content_type; + + if (!params) { + throw new TypeError('params is undefined'); + } + + if (!params.from_uri) { + throw new TypeError('params.from_uri is undefined'); + } + + if (!params.to_uri) { + throw new TypeError('params.to_uri is undefined'); + } + + _this.params = params; + params.from_tag = Utils.newTag(); + params.to_tag = null; + params.call_id = Utils.createRandomToken(20); + params.cseq = Math.floor(Math.random() * 10000 + 1); + _this.contact = ""); // this.contact = ``; + // Optional, used if credential is different from REGISTER/INVITE + + _this.credential = credential; // dialog state: init, notify_wait, pending, active, terminated + + _this._state = 'init'; // dialog id + + _this.id = null; // to refresh subscription + + _this.expires_timer = null; + _this.expires_timestamp = null; + + if (!headers) { + headers = []; + } + + _this.headers = headers.concat(["Event: ".concat(_this.event_name), "Accept: ".concat(_this.accept), "Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); + + if (_this.allowEvents) { + _this.headers.push("Allow-Events: ".concat(_this.allowEvents)); + } + + _this.is_terminated = false; + _this.route_set = null; // Custom session empty object for high level use. + + _this.data = {}; + return _this; + } + /** + * Callbacks + */ + + + _createClass(Subscriber, [{ + key: "onAuthenticated", + value: function onAuthenticated() { + this.params.cseq++; + } + }, { + key: "onRequestTimeout", + value: function onRequestTimeout() { + this._dialogTerminated('subscribe response timeout'); + } + }, { + key: "onTransportError", + value: function onTransportError() { + this._dialogTerminated('subscribe transport error'); + } + }, { + key: "onReceiveResponse", + value: function onReceiveResponse(response) { + if (response.status_code >= 200 && response.status_code < 300) { + if (this.params.to_tag === null) { + this.params.to_tag = response.to_tag; + this.id = "".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag); + debug('added dialog id=', this.id); + + this._ua.newDialog(this); + + this.route_set = response.getHeaders('record-route').reverse(); + + if (this.route_set.length > 0) { + this.params.route_set = this.route_set; + } + } + + var expires = this._getExpires(response); + + if (expires === -1) { + debugerror('response without Expires header'); + return; + } + + if (expires > 0) { + this.expires_timestamp = new Date().getTime() + expires * 1000; + + this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + } + } else if (response.status_code >= 300) { + this._dialogTerminated('receive subscribe non-OK response'); + } + } + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + if (request.method !== JsSIP_C.NOTIFY) { + request.reply(405); + return; + } + + var subs_state = request.parseHeader('subscription-state'); + + if (!subs_state) { + debugerror('missed header Subscription-State'); + request.reply(400); + return; + } + + request.reply(200); + var new_state = subs_state.state.toLowerCase(); + var prev_state = this._state; + + if (prev_state !== 'terminated' && new_state !== 'terminated') { + this._state = new_state; + + if (subs_state.expires !== undefined) { + var expires = subs_state.expires; + var expires_timestamp = new Date().getTime() + expires * 1000; + var max_time_deviation = 2000; // expiration time is shorter and the difference is not too small + + if (this.expires_timestamp - expires_timestamp > max_time_deviation) { + debug('update sending re-SUBSCRIBE time'); + clearTimeout(this.expires_timer); + this.expires_timestamp = expires_timestamp; + + this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + } + } + } + + if (prev_state !== 'active' && new_state === 'active') { + debug('emit "active"'); + this.emit('active'); + } + + var body = request.body; + var is_final = new_state === 'terminated'; // notify event fired for NOTIFY with body + + if (body) { + var content_type = request.getHeader('content-type'); + debug('emit "notify"'); + this.emit('notify', is_final, request, body, content_type); + } + + if (is_final) { + this._dialogTerminated('receive final notify'); + } + } + /** + * User API + */ + + }, { + key: "subscribe", + value: function subscribe() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + debug('subscribe()'); + + if (this._state === 'init') { + this._state = 'notify_wait'; + } + + var headers = this.headers.slice(); + + if (body) { + if (!this.content_type) { + throw new TypeError('content_type is undefined'); + } + + headers.push("Content-Type: ".concat(this.content_type)); + } + + this._send(body, headers); + } + }, { + key: "unsubscribe", + value: function unsubscribe() { + debug('unsubscribe()'); + + this._dialogTerminated('send un-subscribe'); + + var headers = ["Event: ".concat(this.event_name), 'Expires: 0']; + + this._send(null, headers); + } + }, { + key: "state", + get: function get() { + return this._state; + } + /** + * Private API. + */ + + }, { + key: "_dialogTerminated", + value: function _dialogTerminated(reason) { + var _this2 = this; + + // to prevent duplicate emit terminated + if (this.is_terminated) { + return; + } + + this.is_terminated = true; + this._state = 'terminated'; + clearTimeout(this.expires_timer); // remove dialog from dialogs table with some delay, to allow receiving final NOTIFY + + setTimeout(function () { + debug('removed dialog id=', _this2.id); + + _this2._ua.destroyDialog(_this2); + }, 32000); + debug("emit \"terminated\" ".concat(reason, "\"")); + this.emit('terminated', reason); + } + }, { + key: "_send", + value: function _send(body, headers) { + this.params.cseq++; + + this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this.target, this.params, headers, body, this, this.credential); + } + }, { + key: "_getExpires", + value: function _getExpires(r) { + var e = r.getHeader('expires'); + return e ? parseInt(e) : -1; + } + }, { + key: "_calculateTimeoutMs", + value: function _calculateTimeoutMs(expires) { + return expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; + } + }, { + key: "_scheduleSubscribe", + value: function _scheduleSubscribe(timeout) { + var _this3 = this; + + debug("next SUBSCRIBE will be sent in ".concat(Math.floor(timeout / 1000), " sec")); + this.expires_timer = setTimeout(function () { + _this3.expires_timer = undefined; + + _this3._send(null, _this3.headers); + }, timeout); + } + }]); + + return Subscriber; +}(EventEmitter); +},{"./Constants":2,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ +"use strict"; + +var T1 = 500, + T2 = 4000, + T4 = 5000; +module.exports = { + T1: T1, + T2: T2, + T4: T4, + TIMER_B: 64 * T1, + TIMER_D: 0 * T1, + TIMER_F: 64 * T1, + TIMER_H: 64 * T1, + TIMER_I: 0 * T1, + TIMER_J: 0 * T1, + TIMER_K: 0 * T4, + TIMER_L: 64 * T1, + TIMER_M: 64 * T1, + PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 + +}; +},{}],24:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var SIPMessage = require('./SIPMessage'); + +var Timers = require('./Timers'); + +var debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); + +var debugict = require('debug')('JsSIP:InviteClientTransaction'); + +var debugact = require('debug')('JsSIP:AckClientTransaction'); + +var debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); + +var debugist = require('debug')('JsSIP:InviteServerTransaction'); + +var C = { + // Transaction states. + STATUS_TRYING: 1, + STATUS_PROCEEDING: 2, + STATUS_CALLING: 3, + STATUS_ACCEPTED: 4, + STATUS_COMPLETED: 5, + STATUS_TERMINATED: 6, + STATUS_CONFIRMED: 7, + // Transaction types. + NON_INVITE_CLIENT: 'nict', + NON_INVITE_SERVER: 'nist', + INVITE_CLIENT: 'ict', + INVITE_SERVER: 'ist' +}; + +var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { + _inherits(NonInviteClientTransaction, _EventEmitter); + + var _super = _createSuper(NonInviteClientTransaction); + + function NonInviteClientTransaction(ua, transport, request, eventHandlers) { + var _this; + + _classCallCheck(this, NonInviteClientTransaction); + + _this = _super.call(this); + _this.type = C.NON_INVITE_CLIENT; + _this.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); + _this.ua = ua; + _this.transport = transport; + _this.request = request; + _this.eventHandlers = eventHandlers; + var via = "SIP/2.0/".concat(transport.via_transport); + via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this.id); + + _this.request.setHeader('via', via); + + _this.ua.newTransaction(_assertThisInitialized(_this)); + + return _this; + } + + _createClass(NonInviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "stateChanged", + value: function stateChanged(state) { + this.state = state; + this.emit('stateChanged'); + } + }, { + key: "send", + value: function send() { + var _this2 = this; + + this.stateChanged(C.STATUS_TRYING); + this.F = setTimeout(function () { + _this2.timer_F(); + }, Timers.TIMER_F); + + if (!this.transport.send(this.request)) { + this.onTransportError(); + } + } + }, { + key: "onTransportError", + value: function onTransportError() { + debugnict("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 timer_F() { + debugnict("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 timer_K() { + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + }, { + key: "receiveResponse", + value: function receiveResponse(response) { + var _this3 = this; + + var status_code = response.status_code; + + if (status_code < 200) { + switch (this.state) { + case C.STATUS_TRYING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_PROCEEDING); + this.eventHandlers.onReceiveResponse(response); + break; + } + } else { + switch (this.state) { + case C.STATUS_TRYING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_COMPLETED); + clearTimeout(this.F); + + if (status_code === 408) { + this.eventHandlers.onRequestTimeout(); + } else { + this.eventHandlers.onReceiveResponse(response); + } + + this.K = setTimeout(function () { + _this3.timer_K(); + }, Timers.TIMER_K); + break; + + case C.STATUS_COMPLETED: + break; + } + } + } + }]); + + return NonInviteClientTransaction; +}(EventEmitter); + +var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { + _inherits(InviteClientTransaction, _EventEmitter2); + + var _super2 = _createSuper(InviteClientTransaction); + + function InviteClientTransaction(ua, transport, request, eventHandlers) { + var _this4; + + _classCallCheck(this, InviteClientTransaction); + + _this4 = _super2.call(this); + _this4.type = C.INVITE_CLIENT; + _this4.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); + _this4.ua = ua; + _this4.transport = transport; + _this4.request = request; + _this4.eventHandlers = eventHandlers; + request.transaction = _assertThisInitialized(_this4); + var via = "SIP/2.0/".concat(transport.via_transport); + via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this4.id); + + _this4.request.setHeader('via', via); + + _this4.ua.newTransaction(_assertThisInitialized(_this4)); + + return _this4; + } + + _createClass(InviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "stateChanged", + value: function stateChanged(state) { + this.state = state; + this.emit('stateChanged'); + } + }, { + key: "send", + value: function send() { + var _this5 = this; + + this.stateChanged(C.STATUS_CALLING); + this.B = setTimeout(function () { + _this5.timer_B(); + }, Timers.TIMER_B); + + if (!this.transport.send(this.request)) { + this.onTransportError(); + } + } + }, { + key: "onTransportError", + value: function onTransportError() { + clearTimeout(this.B); + clearTimeout(this.D); + clearTimeout(this.M); + + if (this.state !== C.STATUS_ACCEPTED) { + debugict("transport error occurred, deleting transaction ".concat(this.id)); + this.eventHandlers.onTransportError(); + } + + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } // RFC 6026 7.2. + + }, { + key: "timer_M", + value: function timer_M() { + debugict("Timer M expired for transaction ".concat(this.id)); + + if (this.state === C.STATUS_ACCEPTED) { + clearTimeout(this.B); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + } // RFC 3261 17.1.1. + + }, { + key: "timer_B", + value: function timer_B() { + debugict("Timer B expired for transaction ".concat(this.id)); + + if (this.state === C.STATUS_CALLING) { + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + this.eventHandlers.onRequestTimeout(); + } + } + }, { + key: "timer_D", + value: function timer_D() { + debugict("Timer D expired for transaction ".concat(this.id)); + clearTimeout(this.B); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + }, { + key: "sendACK", + value: function sendACK(response) { + var _this6 = this; + + var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, { + 'route_set': this.request.getHeaders('route'), + 'call_id': this.request.getHeader('call-id'), + 'cseq': this.request.cseq + }); + ack.setHeader('from', this.request.getHeader('from')); + ack.setHeader('via', this.request.getHeader('via')); + ack.setHeader('to', response.getHeader('to')); + this.D = setTimeout(function () { + _this6.timer_D(); + }, Timers.TIMER_D); + this.transport.send(ack); + } + }, { + key: "cancel", + value: function cancel(reason) { + // Send only if a provisional response (>100) has been received. + if (this.state !== C.STATUS_PROCEEDING) { + return; + } + + var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, { + 'route_set': this.request.getHeaders('route'), + 'call_id': this.request.getHeader('call-id'), + 'cseq': this.request.cseq + }); + cancel.setHeader('from', this.request.getHeader('from')); + cancel.setHeader('via', this.request.getHeader('via')); + cancel.setHeader('to', this.request.getHeader('to')); + + if (reason) { + cancel.setHeader('reason', reason); + } + + this.transport.send(cancel); + } + }, { + key: "receiveResponse", + value: function receiveResponse(response) { + var _this7 = this; + + var status_code = response.status_code; + + if (status_code >= 100 && status_code <= 199) { + switch (this.state) { + case C.STATUS_CALLING: + this.stateChanged(C.STATUS_PROCEEDING); + this.eventHandlers.onReceiveResponse(response); + break; + + case C.STATUS_PROCEEDING: + this.eventHandlers.onReceiveResponse(response); + break; + } + } else if (status_code >= 200 && status_code <= 299) { + switch (this.state) { + case C.STATUS_CALLING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_ACCEPTED); + this.M = setTimeout(function () { + _this7.timer_M(); + }, Timers.TIMER_M); + this.eventHandlers.onReceiveResponse(response); + break; + + case C.STATUS_ACCEPTED: + this.eventHandlers.onReceiveResponse(response); + break; + } + } else if (status_code >= 300 && status_code <= 699) { + switch (this.state) { + case C.STATUS_CALLING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_COMPLETED); + this.sendACK(response); + this.eventHandlers.onReceiveResponse(response); + break; + + case C.STATUS_COMPLETED: + this.sendACK(response); + break; + } + } + } + }]); + + return InviteClientTransaction; +}(EventEmitter); + +var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { + _inherits(AckClientTransaction, _EventEmitter3); + + var _super3 = _createSuper(AckClientTransaction); + + function AckClientTransaction(ua, transport, request, eventHandlers) { + var _this8; + + _classCallCheck(this, AckClientTransaction); + + _this8 = _super3.call(this); + _this8.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); + _this8.transport = transport; + _this8.request = request; + _this8.eventHandlers = eventHandlers; + var via = "SIP/2.0/".concat(transport.via_transport); + via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this8.id); + + _this8.request.setHeader('via', via); + + return _this8; + } + + _createClass(AckClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "send", + value: function send() { + if (!this.transport.send(this.request)) { + this.onTransportError(); + } + } + }, { + key: "onTransportError", + value: function onTransportError() { + debugact("transport error occurred for transaction ".concat(this.id)); + this.eventHandlers.onTransportError(); + } + }]); + + return AckClientTransaction; +}(EventEmitter); + +var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { + _inherits(NonInviteServerTransaction, _EventEmitter4); + + var _super4 = _createSuper(NonInviteServerTransaction); + + function NonInviteServerTransaction(ua, transport, request) { + var _this9; + + _classCallCheck(this, NonInviteServerTransaction); + + _this9 = _super4.call(this); + _this9.type = C.NON_INVITE_SERVER; + _this9.id = request.via_branch; + _this9.ua = ua; + _this9.transport = transport; + _this9.request = request; + _this9.last_response = ''; + request.server_transaction = _assertThisInitialized(_this9); + _this9.state = C.STATUS_TRYING; + ua.newTransaction(_assertThisInitialized(_this9)); + return _this9; + } + + _createClass(NonInviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "stateChanged", + value: function stateChanged(state) { + this.state = state; + this.emit('stateChanged'); + } + }, { + key: "timer_J", + value: function timer_J() { + debugnist("Timer J expired for transaction ".concat(this.id)); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + }, { + key: "onTransportError", + value: function onTransportError() { + if (!this.transportError) { + this.transportError = true; + debugnist("transport error occurred, deleting transaction ".concat(this.id)); + clearTimeout(this.J); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + } + }, { + key: "receiveResponse", + value: function receiveResponse(status_code, response, onSuccess, onFailure) { + var _this10 = this; + + if (status_code === 100) { + /* RFC 4320 4.1 + * 'A SIP element MUST NOT + * send any provisional response with a + * Status-Code other than 100 to a non-INVITE request.' + */ + switch (this.state) { + case C.STATUS_TRYING: + this.stateChanged(C.STATUS_PROCEEDING); + + if (!this.transport.send(response)) { + this.onTransportError(); + } + + break; + + case C.STATUS_PROCEEDING: + this.last_response = response; + + if (!this.transport.send(response)) { + this.onTransportError(); + + if (onFailure) { + onFailure(); + } + } else if (onSuccess) { + onSuccess(); + } + + break; + } + } else if (status_code >= 200 && status_code <= 699) { + switch (this.state) { + case C.STATUS_TRYING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_COMPLETED); + this.last_response = response; + this.J = setTimeout(function () { + _this10.timer_J(); + }, Timers.TIMER_J); + + if (!this.transport.send(response)) { + this.onTransportError(); + + if (onFailure) { + onFailure(); + } + } else if (onSuccess) { + onSuccess(); + } + + break; + + case C.STATUS_COMPLETED: + break; + } + } + } + }]); + + return NonInviteServerTransaction; +}(EventEmitter); + +var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { + _inherits(InviteServerTransaction, _EventEmitter5); + + var _super5 = _createSuper(InviteServerTransaction); + + function InviteServerTransaction(ua, transport, request) { + var _this11; + + _classCallCheck(this, InviteServerTransaction); + + _this11 = _super5.call(this); + _this11.type = C.INVITE_SERVER; + _this11.id = request.via_branch; + _this11.ua = ua; + _this11.transport = transport; + _this11.request = request; + _this11.last_response = ''; + request.server_transaction = _assertThisInitialized(_this11); + _this11.state = C.STATUS_PROCEEDING; + ua.newTransaction(_assertThisInitialized(_this11)); + _this11.resendProvisionalTimer = null; + request.reply(100); + return _this11; + } + + _createClass(InviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "stateChanged", + value: function stateChanged(state) { + this.state = state; + this.emit('stateChanged'); + } + }, { + key: "timer_H", + value: function timer_H() { + debugist("Timer H expired for transaction ".concat(this.id)); + + if (this.state === C.STATUS_COMPLETED) { + debugist('ACK not received, dialog will be terminated'); + } + + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + }, { + key: "timer_I", + value: function timer_I() { + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } // RFC 6026 7.1. + + }, { + key: "timer_L", + value: function timer_L() { + debugist("Timer L expired for transaction ".concat(this.id)); + + if (this.state === C.STATUS_ACCEPTED) { + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + } + }, { + key: "onTransportError", + value: function onTransportError() { + if (!this.transportError) { + this.transportError = true; + debugist("transport error occurred, deleting transaction ".concat(this.id)); + + if (this.resendProvisionalTimer !== null) { + clearInterval(this.resendProvisionalTimer); + this.resendProvisionalTimer = null; + } + + clearTimeout(this.L); + clearTimeout(this.H); + clearTimeout(this.I); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + } + }, { + key: "resend_provisional", + value: function resend_provisional() { + if (!this.transport.send(this.last_response)) { + this.onTransportError(); + } + } // INVITE Server Transaction RFC 3261 17.2.1. + + }, { + key: "receiveResponse", + value: function receiveResponse(status_code, response, onSuccess, onFailure) { + var _this12 = this; + + if (status_code >= 100 && status_code <= 199) { + switch (this.state) { + case C.STATUS_PROCEEDING: + if (!this.transport.send(response)) { + this.onTransportError(); + } + + this.last_response = response; + break; + } + } + + if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) { + // Trigger the resendProvisionalTimer only for the first non 100 provisional response. + if (this.resendProvisionalTimer === null) { + this.resendProvisionalTimer = setInterval(function () { + _this12.resend_provisional(); + }, Timers.PROVISIONAL_RESPONSE_INTERVAL); + } + } else if (status_code >= 200 && status_code <= 299) { + switch (this.state) { + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_ACCEPTED); + this.last_response = response; + this.L = setTimeout(function () { + _this12.timer_L(); + }, Timers.TIMER_L); + + if (this.resendProvisionalTimer !== null) { + clearInterval(this.resendProvisionalTimer); + this.resendProvisionalTimer = null; + } + + /* falls through */ + + case C.STATUS_ACCEPTED: + // Note that this point will be reached for proceeding this.state also. + if (!this.transport.send(response)) { + this.onTransportError(); + + if (onFailure) { + onFailure(); + } + } else if (onSuccess) { + onSuccess(); + } + + break; + } + } else if (status_code >= 300 && status_code <= 699) { + switch (this.state) { + case C.STATUS_PROCEEDING: + if (this.resendProvisionalTimer !== null) { + clearInterval(this.resendProvisionalTimer); + this.resendProvisionalTimer = null; + } + + if (!this.transport.send(response)) { + this.onTransportError(); + + if (onFailure) { + onFailure(); + } + } else { + this.stateChanged(C.STATUS_COMPLETED); + this.H = setTimeout(function () { + _this12.timer_H(); + }, Timers.TIMER_H); + + if (onSuccess) { + onSuccess(); + } + } + + break; + } + } + } + }]); + + return InviteServerTransaction; +}(EventEmitter); +/** + * INVITE: + * _true_ if retransmission + * _false_ new request + * + * ACK: + * _true_ ACK to non2xx response + * _false_ ACK must be passed to TU (accepted state) + * ACK to 2xx response + * + * CANCEL: + * _true_ no matching invite transaction + * _false_ matching invite transaction and no final response sent + * + * OTHER: + * _true_ retransmission + * _false_ new request + */ + + +function checkTransaction(_ref, request) { + var _transactions = _ref._transactions; + var tr; + + switch (request.method) { + case JsSIP_C.INVITE: + tr = _transactions.ist[request.via_branch]; + + if (tr) { + switch (tr.state) { + case C.STATUS_PROCEEDING: + tr.transport.send(tr.last_response); + break; + // RFC 6026 7.1 Invite retransmission. + // Received while in C.STATUS_ACCEPTED state. Absorb it. + + case C.STATUS_ACCEPTED: + break; + } + + return true; + } + + break; + + case JsSIP_C.ACK: + tr = _transactions.ist[request.via_branch]; // RFC 6026 7.1. + + if (tr) { + if (tr.state === C.STATUS_ACCEPTED) { + return false; + } else if (tr.state === C.STATUS_COMPLETED) { + tr.state = C.STATUS_CONFIRMED; + tr.I = setTimeout(function () { + tr.timer_I(); + }, Timers.TIMER_I); + return true; + } + } // ACK to 2XX Response. + else { + return false; + } + + break; + + case JsSIP_C.CANCEL: + tr = _transactions.ist[request.via_branch]; + + if (tr) { + request.reply_sl(200); + + if (tr.state === C.STATUS_PROCEEDING) { + return false; + } else { + return true; + } + } else { + request.reply_sl(481); + return true; + } + + default: + // Non-INVITE Server Transaction RFC 3261 17.2.2. + tr = _transactions.nist[request.via_branch]; + + if (tr) { + switch (tr.state) { + case C.STATUS_TRYING: + break; + + case C.STATUS_PROCEEDING: + case C.STATUS_COMPLETED: + tr.transport.send(tr.last_response); + break; + } + + return true; + } + + break; + } +} + +module.exports = { + C: C, + NonInviteClientTransaction: NonInviteClientTransaction, + InviteClientTransaction: InviteClientTransaction, + AckClientTransaction: AckClientTransaction, + NonInviteServerTransaction: NonInviteServerTransaction, + InviteServerTransaction: InviteServerTransaction, + checkTransaction: checkTransaction +}; +},{"./Constants":2,"./SIPMessage":20,"./Timers":23,"debug":32,"events":31}],25:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var Socket = require('./Socket'); + +var debug = require('debug')('JsSIP:Transport'); + +var debugerror = require('debug')('JsSIP:ERROR:Transport'); + +var JsSIP_C = require('./Constants'); + +debugerror.log = console.warn.bind(console); +/** + * Constants + */ + +var C = { + // Transport status. + STATUS_CONNECTED: 0, + STATUS_CONNECTING: 1, + STATUS_DISCONNECTED: 2, + // Socket status. + SOCKET_STATUS_READY: 0, + SOCKET_STATUS_ERROR: 1, + // Recovery options. + recovery_options: { + // minimum interval in seconds between recover attempts. + min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL, + // maximum interval in seconds between recover attempts. + max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL + } +}; +/* + * Manages one or multiple JsSIP.Socket instances. + * Is reponsible for transport recovery logic among all socket instances. + * + * @socket JsSIP::Socket instance + */ + +module.exports = /*#__PURE__*/function () { + function Transport(sockets) { + var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options; + + _classCallCheck(this, Transport); + + debug('new()'); + this.status = C.STATUS_DISCONNECTED; // Current socket. + + this.socket = null; // Socket collection. + + this.sockets = []; + this.recovery_options = recovery_options; + this.recover_attempts = 0; + this.recovery_timer = null; + this.close_requested = false; // It seems that TextDecoder is not available in some versions of React-Native. + // See https://github.com/versatica/JsSIP/issues/695 + + try { + this.textDecoder = new TextDecoder('utf8'); + } catch (error) { + debugerror("cannot use TextDecoder: ".concat(error)); + } + + if (typeof sockets === 'undefined') { + throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument'); + } + + if (!(sockets instanceof Array)) { + sockets = [sockets]; + } + + sockets.forEach(function (socket) { + if (!Socket.isSocket(socket.socket)) { + throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance'); + } + + if (socket.weight && !Number(socket.weight)) { + throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number'); + } + + this.sockets.push({ + socket: socket.socket, + weight: socket.weight || 0, + status: C.SOCKET_STATUS_READY + }); + }, this); // Get the socket with higher weight. + + this._getSocket(); + } + /** + * Instance Methods + */ + + + _createClass(Transport, [{ + key: "via_transport", + get: function get() { + return this.socket.via_transport; + } + }, { + key: "url", + get: function get() { + return this.socket.url; + } + }, { + key: "sip_uri", + get: function get() { + return this.socket.sip_uri; + } + }, { + key: "connect", + value: function connect() { + debug('connect()'); + + if (this.isConnected()) { + debug('Transport is already connected'); + return; + } else if (this.isConnecting()) { + debug('Transport is connecting'); + return; + } + + this.close_requested = false; + this.status = C.STATUS_CONNECTING; + this.onconnecting({ + socket: this.socket, + attempts: this.recover_attempts + }); + + if (!this.close_requested) { + // Bind socket event callbacks. + this.socket.onconnect = this._onConnect.bind(this); + this.socket.ondisconnect = this._onDisconnect.bind(this); + this.socket.ondata = this._onData.bind(this); + this.socket.connect(); + } + + return; + } + }, { + key: "disconnect", + value: function disconnect() { + debug('close()'); + this.close_requested = true; + this.recover_attempts = 0; + this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer. + + if (this.recovery_timer !== null) { + clearTimeout(this.recovery_timer); + this.recovery_timer = null; + } // Unbind socket event callbacks. + + + this.socket.onconnect = function () {}; + + this.socket.ondisconnect = function () {}; + + this.socket.ondata = function () {}; + + this.socket.disconnect(); + this.ondisconnect({ + socket: this.socket, + error: false + }); + } + }, { + key: "send", + value: function send(data) { + debug('send()'); + + if (!this.isConnected()) { + debugerror('unable to send message, transport is not connected'); + return false; + } + + var message = data.toString(); + debug("sending message:\n\n".concat(message, "\n")); + return this.socket.send(message); + } + }, { + key: "isConnected", + value: function isConnected() { + return this.status === C.STATUS_CONNECTED; + } + }, { + key: "isConnecting", + value: function isConnecting() { + return this.status === C.STATUS_CONNECTING; + } + /** + * Private API. + */ + + }, { + key: "_reconnect", + value: function _reconnect() { + var _this = this; + + this.recover_attempts += 1; + var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1); + + if (k < this.recovery_options.min_interval) { + k = this.recovery_options.min_interval; + } else if (k > this.recovery_options.max_interval) { + k = this.recovery_options.max_interval; + } + + debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); + this.recovery_timer = setTimeout(function () { + if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) { + // Get the next available socket with higher weight. + _this._getSocket(); // Connect the socket. + + + _this.connect(); + } + }, k * 1000); + } + /** + * get the next available socket with higher weight + */ + + }, { + key: "_getSocket", + value: function _getSocket() { + var candidates = []; + this.sockets.forEach(function (socket) { + if (socket.status === C.SOCKET_STATUS_ERROR) { + return; // continue the array iteration + } else if (candidates.length === 0) { + candidates.push(socket); + } else if (socket.weight > candidates[0].weight) { + candidates = [socket]; + } else if (socket.weight === candidates[0].weight) { + candidates.push(socket); + } + }); + + if (candidates.length === 0) { + // All sockets have failed. reset sockets status. + this.sockets.forEach(function (socket) { + socket.status = C.SOCKET_STATUS_READY; + }); // Get next available socket. + + this._getSocket(); + + return; + } + + var idx = Math.floor(Math.random() * candidates.length); + this.socket = candidates[idx].socket; + } + /** + * Socket Event Handlers + */ + + }, { + key: "_onConnect", + value: function _onConnect() { + this.recover_attempts = 0; + this.status = C.STATUS_CONNECTED; // Clear recovery_timer. + + if (this.recovery_timer !== null) { + clearTimeout(this.recovery_timer); + this.recovery_timer = null; + } + + this.onconnect({ + socket: this + }); + } + }, { + key: "_onDisconnect", + value: function _onDisconnect(error, code, reason) { + this.status = C.STATUS_DISCONNECTED; + this.ondisconnect({ + socket: this.socket, + error: error, + code: code, + reason: reason + }); + + if (this.close_requested) { + return; + } // Update socket status. + else { + this.sockets.forEach(function (socket) { + if (this.socket === socket.socket) { + socket.status = C.SOCKET_STATUS_ERROR; + } + }, this); + } + + this._reconnect(error); + } + }, { + key: "_onData", + value: function _onData(data) { + // CRLF Keep Alive response from server. Ignore it. + if (data === '\r\n') { + debug('received message with CRLF Keep Alive response'); + return; + } // Binary message. + else if (typeof data !== 'string') { + try { + if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data)); + } catch (evt) { + debug('received binary message failed to be converted into string,' + ' message discarded'); + return; + } + + debug("received binary message:\n\n".concat(data, "\n")); + } // Text message. + else { + debug("received text message:\n\n".concat(data, "\n")); + } + + this.ondata({ + transport: this, + message: data + }); + } + }]); + + return Transport; +}(); +},{"./Constants":2,"./Socket":21,"debug":32}],26:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var Registrator = require('./Registrator'); + +var RTCSession = require('./RTCSession'); + +var Subscriber = require('./Subscriber'); + +var Notifier = require('./Notifier'); + +var Message = require('./Message'); + +var Transactions = require('./Transactions'); + +var Transport = require('./Transport'); + +var Utils = require('./Utils'); + +var Exceptions = require('./Exceptions'); + +var URI = require('./URI'); + +var Parser = require('./Parser'); + +var SIPMessage = require('./SIPMessage'); + +var RequestSender = require('./RequestSender'); + +var sanityCheck = require('./sanityCheck'); + +var config = require('./Config'); + +var debug = require('debug')('JsSIP:UA'); + +var debugerror = require('debug')('JsSIP:ERROR:UA'); + +debugerror.log = console.warn.bind(console); +var C = { + // UA status codes. + STATUS_INIT: 0, + STATUS_READY: 1, + STATUS_USER_CLOSED: 2, + STATUS_NOT_READY: 3, + // UA error codes. + CONFIGURATION_ERROR: 1, + NETWORK_ERROR: 2 +}; +/** + * The User-Agent class. + * @class JsSIP.UA + * @param {Object} configuration Configuration parameters. + * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid. + * @throws {TypeError} If no configuration is given. + */ + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(UA, _EventEmitter); + + var _super = _createSuper(UA); + + function UA(configuration) { + var _this; + + _classCallCheck(this, UA); + + debug('new() [configuration:%o]', configuration); + _this = _super.call(this); + _this._cache = { + credentials: {} + }; + _this._configuration = Object.assign({}, config.settings); + _this._dynConfiguration = {}; + _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE). + + _this._applicants = {}; + _this._sessions = {}; + _this._transport = null; + _this._contact = null; + _this._status = C.STATUS_INIT; + _this._error = null; + _this._transactions = { + nist: {}, + nict: {}, + ist: {}, + ict: {} + }; // Custom UA empty object for high level use. + + _this._data = {}; + _this._closeTimer = null; // Check configuration argument. + + if (configuration === undefined) { + throw new TypeError('Not enough arguments'); + } // Load configuration. + + + try { + _this._loadConfig(configuration); + } catch (e) { + _this._status = C.STATUS_NOT_READY; + _this._error = C.CONFIGURATION_ERROR; + throw e; + } // Initialize registrator. + + + _this._registrator = new Registrator(_assertThisInitialized(_this)); + return _this; + } + + _createClass(UA, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "configuration", + get: function get() { + return this._configuration; + } + }, { + key: "transport", + get: function get() { + return this._transport; + } // ================= + // High Level API + // ================= + + /** + * Connect to the server if status = STATUS_INIT. + * Resume UA after being closed. + */ + + }, { + key: "start", + value: function start() { + debug('start()'); + + if (this._status === C.STATUS_INIT) { + this._transport.connect(); + } else if (this._status === C.STATUS_USER_CLOSED) { + debug('restarting UA'); // Disconnect. + + if (this._closeTimer !== null) { + clearTimeout(this._closeTimer); + this._closeTimer = null; + + this._transport.disconnect(); + } // Reconnect. + + + this._status = C.STATUS_INIT; + + this._transport.connect(); + } else if (this._status === C.STATUS_READY) { + debug('UA is in READY status, not restarted'); + } else { + debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); + } // Set dynamic configuration. + + + this._dynConfiguration.register = this._configuration.register; + } + /** + * Register. + */ + + }, { + key: "register", + value: function register() { + debug('register()'); + this._dynConfiguration.register = true; + + this._registrator.register(); + } + /** + * Unregister. + */ + + }, { + key: "unregister", + value: function unregister(options) { + debug('unregister()'); + this._dynConfiguration.register = false; + + this._registrator.unregister(options); + } + /** + * Get the Registrator instance. + */ + + }, { + key: "registrator", + value: function registrator() { + return this._registrator; + } + /** + * Registration state. + */ + + }, { + key: "isRegistered", + value: function isRegistered() { + return this._registrator.registered; + } + /** + * Connection state. + */ + + }, { + key: "isConnected", + value: function isConnected() { + return this._transport.isConnected(); + } + /** + * Make an outgoing call. + * + * -param {String} target + * -param {Object} [options] + * + * -throws {TypeError} + * + */ + + }, { + key: "call", + value: function call(target, options) { + debug('call()'); + var session = new RTCSession(this); + session.connect(target, options); + return session; + } + /** + * Send a message. + * + * -param {String} target + * -param {String} body + * -param {Object} [options] + * + * -throws {TypeError} + * + */ + + }, { + key: "sendMessage", + value: function sendMessage(target, body, options) { + debug('sendMessage()'); + var message = new Message(this); + message.send(target, body, options); + return message; + } + /** + * Arbitrary client transaction + */ + + }, { + key: "sendRequest", + value: function sendRequest(method, target, params, headers, body, handlers, credential) { + debug('sendRequest()'); + var request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); + var requestSender = new RequestSender(this, request, handlers, credential); + requestSender.send(); + } + /** + * Create subscriber + */ + + }, { + key: "subscriber", + value: function subscriber(target, options) { + debug('subscriber()'); + return new Subscriber(this, target, options); + } + /** + * Create notifier + */ + + }, { + key: "notifier", + value: function notifier(options) { + debug('notifier()'); + return new Notifier(this, options); + } + /** + * Terminate ongoing sessions. + */ + + }, { + key: "terminateSessions", + value: function terminateSessions(options) { + debug('terminateSessions()'); + + for (var idx in this._sessions) { + if (!this._sessions[idx].isEnded()) { + this._sessions[idx].terminate(options); + } + } + } + /** + * Gracefully close. + * + */ + + }, { + key: "stop", + value: function stop() { + var _this2 = this; + + debug('stop()'); // Remove dynamic settings. + + this._dynConfiguration = {}; + + if (this._status === C.STATUS_USER_CLOSED) { + debug('UA already closed'); + return; + } // Close registrator. + + + this._registrator.close(); // If there are session wait a bit so CANCEL/BYE can be sent and their responses received. + + + var num_sessions = Object.keys(this._sessions).length; // Run _terminate_ on every Session. + + for (var session in this._sessions) { + if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { + debug("closing session ".concat(session)); + + try { + this._sessions[session].terminate(); + } catch (error) {} + } + } // Run _close_ on every applicant. + + + for (var applicant in this._applicants) { + if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try { + this._applicants[applicant].close(); + } catch (error) {} + } + + this._status = C.STATUS_USER_CLOSED; + var num_transactions = Object.keys(this._transactions.nict).length + Object.keys(this._transactions.nist).length + Object.keys(this._transactions.ict).length + Object.keys(this._transactions.ist).length; + + if (num_transactions === 0 && num_sessions === 0) { + this._transport.disconnect(); + } else { + this._closeTimer = setTimeout(function () { + _this2._closeTimer = null; + + _this2._transport.disconnect(); + }, 2000); + } + } + /** + * Normalice a string into a valid SIP request URI + * -param {String} target + * -returns {JsSIP.URI|undefined} + */ + + }, { + key: "normalizeTarget", + value: function normalizeTarget(target) { + return Utils.normalizeTarget(target, this._configuration.hostport_params); + } + /** + * Allow retrieving configuration and autogenerated fields in runtime. + */ + + }, { + key: "get", + value: function get(parameter) { + switch (parameter) { + case 'authorization_user': + return this._configuration.authorization_user; + + case 'realm': + return this._configuration.realm; + + case 'ha1': + return this._configuration.ha1; + + case 'authorization_jwt': + return this._configuration.authorization_jwt; + + default: + debugerror('get() | cannot get "%s" parameter in runtime', parameter); + return undefined; + } + } + /** + * Allow configuration changes in runtime. + * Returns true if the parameter could be set. + */ + + }, { + key: "set", + value: function set(parameter, value) { + switch (parameter) { + case 'authorization_user': + { + this._configuration.authorization_user = String(value); + break; + } + + case 'password': + { + this._configuration.password = String(value); + break; + } + + case 'realm': + { + this._configuration.realm = String(value); + break; + } + + case 'ha1': + { + this._configuration.ha1 = String(value); // Delete the plain SIP password. + + this._configuration.password = null; + break; + } + + case 'authorization_jwt': + { + this._configuration.authorization_jwt = String(value); + break; + } + + case 'display_name': + { + this._configuration.display_name = value; + break; + } + + default: + debugerror('set() | cannot set "%s" parameter in runtime', parameter); + return false; + } + + return true; + } // ========================== + // Event Handlers. + // ========================== + + /** + * new Transaction + */ + + }, { + key: "newTransaction", + value: function newTransaction(transaction) { + this._transactions[transaction.type][transaction.id] = transaction; + this.emit('newTransaction', { + transaction: transaction + }); + } + /** + * Transaction destroyed. + */ + + }, { + key: "destroyTransaction", + value: function destroyTransaction(transaction) { + delete this._transactions[transaction.type][transaction.id]; + this.emit('transactionDestroyed', { + transaction: transaction + }); + } + /** + * new Dialog + */ + + }, { + key: "newDialog", + value: function newDialog(dialog) { + this._dialogs[dialog.id] = dialog; + } + /** + * Dialog destroyed. + */ + + }, { + key: "destroyDialog", + value: function destroyDialog(dialog) { + delete this._dialogs[dialog.id]; + } + /** + * new Message + */ + + }, { + key: "newMessage", + value: function newMessage(message, data) { + this._applicants[message] = message; + this.emit('newMessage', data); + } + /** + * Message destroyed. + */ + + }, { + key: "destroyMessage", + value: function destroyMessage(message) { + delete this._applicants[message]; + } + /** + * new RTCSession + */ + + }, { + key: "newRTCSession", + value: function newRTCSession(session, data) { + this._sessions[session.id] = session; + this.emit('newRTCSession', data); + } + /** + * RTCSession destroyed. + */ + + }, { + key: "destroyRTCSession", + value: function destroyRTCSession(session) { + delete this._sessions[session.id]; + } + /** + * Registered + */ + + }, { + key: "registered", + value: function registered(data) { + this.emit('registered', data); + } + /** + * Unregistered + */ + + }, { + key: "unregistered", + value: function unregistered(data) { + this.emit('unregistered', data); + } + /** + * Registration Failed + */ + + }, { + key: "registrationFailed", + value: function registrationFailed(data) { + this.emit('registrationFailed', data); + } // ========================= + // ReceiveRequest. + // ========================= + + /** + * Request reception + */ + + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + var method = request.method; // Check that request URI points to us. + + if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { + debug('Request-URI does not point to us'); + + if (request.method !== JsSIP_C.ACK) { + request.reply_sl(404); + } + + return; + } // Check request URI scheme. + + + if (request.ruri.scheme === JsSIP_C.SIPS) { + request.reply_sl(416); + return; + } // Check transaction. + + + if (Transactions.checkTransaction(this, request)) { + return; + } // Create the server transaction. + + + if (method === JsSIP_C.INVITE) { + /* eslint-disable no-new */ + new Transactions.InviteServerTransaction(this, this._transport, request); + /* eslint-enable no-new */ + } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) { + /* eslint-disable no-new */ + new Transactions.NonInviteServerTransaction(this, this._transport, request); + /* eslint-enable no-new */ + } + /* RFC3261 12.2.2 + * Requests that do not change in any way the state of a dialog may be + * received within a dialog (for example, an OPTIONS request). + * They are processed as if they had been received outside the dialog. + */ + + + if (method === JsSIP_C.OPTIONS) { + request.reply(200); + } else if (method === JsSIP_C.MESSAGE) { + if (this.listeners('newMessage').length === 0) { + request.reply(405); + return; + } + + var message = new Message(this); + message.init_incoming(request); + } else if (method === JsSIP_C.SUBSCRIBE) { + if (this.listeners('newSubscribe').length === 0) { + request.reply(405); + return; + } + } else if (method === JsSIP_C.INVITE) { + // Initial INVITE. + if (!request.to_tag && this.listeners('newRTCSession').length === 0) { + request.reply(405); + return; + } + } + + var dialog; + var session; // Initial Request. + + if (!request.to_tag) { + switch (method) { + case JsSIP_C.INVITE: + if (window.RTCPeerConnection) { + // TODO + if (request.hasHeader('replaces')) { + var replaces = request.replaces; + dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag); + + if (dialog) { + session = dialog.owner; + + if (!session.isEnded()) { + session.receiveRequest(request); + } else { + request.reply(603); + } + } else { + request.reply(481); + } + } else { + session = new RTCSession(this); + session.init_incoming(request); + } + } else { + debugerror('INVITE received but WebRTC is not supported'); + request.reply(488); + } + + break; + + case JsSIP_C.BYE: + // Out of dialog BYE received. + request.reply(481); + break; + + case JsSIP_C.CANCEL: + session = this._findSession(request); + + if (session) { + session.receiveRequest(request); + } else { + debug('received CANCEL request for a non existent session'); + } + + break; + + case JsSIP_C.ACK: + /* Absorb it. + * ACK request without a corresponding Invite Transaction + * and without To tag. + */ + break; + + case JsSIP_C.NOTIFY: + // Receive new sip event. + this.emit('sipEvent', { + event: request.event, + request: request + }); + request.reply(200); + break; + + case JsSIP_C.SUBSCRIBE: + this.emit('newSubscribe', { + event: request.event, + request: request + }); + break; + + default: + request.reply(405); + break; + } + } // In-dialog request. + else { + dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag); + + if (dialog) { + dialog.receiveRequest(request); + } else if (method === JsSIP_C.NOTIFY) { + session = this._findSession(request); + + if (session) { + session.receiveRequest(request); + } else { + debug('received NOTIFY request for a non existent subscription'); + request.reply(481, 'Subscription does not exist'); + } + } + /* RFC3261 12.2.2 + * Request with to tag, but no matching dialog found. + * Exception: ACK for an Invite request for which a dialog has not + * been created. + */ + else if (method !== JsSIP_C.ACK) { + request.reply(481); + } + } + } // ================= + // Utils. + // ================= + + /** + * Get the session to which the request belongs to, if any. + */ + + }, { + key: "_findSession", + value: function _findSession(_ref) { + var call_id = _ref.call_id, + from_tag = _ref.from_tag, + to_tag = _ref.to_tag; + var sessionIDa = call_id + from_tag; + var sessionA = this._sessions[sessionIDa]; + var sessionIDb = call_id + to_tag; + var sessionB = this._sessions[sessionIDb]; + + if (sessionA) { + return sessionA; + } else if (sessionB) { + return sessionB; + } else { + return null; + } + } + /** + * Get the dialog to which the request belongs to, if any. + */ + + }, { + key: "_findDialog", + value: function _findDialog(call_id, from_tag, to_tag) { + var id = call_id + from_tag + to_tag; + var dialog = this._dialogs[id]; + + if (dialog) { + return dialog; + } else { + id = call_id + to_tag + from_tag; + dialog = this._dialogs[id]; + + if (dialog) { + return dialog; + } else { + return null; + } + } + } + }, { + key: "_loadConfig", + value: function _loadConfig(configuration) { + // Check and load the given configuration. + try { + config.load(this._configuration, configuration); + } catch (e) { + throw e; + } // Post Configuration Process. + // Allow passing 0 number as display_name. + + + if (this._configuration.display_name === 0) { + this._configuration.display_name = '0'; + } // Instance-id for GRUU. + + + if (!this._configuration.instance_id) { + this._configuration.instance_id = Utils.newUUID(); + } // Jssip_id instance parameter. Static random tag of length 5. + + + this._configuration.jssip_id = Utils.createRandomToken(5); // String containing this._configuration.uri without scheme and user. + + var hostport_params = this._configuration.uri.clone(); + + hostport_params.user = null; + this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, ''); // Transport. + + try { + this._transport = new Transport(this._configuration.sockets, { + // Recovery options. + max_interval: this._configuration.connection_recovery_max_interval, + min_interval: this._configuration.connection_recovery_min_interval + }); // Transport event callbacks. + + this._transport.onconnecting = onTransportConnecting.bind(this); + this._transport.onconnect = onTransportConnect.bind(this); + this._transport.ondisconnect = onTransportDisconnect.bind(this); + this._transport.ondata = onTransportData.bind(this); + } catch (e) { + debugerror(e); + throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); + } // Remove sockets instance from configuration object. + + + delete this._configuration.sockets; // Check whether authorization_user is explicitly defined. + // Take 'this._configuration.uri.user' value if not. + + if (!this._configuration.authorization_user) { + this._configuration.authorization_user = this._configuration.uri.user; + } // If no 'registrar_server' is set use the 'uri' value without user portion and + // without URI params/headers. + + + if (!this._configuration.registrar_server) { + var registrar_server = this._configuration.uri.clone(); + + registrar_server.user = null; + registrar_server.clearParams(); + registrar_server.clearHeaders(); + this._configuration.registrar_server = registrar_server; + } // User no_answer_timeout. + + + this._configuration.no_answer_timeout *= 1000; // Via Host. + + if (this._configuration.contact_uri) { + this._configuration.via_host = this._configuration.contact_uri.host; + } // Contact URI. + else { + this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, { + transport: 'ws' + }); + } + + this._contact = { + pub_gruu: null, + temp_gruu: null, + uri: this._configuration.contact_uri, + toString: function toString() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var anonymous = options.anonymous || null; + var outbound = options.outbound || null; + var contact = '<'; + + if (anonymous) { + contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws'; + } else { + contact += this.pub_gruu || this.uri.toString(); + } + + if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) { + contact += ';ob'; + } + + contact += '>'; + return contact; + } + }; // Seal the configuration. + + var writable_parameters = ['authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register']; + + for (var parameter in this._configuration) { + if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) { + if (writable_parameters.indexOf(parameter) !== -1) { + Object.defineProperty(this._configuration, parameter, { + writable: true, + configurable: false + }); + } else { + Object.defineProperty(this._configuration, parameter, { + writable: false, + configurable: false + }); + } + } + } + + debug('configuration parameters after validation:'); + + for (var _parameter in this._configuration) { + // Only show the user user configurable parameters. + if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) { + switch (_parameter) { + case 'uri': + case 'registrar_server': + debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); + break; + + case 'password': + case 'ha1': + case 'authorization_jwt': + debug("- ".concat(_parameter, ": NOT SHOWN")); + break; + + default: + debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); + } + } + } + + return; + } + }], [{ + key: "C", + get: // Expose C object. + function get() { + return C; + } + }]); + + return UA; +}(EventEmitter); +/** + * Transport event handlers + */ +// Transport connecting event. + + +function onTransportConnecting(data) { + this.emit('connecting', data); +} // Transport connected event. + + +function onTransportConnect(data) { + if (this._status === C.STATUS_USER_CLOSED) { + return; + } + + this._status = C.STATUS_READY; + this._error = null; + this.emit('connected', data); + + if (this._dynConfiguration.register) { + this._registrator.register(); + } +} // Transport disconnected event. + + +function onTransportDisconnect(data) { + // Run _onTransportError_ callback on every client transaction using _transport_. + var client_transactions = ['nict', 'ict', 'nist', 'ist']; + + for (var _i = 0, _client_transactions = client_transactions; _i < _client_transactions.length; _i++) { + var type = _client_transactions[_i]; + + for (var id in this._transactions[type]) { + if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) { + this._transactions[type][id].onTransportError(); + } + } + } + + this.emit('disconnected', data); // Call registrator _onTransportClosed_. + + this._registrator.onTransportClosed(); + + if (this._status !== C.STATUS_USER_CLOSED) { + this._status = C.STATUS_NOT_READY; + this._error = C.NETWORK_ERROR; + } +} // Transport data event. + + +function onTransportData(data) { + var transport = data.transport; + var message = data.message; + message = Parser.parseMessage(message, this); + + if (!message) { + return; + } + + if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) { + return; + } // Do some sanity check. + + + if (!sanityCheck(message, this, transport)) { + return; + } + + if (message instanceof SIPMessage.IncomingRequest) { + message.transport = transport; + this.receiveRequest(message); + } else if (message instanceof SIPMessage.IncomingResponse) { + /* Unike stated in 18.1.2, if a response does not match + * any transaction, it is discarded here and no passed to the core + * in order to be discarded there. + */ + var transaction; + + switch (message.method) { + case JsSIP_C.INVITE: + transaction = this._transactions.ict[message.via_branch]; + + if (transaction) { + transaction.receiveResponse(message); + } + + break; + + case JsSIP_C.ACK: + // Just in case ;-). + break; + + default: + transaction = this._transactions.nict[message.via_branch]; + + if (transaction) { + transaction.receiveResponse(message); + } + + break; + } + } +} +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"debug":32,"events":31}],27:[function(require,module,exports){ +"use strict"; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var Grammar = require('./Grammar'); +/** + * -param {String} [scheme] + * -param {String} [user] + * -param {String} host + * -param {String} [port] + * -param {Object} [parameters] + * -param {Object} [headers] + * + */ + + +module.exports = /*#__PURE__*/function () { + function URI(scheme, user, host, port) { + var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; + var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; + + _classCallCheck(this, URI); + + // Checks. + if (!host) { + throw new TypeError('missing or invalid "host" parameter'); + } // Initialize parameters. + + + this._parameters = {}; + this._headers = {}; + this._scheme = scheme || JsSIP_C.SIP; + this._user = user; + this._host = host; + this._port = port; + + for (var param in parameters) { + if (Object.prototype.hasOwnProperty.call(parameters, param)) { + this.setParam(param, parameters[param]); + } + } + + for (var header in headers) { + if (Object.prototype.hasOwnProperty.call(headers, header)) { + this.setHeader(header, headers[header]); + } + } + } + + _createClass(URI, [{ + key: "scheme", + get: function get() { + return this._scheme; + }, + set: function set(value) { + this._scheme = value.toLowerCase(); + } + }, { + key: "user", + get: function get() { + return this._user; + }, + set: function set(value) { + this._user = value; + } + }, { + key: "host", + get: function get() { + return this._host; + }, + set: function set(value) { + this._host = value.toLowerCase(); + } + }, { + key: "port", + get: function get() { + return this._port; + }, + set: function set(value) { + this._port = value === 0 ? value : parseInt(value, 10) || null; + } + }, { + key: "setParam", + value: function setParam(key, value) { + if (key) { + this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString(); + } + } + }, { + key: "getParam", + value: function getParam(key) { + if (key) { + return this._parameters[key.toLowerCase()]; + } + } + }, { + key: "hasParam", + value: function hasParam(key) { + if (key) { + return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false; + } + } + }, { + key: "deleteParam", + value: function deleteParam(parameter) { + parameter = parameter.toLowerCase(); + + if (this._parameters.hasOwnProperty(parameter)) { + var value = this._parameters[parameter]; + delete this._parameters[parameter]; + return value; + } + } + }, { + key: "clearParams", + value: function clearParams() { + this._parameters = {}; + } + }, { + key: "setHeader", + value: function setHeader(name, value) { + this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value]; + } + }, { + key: "getHeader", + value: function getHeader(name) { + if (name) { + return this._headers[Utils.headerize(name)]; + } + } + }, { + key: "hasHeader", + value: function hasHeader(name) { + if (name) { + return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false; + } + } + }, { + key: "deleteHeader", + value: function deleteHeader(header) { + header = Utils.headerize(header); + + if (this._headers.hasOwnProperty(header)) { + var value = this._headers[header]; + delete this._headers[header]; + return value; + } + } + }, { + key: "clearHeaders", + value: function clearHeaders() { + this._headers = {}; + } + }, { + key: "clone", + value: function clone() { + return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers))); + } + }, { + key: "toString", + value: function toString() { + var headers = []; + var uri = "".concat(this._scheme, ":"); + + if (this._user) { + uri += "".concat(Utils.escapeUser(this._user), "@"); + } + + uri += this._host; + + if (this._port || this._port === 0) { + uri += ":".concat(this._port); + } + + for (var parameter in this._parameters) { + if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) { + uri += ";".concat(parameter); + + if (this._parameters[parameter] !== null) { + uri += "=".concat(this._parameters[parameter]); + } + } + } + + for (var header in this._headers) { + if (Object.prototype.hasOwnProperty.call(this._headers, header)) { + var _iterator = _createForOfIteratorHelper(this._headers[header]), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var item = _step.value; + headers.push("".concat(header, "=").concat(item)); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + } + + if (headers.length > 0) { + uri += "?".concat(headers.join('&')); + } + + return uri; + } + }, { + key: "toAor", + value: function toAor(show_port) { + var aor = "".concat(this._scheme, ":"); + + if (this._user) { + aor += "".concat(Utils.escapeUser(this._user), "@"); + } + + aor += this._host; + + if (show_port && (this._port || this._port === 0)) { + aor += ":".concat(this._port); + } + + return aor; + } + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a JsSIP.URI instance or undefined if + * it is an invalid URI. + */ + function parse(uri) { + uri = Grammar.parse(uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } else { + return undefined; + } + } + }]); + + return URI; +}(); +},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var JsSIP_C = require('./Constants'); + +var URI = require('./URI'); + +var Grammar = require('./Grammar'); + +exports.str_utf8_length = function (string) { + return unescape(encodeURIComponent(string)).length; +}; // Used by 'hasMethods'. + + +var isFunction = exports.isFunction = function (fn) { + if (fn !== undefined) { + return Object.prototype.toString.call(fn) === '[object Function]' ? true : false; + } else { + return false; + } +}; + +exports.isString = function (str) { + if (str !== undefined) { + return Object.prototype.toString.call(str) === '[object String]' ? true : false; + } else { + return false; + } +}; + +exports.isDecimal = function (num) { + return !isNaN(num) && parseFloat(num) === parseInt(num, 10); +}; + +exports.isEmpty = function (value) { + return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value); +}; + +exports.hasMethods = function (obj) { + for (var _len = arguments.length, methodNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + methodNames[_key - 1] = arguments[_key]; + } + + for (var _i = 0, _methodNames = methodNames; _i < _methodNames.length; _i++) { + var methodName = _methodNames[_i]; + + if (isFunction(obj[methodName])) { + return false; + } + } + + return true; +}; // Used by 'newTag'. + + +var createRandomToken = exports.createRandomToken = function (size) { + var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32; + var i, + r, + token = ''; + + for (i = 0; i < size; i++) { + r = Math.random() * base | 0; + token += r.toString(base); + } + + return token; +}; + +exports.newTag = function () { + return createRandomToken(10); +}; // https://stackoverflow.com/users/109538/broofa. + + +exports.newUUID = function () { + var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0, + v = c === 'x' ? r : r & 0x3 | 0x8; + return v.toString(16); + }); + return UUID; +}; + +exports.hostType = function (host) { + if (!host) { + return; + } else { + host = Grammar.parse(host, 'host'); + + if (host !== -1) { + return host.host_type; + } + } +}; +/** +* Hex-escape a SIP URI user. +* Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F). +* +* Used by 'normalizeTarget'. +*/ + + +var escapeUser = exports.escapeUser = function (user) { + return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/'); +}; +/** +* Normalize SIP URI. +* NOTE: It does not allow a SIP URI without username. +* Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'. +* Detects the domain part (if given) and properly hex-escapes the user portion. +* If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators. +*/ + + +exports.normalizeTarget = function (target, domain) { + // If no target is given then raise an error. + if (!target) { + return; // If a URI instance is given then return it. + } else if (target instanceof URI) { + return target; // If a string is given split it by '@': + // - Last fragment is the desired domain. + // - Otherwise append the given domain argument. + } else if (typeof target === 'string') { + var target_array = target.split('@'); + var target_user; + var target_domain; + + switch (target_array.length) { + case 1: + if (!domain) { + return; + } + + target_user = target; + target_domain = domain; + break; + + case 2: + target_user = target_array[0]; + target_domain = target_array[1]; + break; + + default: + target_user = target_array.slice(0, target_array.length - 1).join('@'); + target_domain = target_array[target_array.length - 1]; + } // Remove the URI scheme (if present). + + + target_user = target_user.replace(/^(sips?|tel):/i, ''); // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols. + + if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) { + target_user = target_user.replace(/[-.()]/g, ''); + } // Build the complete SIP URI. + + + target = "".concat(JsSIP_C.SIP, ":").concat(escapeUser(target_user), "@").concat(target_domain); // Finally parse the resulting URI. + + var uri; + + if (uri = URI.parse(target)) { + return uri; + } else { + return; + } + } else { + return; + } +}; + +exports.headerize = function (string) { + var exceptions = { + 'Call-Id': 'Call-ID', + 'Cseq': 'CSeq', + 'Www-Authenticate': 'WWW-Authenticate' + }; + var name = string.toLowerCase().replace(/_/g, '-').split('-'); + var hname = ''; + var parts = name.length; + var part; + + for (part = 0; part < parts; part++) { + if (part !== 0) { + hname += '-'; + } + + hname += name[part].charAt(0).toUpperCase() + name[part].substring(1); + } + + if (exceptions[hname]) { + hname = exceptions[hname]; + } + + return hname; +}; + +exports.sipErrorCause = function (status_code) { + for (var cause in JsSIP_C.SIP_ERROR_CAUSES) { + if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) { + return JsSIP_C.causes[cause]; + } + } + + return JsSIP_C.causes.SIP_FAILURE_CODE; +}; +/** +* Generate a random Test-Net IP (https://tools.ietf.org/html/rfc5735) +*/ + + +exports.getRandomTestNetIP = function () { + function getOctet(from, to) { + return Math.floor(Math.random() * (to - from + 1) + from); + } + + return "192.0.2.".concat(getOctet(1, 254)); +}; // MD5 (Message-Digest Algorithm) https://www.webtoolkit.info. + + +exports.calculateMD5 = function (string) { + function rotateLeft(lValue, iShiftBits) { + return lValue << iShiftBits | lValue >>> 32 - iShiftBits; + } + + function addUnsigned(lX, lY) { + var lX8 = lX & 0x80000000; + var lY8 = lY & 0x80000000; + var lX4 = lX & 0x40000000; + var lY4 = lY & 0x40000000; + var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); + + if (lX4 & lY4) { + return lResult ^ 0x80000000 ^ lX8 ^ lY8; + } + + if (lX4 | lY4) { + if (lResult & 0x40000000) { + return lResult ^ 0xC0000000 ^ lX8 ^ lY8; + } else { + return lResult ^ 0x40000000 ^ lX8 ^ lY8; + } + } else { + return lResult ^ lX8 ^ lY8; + } + } + + function doF(x, y, z) { + return x & y | ~x & z; + } + + function doG(x, y, z) { + return x & z | y & ~z; + } + + function doH(x, y, z) { + return x ^ y ^ z; + } + + function doI(x, y, z) { + return y ^ (x | ~z); + } + + function doFF(a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + } + + function doGG(a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + } + + function doHH(a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + } + + function doII(a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + } + + function convertToWordArray(str) { + var lWordCount; + var lMessageLength = str.length; + var lNumberOfWords_temp1 = lMessageLength + 8; + var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64; + var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; + var lWordArray = new Array(lNumberOfWords - 1); + var lBytePosition = 0; + var lByteCount = 0; + + while (lByteCount < lMessageLength) { + lWordCount = (lByteCount - lByteCount % 4) / 4; + lBytePosition = lByteCount % 4 * 8; + lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition; + lByteCount++; + } + + lWordCount = (lByteCount - lByteCount % 4) / 4; + lBytePosition = lByteCount % 4 * 8; + lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition; + lWordArray[lNumberOfWords - 2] = lMessageLength << 3; + lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; + return lWordArray; + } + + function wordToHex(lValue) { + var wordToHexValue = '', + wordToHexValue_temp = '', + lByte, + lCount; + + for (lCount = 0; lCount <= 3; lCount++) { + lByte = lValue >>> lCount * 8 & 255; + wordToHexValue_temp = "0".concat(lByte.toString(16)); + wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2); + } + + return wordToHexValue; + } + + function utf8Encode(str) { + str = str.replace(/\r\n/g, '\n'); + var utftext = ''; + + for (var n = 0; n < str.length; n++) { + var _c = str.charCodeAt(n); + + if (_c < 128) { + utftext += String.fromCharCode(_c); + } else if (_c > 127 && _c < 2048) { + utftext += String.fromCharCode(_c >> 6 | 192); + utftext += String.fromCharCode(_c & 63 | 128); + } else { + utftext += String.fromCharCode(_c >> 12 | 224); + utftext += String.fromCharCode(_c >> 6 & 63 | 128); + utftext += String.fromCharCode(_c & 63 | 128); + } + } + + return utftext; + } + + var x = []; + var k, AA, BB, CC, DD, a, b, c, d; + var S11 = 7, + S12 = 12, + S13 = 17, + S14 = 22; + var S21 = 5, + S22 = 9, + S23 = 14, + S24 = 20; + var S31 = 4, + S32 = 11, + S33 = 16, + S34 = 23; + var S41 = 6, + S42 = 10, + S43 = 15, + S44 = 21; + string = utf8Encode(string); + x = convertToWordArray(string); + a = 0x67452301; + b = 0xEFCDAB89; + c = 0x98BADCFE; + d = 0x10325476; + + for (k = 0; k < x.length; k += 16) { + AA = a; + BB = b; + CC = c; + DD = d; + a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478); + d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); + c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB); + b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); + a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); + d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A); + c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613); + b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501); + a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8); + d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); + c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); + b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); + a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122); + d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193); + c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E); + b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821); + a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562); + d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340); + c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51); + b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); + a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D); + d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453); + c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); + b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); + a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); + d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6); + c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); + b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED); + a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); + d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); + c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9); + b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); + a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); + d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681); + c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); + b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); + a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); + d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); + c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); + b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); + a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); + d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); + c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); + b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05); + a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); + d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); + c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); + b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); + a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244); + d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97); + c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7); + b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039); + a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3); + d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); + c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); + b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1); + a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); + d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); + c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314); + b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1); + a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82); + d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235); + c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); + b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391); + a = addUnsigned(a, AA); + b = addUnsigned(b, BB); + c = addUnsigned(c, CC); + d = addUnsigned(d, DD); + } + + var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); + return temp.toLowerCase(); +}; + +exports.closeMediaStream = function (stream) { + if (!stream) { + return; + } // Latest spec states that MediaStream has no stop() method and instead must + // call stop() on every MediaStreamTrack. + + + try { + var tracks; + + if (stream.getTracks) { + tracks = stream.getTracks(); + + var _iterator = _createForOfIteratorHelper(tracks), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var track = _step.value; + track.stop(); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } else { + tracks = stream.getAudioTracks(); + + var _iterator2 = _createForOfIteratorHelper(tracks), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var _track = _step2.value; + + _track.stop(); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + + tracks = stream.getVideoTracks(); + + var _iterator3 = _createForOfIteratorHelper(tracks), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _track2 = _step3.value; + + _track2.stop(); + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } + } catch (error) { + // Deprecated by the spec, but still in use. + // NOTE: In Temasys IE plugin stream.stop is a callable 'object'. + if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') { + stream.stop(); + } + } +}; + +exports.cloneArray = function (array) { + return array && array.slice() || []; +}; + +exports.cloneObject = function (obj) { + var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return obj && Object.assign({}, obj) || fallback; +}; +},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var Grammar = require('./Grammar'); + +var debug = require('debug')('JsSIP:WebSocketInterface'); + +var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); + +debugerror.log = console.warn.bind(console); + +module.exports = /*#__PURE__*/function () { + function WebSocketInterface(url) { + _classCallCheck(this, WebSocketInterface); + + debug('new() [url:"%s"]', url); + this._url = url; + this._sip_uri = null; + this._via_transport = null; + this._ws = null; + var parsed_url = Grammar.parse(url, 'absoluteURI'); + + if (parsed_url === -1) { + debugerror("invalid WebSocket URI: ".concat(url)); + throw new TypeError("Invalid argument: ".concat(url)); + } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { + debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); + throw new TypeError("Invalid argument: ".concat(url)); + } else { + this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws"); + this._via_transport = parsed_url.scheme.toUpperCase(); + } + } + + _createClass(WebSocketInterface, [{ + key: "via_transport", + get: function get() { + return this._via_transport; + }, + set: function set(value) { + this._via_transport = value.toUpperCase(); + } + }, { + key: "sip_uri", + get: function get() { + return this._sip_uri; + } + }, { + key: "url", + get: function get() { + return this._url; + } + }, { + key: "connect", + value: function connect() { + debug('connect()'); + + if (this.isConnected()) { + debug("WebSocket ".concat(this._url, " is already connected")); + return; + } else if (this.isConnecting()) { + debug("WebSocket ".concat(this._url, " is connecting")); + return; + } + + if (this._ws) { + this.disconnect(); + } + + debug("connecting to WebSocket ".concat(this._url)); + + try { + this._ws = new WebSocket(this._url, 'sip'); + this._ws.binaryType = 'arraybuffer'; + this._ws.onopen = this._onOpen.bind(this); + this._ws.onclose = this._onClose.bind(this); + this._ws.onmessage = this._onMessage.bind(this); + this._ws.onerror = this._onError.bind(this); + } catch (e) { + this._onError(e); + } + } + }, { + key: "disconnect", + value: function disconnect() { + debug('disconnect()'); + + if (this._ws) { + // Unbind websocket event callbacks. + 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 send(message) { + debug('send()'); + + if (this.isConnected()) { + this._ws.send(message); + + return true; + } else { + debugerror('unable to send message, WebSocket is not open'); + return false; + } + } + }, { + key: "isConnected", + value: function isConnected() { + return this._ws && this._ws.readyState === this._ws.OPEN; + } + }, { + key: "isConnecting", + value: function isConnecting() { + return this._ws && this._ws.readyState === this._ws.CONNECTING; + } + /** + * WebSocket Event Handlers + */ + + }, { + key: "_onOpen", + value: function _onOpen() { + debug("WebSocket ".concat(this._url, " connected")); + this.onconnect(); + } + }, { + key: "_onClose", + value: function _onClose(_ref) { + var wasClean = _ref.wasClean, + code = _ref.code, + reason = _ref.reason; + debug("WebSocket ".concat(this._url, " closed")); + + if (wasClean === false) { + debug('WebSocket abrupt disconnection'); + } + + this.ondisconnect(!wasClean, code, reason); + } + }, { + key: "_onMessage", + value: function _onMessage(_ref2) { + var data = _ref2.data; + debug('received WebSocket message'); + this.ondata(data); + } + }, { + key: "_onError", + value: function _onError(e) { + debugerror("WebSocket ".concat(this._url, " error: "), e); + } + }]); + + return WebSocketInterface; +}(); +},{"./Grammar":7,"debug":32}],30:[function(require,module,exports){ +"use strict"; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var JsSIP_C = require('./Constants'); + +var SIPMessage = require('./SIPMessage'); + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses. + + +var all = [minimumHeaders]; // Checks for requests. + +var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2]; // Checks for responses. + +var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response]; // local variables. + +var message; +var ua; +var transport; + +module.exports = function (m, u, t) { + message = m; + ua = u; + transport = t; + + var _iterator = _createForOfIteratorHelper(all), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var _check2 = _step.value; + + if (_check2() === false) { + return false; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + if (message instanceof SIPMessage.IncomingRequest) { + var _iterator2 = _createForOfIteratorHelper(requests), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var check = _step2.value; + + if (check() === false) { + return false; + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } else if (message instanceof SIPMessage.IncomingResponse) { + var _iterator3 = _createForOfIteratorHelper(responses), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _check = _step3.value; + + if (_check() === false) { + return false; + } + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } // Everything is OK. + + + return true; +}; +/* + * Sanity Check for incoming Messages + * + * Requests: + * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme + * - _rfc3261_16_3_4_ Receive a Request already sent by us + * Does not look at via sent-by but at jssip_id, which is inserted as + * a prefix in all initial requests generated by the ua + * - _rfc3261_18_3_request_ Body Content-Length + * - _rfc3261_8_2_2_2_ Merged Requests + * + * Responses: + * - _rfc3261_8_1_3_3_ Multiple Via headers + * - _rfc3261_18_3_response_ Body Content-Length + * + * All: + * - Minimum headers in a SIP message + */ +// Sanity Check functions for requests. + + +function rfc3261_8_2_2_1() { + if (message.s('to').uri.scheme !== 'sip') { + reply(416); + return false; + } +} + +function rfc3261_16_3_4() { + if (!message.to_tag) { + if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) { + reply(482); + return false; + } + } +} + +function rfc3261_18_3_request() { + var len = Utils.str_utf8_length(message.body); + var contentLength = message.getHeader('content-length'); + + if (len < contentLength) { + reply(400); + return false; + } +} + +function rfc3261_8_2_2_2() { + var fromTag = message.from_tag; + var call_id = message.call_id; + var cseq = message.cseq; + var tr; // Accept any in-dialog request. + + if (message.to_tag) { + return; + } // INVITE request. + + + if (message.method === JsSIP_C.INVITE) { + // If the branch matches the key of any IST then assume it is a retransmission + // and ignore the INVITE. + // TODO: we should reply the last response. + if (ua._transactions.ist[message.via_branch]) { + return false; + } // Otherwise check whether it is a merged request. + else { + for (var transaction in ua._transactions.ist) { + if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) { + tr = ua._transactions.ist[transaction]; + + if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) { + reply(482); + return false; + } + } + } + } + } // Non INVITE request. + // If the branch matches the key of any NIST then assume it is a retransmission + // and ignore the request. + // TODO: we should reply the last response. + else if (ua._transactions.nist[message.via_branch]) { + return false; + } // Otherwise check whether it is a merged request. + else { + for (var _transaction in ua._transactions.nist) { + if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) { + tr = ua._transactions.nist[_transaction]; + + if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) { + reply(482); + return false; + } + } + } + } +} // Sanity Check functions for responses. + + +function rfc3261_8_1_3_3() { + if (message.getHeaders('via').length > 1) { + debug('more than one Via header field present in the response, dropping the response'); + return false; + } +} + +function rfc3261_18_3_response() { + var len = Utils.str_utf8_length(message.body), + contentLength = message.getHeader('content-length'); + + if (len < contentLength) { + debug('message body length is lower than the value in Content-Length header field, dropping the response'); + return false; + } +} // Sanity Check functions for requests and responses. + + +function minimumHeaders() { + var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via']; + + for (var _i = 0, _mandatoryHeaders = mandatoryHeaders; _i < _mandatoryHeaders.length; _i++) { + var header = _mandatoryHeaders[_i]; + + if (!message.hasHeader(header)) { + debug("missing mandatory header field : ".concat(header, ", dropping the response")); + return false; + } + } +} // Reply. + + +function reply(status_code) { + var vias = message.getHeaders('via'); + var to; + var response = "SIP/2.0 ".concat(status_code, " ").concat(JsSIP_C.REASON_PHRASE[status_code], "\r\n"); + + var _iterator4 = _createForOfIteratorHelper(vias), + _step4; + + try { + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + var via = _step4.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); + } + + to = message.getHeader('To'); + + if (!message.to_tag) { + to += ";tag=".concat(Utils.newTag()); + } + + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(message.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(message.call_id, "\r\n"); + response += "CSeq: ".concat(message.cseq, " ").concat(message.method, "\r\n"); + response += '\r\n'; + transport.send(response); +} +},{"./Constants":2,"./SIPMessage":20,"./Utils":28,"debug":32}],31:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var objectCreate = Object.create || objectCreatePolyfill +var objectKeys = Object.keys || objectKeysPolyfill +var bind = Function.prototype.bind || functionBindPolyfill + +function EventEmitter() { + if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) { + this._events = objectCreate(null); + this._eventsCount = 0; + } + + this._maxListeners = this._maxListeners || undefined; +} +module.exports = EventEmitter; + +// Backwards-compat with node 0.10.x +EventEmitter.EventEmitter = EventEmitter; + +EventEmitter.prototype._events = undefined; +EventEmitter.prototype._maxListeners = undefined; + +// By default EventEmitters will print a warning if more than 10 listeners are +// added to it. This is a useful default which helps finding memory leaks. +var defaultMaxListeners = 10; + +var hasDefineProperty; +try { + var o = {}; + if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 }); + hasDefineProperty = o.x === 0; +} catch (err) { hasDefineProperty = false } +if (hasDefineProperty) { + Object.defineProperty(EventEmitter, 'defaultMaxListeners', { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + // check whether the input is a positive number (whose value is zero or + // greater and not a NaN). + if (typeof arg !== 'number' || arg < 0 || arg !== arg) + throw new TypeError('"defaultMaxListeners" must be a positive number'); + defaultMaxListeners = arg; + } + }); +} else { + EventEmitter.defaultMaxListeners = defaultMaxListeners; +} + +// Obviously not all Emitters should be limited to 10. This function allows +// that to be increased. Set to zero for unlimited. +EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== 'number' || n < 0 || isNaN(n)) + throw new TypeError('"n" argument must be a positive number'); + this._maxListeners = n; + return this; +}; + +function $getMaxListeners(that) { + if (that._maxListeners === undefined) + return EventEmitter.defaultMaxListeners; + return that._maxListeners; +} + +EventEmitter.prototype.getMaxListeners = function getMaxListeners() { + return $getMaxListeners(this); +}; + +// These standalone emit* functions are used to optimize calling of event +// handlers for fast cases because emit() itself often has a variable number of +// arguments and can be deoptimized because of that. These functions always have +// the same number of arguments and thus do not get deoptimized, so the code +// inside them can execute faster. +function emitNone(handler, isFn, self) { + if (isFn) + handler.call(self); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self); + } +} +function emitOne(handler, isFn, self, arg1) { + if (isFn) + handler.call(self, arg1); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1); + } +} +function emitTwo(handler, isFn, self, arg1, arg2) { + if (isFn) + handler.call(self, arg1, arg2); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1, arg2); + } +} +function emitThree(handler, isFn, self, arg1, arg2, arg3) { + if (isFn) + handler.call(self, arg1, arg2, arg3); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1, arg2, arg3); + } +} + +function emitMany(handler, isFn, self, args) { + if (isFn) + handler.apply(self, args); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].apply(self, args); + } +} + +EventEmitter.prototype.emit = function emit(type) { + var er, handler, len, args, i, events; + var doError = (type === 'error'); + + events = this._events; + if (events) + doError = (doError && events.error == null); + else if (!doError) + return false; + + // If there is no 'error' event listener then throw. + if (doError) { + if (arguments.length > 1) + er = arguments[1]; + if (er instanceof Error) { + throw er; // Unhandled 'error' event + } else { + // At least give some kind of context to the user + var err = new Error('Unhandled "error" event. (' + er + ')'); + err.context = er; + throw err; + } + return false; + } + + handler = events[type]; + + if (!handler) + return false; + + var isFn = typeof handler === 'function'; + len = arguments.length; + switch (len) { + // fast cases + case 1: + emitNone(handler, isFn, this); + break; + case 2: + emitOne(handler, isFn, this, arguments[1]); + break; + case 3: + emitTwo(handler, isFn, this, arguments[1], arguments[2]); + break; + case 4: + emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]); + break; + // slower + default: + args = new Array(len - 1); + for (i = 1; i < len; i++) + args[i - 1] = arguments[i]; + emitMany(handler, isFn, this, args); + } + + return true; +}; + +function _addListener(target, type, listener, prepend) { + var m; + var events; + var existing; + + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + + events = target._events; + if (!events) { + events = target._events = objectCreate(null); + target._eventsCount = 0; + } else { + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (events.newListener) { + target.emit('newListener', type, + listener.listener ? listener.listener : listener); + + // Re-assign `events` because a newListener handler could have caused the + // this._events to be assigned to a new object + events = target._events; + } + existing = events[type]; + } + + if (!existing) { + // Optimize the case of one listener. Don't need the extra array object. + existing = events[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === 'function') { + // Adding the second element, need to change to array. + existing = events[type] = + prepend ? [listener, existing] : [existing, listener]; + } else { + // If we've already got an array, just append. + if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + } + + // Check for listener leak + if (!existing.warned) { + m = $getMaxListeners(target); + if (m && m > 0 && existing.length > m) { + existing.warned = true; + var w = new Error('Possible EventEmitter memory leak detected. ' + + existing.length + ' "' + String(type) + '" listeners ' + + 'added. Use emitter.setMaxListeners() to ' + + 'increase limit.'); + w.name = 'MaxListenersExceededWarning'; + w.emitter = target; + w.type = type; + w.count = existing.length; + if (typeof console === 'object' && console.warn) { + console.warn('%s: %s', w.name, w.message); + } + } + } + } + + return target; +} + +EventEmitter.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); +}; + +EventEmitter.prototype.on = EventEmitter.prototype.addListener; + +EventEmitter.prototype.prependListener = + function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + +function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + switch (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: + var args = new Array(arguments.length); + for (var i = 0; i < args.length; ++i) + args[i] = arguments[i]; + this.listener.apply(this.target, args); + } + } +} + +function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener }; + var wrapped = bind.call(onceWrapper, state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; +} + +EventEmitter.prototype.once = function once(type, listener) { + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + this.on(type, _onceWrap(this, type, listener)); + return this; +}; + +EventEmitter.prototype.prependOnceListener = + function prependOnceListener(type, listener) { + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + +// Emits a 'removeListener' event if and only if the listener was removed. +EventEmitter.prototype.removeListener = + function removeListener(type, listener) { + var list, events, position, i, originalListener; + + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + + events = this._events; + if (!events) + return this; + + list = events[type]; + if (!list) + return this; + + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = objectCreate(null); + else { + delete events[type]; + if (events.removeListener) + this.emit('removeListener', type, list.listener || listener); + } + } else if (typeof list !== 'function') { + position = -1; + + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + + if (position < 0) + return this; + + if (position === 0) + list.shift(); + else + spliceOne(list, position); + + if (list.length === 1) + events[type] = list[0]; + + if (events.removeListener) + this.emit('removeListener', type, originalListener || listener); + } + + return this; + }; + +EventEmitter.prototype.removeAllListeners = + function removeAllListeners(type) { + var listeners, events, i; + + events = this._events; + if (!events) + return this; + + // not listening for removeListener, no need to emit + if (!events.removeListener) { + if (arguments.length === 0) { + this._events = objectCreate(null); + this._eventsCount = 0; + } else if (events[type]) { + if (--this._eventsCount === 0) + this._events = objectCreate(null); + else + delete events[type]; + } + return this; + } + + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + var keys = objectKeys(events); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === 'removeListener') continue; + this.removeAllListeners(key); + } + this.removeAllListeners('removeListener'); + this._events = objectCreate(null); + this._eventsCount = 0; + return this; + } + + listeners = events[type]; + + if (typeof listeners === 'function') { + this.removeListener(type, listeners); + } else if (listeners) { + // LIFO order + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + + return this; + }; + +function _listeners(target, type, unwrap) { + var events = target._events; + + if (!events) + return []; + + var evlistener = events[type]; + if (!evlistener) + return []; + + if (typeof evlistener === 'function') + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); +} + +EventEmitter.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); +}; + +EventEmitter.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); +}; + +EventEmitter.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === 'function') { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } +}; + +EventEmitter.prototype.listenerCount = listenerCount; +function listenerCount(type) { + var events = this._events; + + if (events) { + var evlistener = events[type]; + + if (typeof evlistener === 'function') { + return 1; + } else if (evlistener) { + return evlistener.length; + } + } + + return 0; +} + +EventEmitter.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : []; +}; + +// About 1.5x faster than the two-arg version of Array#splice(). +function spliceOne(list, index) { + for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) + list[i] = list[k]; + list.pop(); +} + +function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; +} + +function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; +} + +function objectCreatePolyfill(proto) { + var F = function() {}; + F.prototype = proto; + return new F; +} +function objectKeysPolyfill(obj) { + var keys = []; + for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) { + keys.push(k); + } + return k; +} +function functionBindPolyfill(context) { + var fn = this; + return function () { + return fn.apply(context, arguments); + }; +} + +},{}],32:[function(require,module,exports){ +(function (process){(function (){ +/* eslint-env browser */ + +/** + * This is the web browser implementation of `debug()`. + */ + +exports.formatArgs = formatArgs; +exports.save = save; +exports.load = load; +exports.useColors = useColors; +exports.storage = localstorage(); +exports.destroy = (() => { + let warned = false; + + return () => { + if (!warned) { + warned = true; + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + }; +})(); + +/** + * Colors. + */ + +exports.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' +]; + +/** + * Currently only WebKit-based Web Inspectors, Firefox >= v31, + * and the Firebug extension (any Firefox version) are known + * to support "%c" CSS customizations. + * + * TODO: add a `localStorage` variable to explicitly enable/disable colors + */ + +// eslint-disable-next-line complexity +function useColors() { + // NB: In an Electron preload script, document will be defined but not fully + // initialized. Since we know we're in Chrome, we'll just detect this case + // explicitly + if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { + return true; + } + + // Internet Explorer and Edge do not support colors. + if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { + return false; + } + + // Is webkit? http://stackoverflow.com/a/16459606/376773 + // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 + return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || + // Is firebug? http://stackoverflow.com/a/398120/376773 + (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || + // Is firefox >= v31? + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || + // Double check webkit in userAgent just in case we are in a worker + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); +} + +/** + * Colorize log arguments if enabled. + * + * @api public + */ + +function formatArgs(args) { + args[0] = (this.useColors ? '%c' : '') + + this.namespace + + (this.useColors ? ' %c' : ' ') + + args[0] + + (this.useColors ? '%c ' : ' ') + + '+' + module.exports.humanize(this.diff); + + if (!this.useColors) { + return; + } + + const c = 'color: ' + this.color; + args.splice(1, 0, c, 'color: inherit'); + + // The final "%c" is somewhat tricky, because there could be other + // arguments passed either before or after the %c, so we need to + // figure out the correct index to insert the CSS into + let index = 0; + let lastC = 0; + args[0].replace(/%[a-zA-Z%]/g, match => { + if (match === '%%') { + return; + } + index++; + if (match === '%c') { + // We only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; + } + }); + + args.splice(lastC, 0, c); +} + +/** + * Invokes `console.debug()` when available. + * No-op when `console.debug` is not a "function". + * If `console.debug` is not available, falls back + * to `console.log`. + * + * @api public + */ +exports.log = console.debug || console.log || (() => {}); + +/** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ +function save(namespaces) { + try { + if (namespaces) { + exports.storage.setItem('debug', namespaces); + } else { + exports.storage.removeItem('debug'); + } + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } +} + +/** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ +function load() { + let r; + try { + r = exports.storage.getItem('debug'); + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } + + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + if (!r && typeof process !== 'undefined' && 'env' in process) { + r = process.env.DEBUG; + } + + return r; +} + +/** + * Localstorage attempts to return the localstorage. + * + * This is necessary because safari throws + * when a user disables cookies/localstorage + * and you attempt to access it. + * + * @return {LocalStorage} + * @api private + */ + +function localstorage() { + try { + // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context + // The Browser also has localStorage in the global context. + return localStorage; + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } +} + +module.exports = require('./common')(exports); + +const {formatters} = module.exports; + +/** + * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. + */ + +formatters.j = function (v) { + try { + return JSON.stringify(v); + } catch (error) { + return '[UnexpectedJSONParseError]: ' + error.message; + } +}; + +}).call(this)}).call(this,require('_process')) +},{"./common":33,"_process":35}],33:[function(require,module,exports){ + +/** + * This is the common logic for both the Node.js and web browser + * implementations of `debug()`. + */ + +function setup(env) { + createDebug.debug = createDebug; + createDebug.default = createDebug; + createDebug.coerce = coerce; + createDebug.disable = disable; + createDebug.enable = enable; + createDebug.enabled = enabled; + createDebug.humanize = require('ms'); + createDebug.destroy = destroy; + + Object.keys(env).forEach(key => { + createDebug[key] = env[key]; + }); + + /** + * The currently active debug mode names, and names to skip. + */ + + createDebug.names = []; + createDebug.skips = []; + + /** + * Map of special "%n" handling functions, for the debug "format" argument. + * + * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". + */ + createDebug.formatters = {}; + + /** + * Selects a color for a debug namespace + * @param {String} namespace The namespace string for the for the debug instance to be colored + * @return {Number|String} An ANSI color code for the given namespace + * @api private + */ + function selectColor(namespace) { + let hash = 0; + + for (let i = 0; i < namespace.length; i++) { + hash = ((hash << 5) - hash) + namespace.charCodeAt(i); + hash |= 0; // Convert to 32bit integer + } + + return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; + } + createDebug.selectColor = selectColor; + + /** + * Create a debugger with the given `namespace`. + * + * @param {String} namespace + * @return {Function} + * @api public + */ + function createDebug(namespace) { + let prevTime; + let enableOverride = null; + + function debug(...args) { + // Disabled? + if (!debug.enabled) { + return; + } + + const self = debug; + + // Set `diff` timestamp + const curr = Number(new Date()); + const ms = curr - (prevTime || curr); + self.diff = ms; + self.prev = prevTime; + self.curr = curr; + prevTime = curr; + + args[0] = createDebug.coerce(args[0]); + + if (typeof args[0] !== 'string') { + // Anything else let's inspect with %O + args.unshift('%O'); + } + + // Apply any `formatters` transformations + let index = 0; + args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { + // If we encounter an escaped % then don't increase the array index + if (match === '%%') { + return '%'; + } + index++; + const formatter = createDebug.formatters[format]; + if (typeof formatter === 'function') { + const val = args[index]; + match = formatter.call(self, val); + + // Now we need to remove `args[index]` since it's inlined in the `format` + args.splice(index, 1); + index--; + } + return match; + }); + + // Apply env-specific formatting (colors, etc.) + createDebug.formatArgs.call(self, args); + + const logFn = self.log || createDebug.log; + logFn.apply(self, args); + } + + debug.namespace = namespace; + debug.useColors = createDebug.useColors(); + debug.color = createDebug.selectColor(namespace); + debug.extend = extend; + debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. + + Object.defineProperty(debug, 'enabled', { + enumerable: true, + configurable: false, + get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, + set: v => { + enableOverride = v; + } + }); + + // Env-specific initialization logic for debug instances + if (typeof createDebug.init === 'function') { + createDebug.init(debug); + } + + return debug; + } + + function extend(namespace, delimiter) { + const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); + newDebug.log = this.log; + return newDebug; + } + + /** + * Enables a debug mode by namespaces. This can include modes + * separated by a colon and wildcards. + * + * @param {String} namespaces + * @api public + */ + function enable(namespaces) { + createDebug.save(namespaces); + + createDebug.names = []; + createDebug.skips = []; + + let i; + const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); + const len = split.length; + + for (i = 0; i < len; i++) { + if (!split[i]) { + // ignore empty strings + continue; + } + + namespaces = split[i].replace(/\*/g, '.*?'); + + if (namespaces[0] === '-') { + createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); + } else { + createDebug.names.push(new RegExp('^' + namespaces + '$')); + } + } + } + + /** + * Disable debug output. + * + * @return {String} namespaces + * @api public + */ + function disable() { + const namespaces = [ + ...createDebug.names.map(toNamespace), + ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace) + ].join(','); + createDebug.enable(''); + return namespaces; + } + + /** + * Returns true if the given mode name is enabled, false otherwise. + * + * @param {String} name + * @return {Boolean} + * @api public + */ + function enabled(name) { + if (name[name.length - 1] === '*') { + return true; + } + + let i; + let len; + + for (i = 0, len = createDebug.skips.length; i < len; i++) { + if (createDebug.skips[i].test(name)) { + return false; + } + } + + for (i = 0, len = createDebug.names.length; i < len; i++) { + if (createDebug.names[i].test(name)) { + return true; + } + } + + return false; + } + + /** + * Convert regexp to namespace + * + * @param {RegExp} regxep + * @return {String} namespace + * @api private + */ + function toNamespace(regexp) { + return regexp.toString() + .substring(2, regexp.toString().length - 2) + .replace(/\.\*\?$/, '*'); + } + + /** + * Coerce `val`. + * + * @param {Mixed} val + * @return {Mixed} + * @api private + */ + function coerce(val) { + if (val instanceof Error) { + return val.stack || val.message; + } + return val; + } + + /** + * XXX DO NOT USE. This is a temporary stub function. + * XXX It WILL be removed in the next major release. + */ + function destroy() { + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + + createDebug.enable(createDebug.load()); + + return createDebug; +} + +module.exports = setup; + +},{"ms":34}],34:[function(require,module,exports){ +/** + * Helpers. + */ + +var s = 1000; +var m = s * 60; +var h = m * 60; +var d = h * 24; +var w = d * 7; +var y = d * 365.25; + +/** + * Parse or format the given `val`. + * + * Options: + * + * - `long` verbose formatting [false] + * + * @param {String|Number} val + * @param {Object} [options] + * @throws {Error} throw an error if val is not a non-empty string or a number + * @return {String|Number} + * @api public + */ + +module.exports = function(val, options) { + options = options || {}; + var type = typeof val; + if (type === 'string' && val.length > 0) { + return parse(val); + } else if (type === 'number' && isFinite(val)) { + return options.long ? fmtLong(val) : fmtShort(val); + } + throw new Error( + 'val is not a non-empty string or a valid number. val=' + + JSON.stringify(val) + ); +}; + +/** + * Parse the given `str` and return milliseconds. + * + * @param {String} str + * @return {Number} + * @api private + */ + +function parse(str) { + str = String(str); + if (str.length > 100) { + return; + } + var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( + str + ); + if (!match) { + return; + } + var n = parseFloat(match[1]); + var type = (match[2] || 'ms').toLowerCase(); + switch (type) { + case 'years': + case 'year': + case 'yrs': + case 'yr': + case 'y': + return n * y; + case 'weeks': + case 'week': + case 'w': + return n * w; + case 'days': + case 'day': + case 'd': + return n * d; + case 'hours': + case 'hour': + case 'hrs': + case 'hr': + case 'h': + return n * h; + case 'minutes': + case 'minute': + case 'mins': + case 'min': + case 'm': + return n * m; + case 'seconds': + case 'second': + case 'secs': + case 'sec': + case 's': + return n * s; + case 'milliseconds': + case 'millisecond': + case 'msecs': + case 'msec': + case 'ms': + return n; + default: + return undefined; + } +} + +/** + * Short format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtShort(ms) { + var msAbs = Math.abs(ms); + if (msAbs >= d) { + return Math.round(ms / d) + 'd'; + } + if (msAbs >= h) { + return Math.round(ms / h) + 'h'; + } + if (msAbs >= m) { + return Math.round(ms / m) + 'm'; + } + if (msAbs >= s) { + return Math.round(ms / s) + 's'; + } + return ms + 'ms'; +} + +/** + * Long format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtLong(ms) { + var msAbs = Math.abs(ms); + if (msAbs >= d) { + return plural(ms, msAbs, d, 'day'); + } + if (msAbs >= h) { + return plural(ms, msAbs, h, 'hour'); + } + if (msAbs >= m) { + return plural(ms, msAbs, m, 'minute'); + } + if (msAbs >= s) { + return plural(ms, msAbs, s, 'second'); + } + return ms + ' ms'; +} + +/** + * Pluralization helper. + */ + +function plural(ms, msAbs, n, name) { + var isPlural = msAbs >= n * 1.5; + return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); +} + +},{}],35:[function(require,module,exports){ +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + +},{}],36:[function(require,module,exports){ +var grammar = module.exports = { + v: [{ + name: 'version', + reg: /^(\d*)$/ + }], + o: [{ + // o=- 20518 0 IN IP4 203.0.113.1 + // NB: sessionId will be a String in most cases because it is huge + 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' + }], + // default parsing of these only (though some of these feel outdated) + s: [{ name: 'name' }], + i: [{ name: 'description' }], + u: [{ name: 'uri' }], + e: [{ name: 'email' }], + p: [{ name: 'phone' }], + z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly... + r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly + // k: [{}], // outdated thing ignored + t: [{ + // t=0 0 + name: 'timing', + reg: /^(\d*) (\d*)/, + names: ['start', 'stop'], + format: '%d %d' + }], + c: [{ + // c=IN IP4 10.47.197.26 + name: 'connection', + reg: /^IN IP(\d) (\S*)/, + names: ['version', 'ip'], + format: 'IN IP%d %s' + }], + b: [{ + // b=AS:4000 + push: 'bandwidth', + reg: /^(TIAS|AS|CT|RR|RS):(\d*)/, + names: ['type', 'limit'], + format: '%s:%s' + }], + m: [{ + // m=video 51744 RTP/AVP 126 97 98 34 31 + // NB: special - pushes to session + // TODO: rtp/fmtp should be filtered by the payloads found here? + reg: /^(\w*) (\d*) ([\w/]*)(?: (.*))?/, + names: ['type', 'port', 'protocol', 'payloads'], + format: '%s %d %s %s' + }], + a: [ + { + // a=rtpmap:110 opus/48000/2 + push: 'rtp', + reg: /^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/, + names: ['payload', 'codec', 'rate', 'encoding'], + format: function (o) { + return (o.encoding) + ? 'rtpmap:%d %s/%s/%s' + : o.rate + ? 'rtpmap:%d %s/%s' + : 'rtpmap:%d %s'; + } + }, + { + // a=fmtp:108 profile-level-id=24;object=23;bitrate=64000 + // a=fmtp:111 minptime=10; useinbandfec=1 + push: 'fmtp', + reg: /^fmtp:(\d*) ([\S| ]*)/, + names: ['payload', 'config'], + format: 'fmtp:%d %s' + }, + { + // a=control:streamid=0 + name: 'control', + reg: /^control:(.*)/, + format: 'control:%s' + }, + { + // a=rtcp:65179 IN IP4 193.84.77.194 + name: 'rtcp', + reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/, + names: ['port', 'netType', 'ipVer', 'address'], + format: function (o) { + return (o.address != null) + ? 'rtcp:%d %s IP%d %s' + : 'rtcp:%d'; + } + }, + { + // a=rtcp-fb:98 trr-int 100 + push: 'rtcpFbTrrInt', + reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, + names: ['payload', 'value'], + format: 'rtcp-fb:%s trr-int %d' + }, + { + // a=rtcp-fb:98 nack rpsi + push: 'rtcpFb', + reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/, + names: ['payload', 'type', 'subtype'], + format: function (o) { + return (o.subtype != null) + ? 'rtcp-fb:%s %s %s' + : 'rtcp-fb:%s %s'; + } + }, + { + // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset + // a=extmap:1/recvonly URI-gps-string + // a=extmap:3 urn:ietf:params:rtp-hdrext:encrypt urn:ietf:params:rtp-hdrext:smpte-tc 25@600/24 + push: 'ext', + reg: /^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/, + names: ['value', 'direction', 'encrypt-uri', 'uri', 'config'], + format: function (o) { + return ( + 'extmap:%d' + + (o.direction ? '/%s' : '%v') + + (o['encrypt-uri'] ? ' %s' : '%v') + + ' %s' + + (o.config ? ' %s' : '') + ); + } + }, + { + // a=extmap-allow-mixed + name: 'extmapAllowMixed', + reg: /^(extmap-allow-mixed)/ + }, + { + // a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32 + push: 'crypto', + reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/, + names: ['id', 'suite', 'config', 'sessionConfig'], + format: function (o) { + return (o.sessionConfig != null) + ? 'crypto:%d %s %s %s' + : 'crypto:%d %s %s'; + } + }, + { + // a=setup:actpass + name: 'setup', + reg: /^setup:(\w*)/, + format: 'setup:%s' + }, + { + // a=connection:new + name: 'connectionType', + reg: /^connection:(new|existing)/, + format: 'connection:%s' + }, + { + // a=mid:1 + name: 'mid', + reg: /^mid:([^\s]*)/, + format: 'mid:%s' + }, + { + // a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a + name: 'msid', + reg: /^msid:(.*)/, + format: 'msid:%s' + }, + { + // a=ptime:20 + name: 'ptime', + reg: /^ptime:(\d*(?:\.\d*)*)/, + format: 'ptime:%d' + }, + { + // a=maxptime:60 + name: 'maxptime', + reg: /^maxptime:(\d*(?:\.\d*)*)/, + format: 'maxptime:%d' + }, + { + // a=sendrecv + name: 'direction', + reg: /^(sendrecv|recvonly|sendonly|inactive)/ + }, + { + // a=ice-lite + name: 'icelite', + reg: /^(ice-lite)/ + }, + { + // a=ice-ufrag:F7gI + name: 'iceUfrag', + reg: /^ice-ufrag:(\S*)/, + format: 'ice-ufrag:%s' + }, + { + // a=ice-pwd:x9cml/YzichV2+XlhiMu8g + name: 'icePwd', + reg: /^ice-pwd:(\S*)/, + format: 'ice-pwd:%s' + }, + { + // a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33 + name: 'fingerprint', + reg: /^fingerprint:(\S*) (\S*)/, + names: ['type', 'hash'], + format: 'fingerprint:%s %s' + }, + { + // a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host + // a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10 + // a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0 network-id 3 network-cost 10 + // a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10 + // a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0 network-id 3 network-cost 10 + 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 (o) { + var str = 'candidate:%s %d %s %d %s %d typ %s'; + + str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v'; + + // NB: candidate has three optional chunks, so %void middles one if it's missing + str += (o.tcptype != null) ? ' tcptype %s' : '%v'; + + if (o.generation != null) { + str += ' generation %d'; + } + + str += (o['network-id'] != null) ? ' network-id %d' : '%v'; + str += (o['network-cost'] != null) ? ' network-cost %d' : '%v'; + return str; + } + }, + { + // a=end-of-candidates (keep after the candidates line for readability) + name: 'endOfCandidates', + reg: /^(end-of-candidates)/ + }, + { + // a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ... + name: 'remoteCandidates', + reg: /^remote-candidates:(.*)/, + format: 'remote-candidates:%s' + }, + { + // a=ice-options:google-ice + name: 'iceOptions', + reg: /^ice-options:(\S*)/, + format: 'ice-options:%s' + }, + { + // a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1 + push: 'ssrcs', + reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/, + names: ['id', 'attribute', 'value'], + format: function (o) { + var str = 'ssrc:%d'; + if (o.attribute != null) { + str += ' %s'; + if (o.value != null) { + str += ':%s'; + } + } + return str; + } + }, + { + // a=ssrc-group:FEC 1 2 + // a=ssrc-group:FEC-FR 3004364195 1080772241 + push: 'ssrcGroups', + // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E + reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/, + names: ['semantics', 'ssrcs'], + format: 'ssrc-group:%s %s' + }, + { + // a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV + name: 'msidSemantic', + reg: /^msid-semantic:\s?(\w*) (\S*)/, + names: ['semantic', 'token'], + format: 'msid-semantic: %s %s' // space after ':' is not accidental + }, + { + // a=group:BUNDLE audio video + push: 'groups', + reg: /^group:(\w*) (.*)/, + names: ['type', 'mids'], + format: 'group:%s %s' + }, + { + // a=rtcp-mux + name: 'rtcpMux', + reg: /^(rtcp-mux)/ + }, + { + // a=rtcp-rsize + name: 'rtcpRsize', + reg: /^(rtcp-rsize)/ + }, + { + // a=sctpmap:5000 webrtc-datachannel 1024 + name: 'sctpmap', + reg: /^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/, + names: ['sctpmapNumber', 'app', 'maxMessageSize'], + format: function (o) { + return (o.maxMessageSize != null) + ? 'sctpmap:%s %s %s' + : 'sctpmap:%s %s'; + } + }, + { + // a=x-google-flag:conference + name: 'xGoogleFlag', + reg: /^x-google-flag:([^\s]*)/, + format: 'x-google-flag:%s' + }, + { + // a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0 + push: 'rids', + reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/, + names: ['id', 'direction', 'params'], + format: function (o) { + return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s'; + } + }, + { + // a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250] + // a=imageattr:* send [x=800,y=640] recv * + // a=imageattr:100 recv [x=320,y=240] + push: 'imageattrs', + reg: new RegExp( + // a=imageattr:97 + '^imageattr:(\\d+|\\*)' + + // send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] + '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' + + // recv [x=330,y=250] + '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?' + ), + names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'], + format: function (o) { + return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : ''); + } + }, + { + // a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8 + // a=simulcast:recv 1;4,5 send 6;7 + name: 'simulcast', + reg: new RegExp( + // a=simulcast: + '^simulcast:' + + // send 1,2,3;~4,~5 + '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' + + // space + recv 6;~7,~8 + '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' + + // end + '$' + ), + names: ['dir1', 'list1', 'dir2', 'list2'], + format: function (o) { + return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : ''); + } + }, + { + // old simulcast draft 03 (implemented by Firefox) + // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03 + // a=simulcast: recv pt=97;98 send pt=97 + // a=simulcast: send rid=5;6;7 paused=6,7 + name: 'simulcast_03', + reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/, + names: ['value'], + format: 'simulcast: %s' + }, + { + // a=framerate:25 + // a=framerate:29.97 + name: 'framerate', + reg: /^framerate:(\d+(?:$|\.\d+))/, + format: 'framerate:%s' + }, + { + // RFC4570 + // a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5 + 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' + }, + { + // a=bundle-only + name: 'bundleOnly', + reg: /^(bundle-only)/ + }, + { + // a=label:1 + name: 'label', + reg: /^label:(.+)/, + format: 'label:%s' + }, + { + // RFC version 26 for SCTP over DTLS + // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5 + name: 'sctpPort', + reg: /^sctp-port:(\d+)$/, + format: 'sctp-port:%s' + }, + { + // RFC version 26 for SCTP over DTLS + // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6 + name: 'maxMessageSize', + reg: /^max-message-size:(\d+)$/, + format: 'max-message-size:%s' + }, + { + // RFC7273 + // a=ts-refclk:ptp=IEEE1588-2008:39-A7-94-FF-FE-07-CB-D0:37 + push:'tsRefClocks', + reg: /^ts-refclk:([^\s=]*)(?:=(\S*))?/, + names: ['clksrc', 'clksrcExt'], + format: function (o) { + return 'ts-refclk:%s' + (o.clksrcExt != null ? '=%s' : ''); + } + }, + { + // RFC7273 + // a=mediaclk:direct=963214424 + name:'mediaClk', + reg: /^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/, + names: ['id', 'mediaClockName', 'mediaClockValue', 'rateNumerator', 'rateDenominator'], + format: function (o) { + var str = 'mediaclk:'; + str += (o.id != null ? 'id=%s %s' : '%v%s'); + str += (o.mediaClockValue != null ? '=%s' : ''); + str += (o.rateNumerator != null ? ' rate=%s' : ''); + str += (o.rateDenominator != null ? '/%s' : ''); + return str; + } + }, + { + // a=keywds:keywords + name: 'keywords', + reg: /^keywds:(.+)$/, + format: 'keywds:%s' + }, + { + // a=content:main + name: 'content', + reg: /^content:(.+)/, + format: 'content:%s' + }, + // BFCP https://tools.ietf.org/html/rfc4583 + { + // a=floorctrl:c-s + name: 'bfcpFloorCtrl', + reg: /^floorctrl:(c-only|s-only|c-s)/, + format: 'floorctrl:%s' + }, + { + // a=confid:1 + name: 'bfcpConfId', + reg: /^confid:(\d+)/, + format: 'confid:%s' + }, + { + // a=userid:1 + name: 'bfcpUserId', + reg: /^userid:(\d+)/, + format: 'userid:%s' + }, + { + // a=floorid:1 + name: 'bfcpFloorId', + reg: /^floorid:(.+) (?:m-stream|mstrm):(.+)/, + names: ['id', 'mStream'], + format: 'floorid:%s mstrm:%s' + }, + { + // any a= that we don't understand is kept verbatim on media.invalid + push: 'invalid', + names: ['value'] + } + ] +}; + +// set sensible defaults to avoid polluting the grammar with boring details +Object.keys(grammar).forEach(function (key) { + var objs = grammar[key]; + objs.forEach(function (obj) { + if (!obj.reg) { + obj.reg = /(.*)/; + } + if (!obj.format) { + obj.format = '%s'; + } + }); +}); + +},{}],37:[function(require,module,exports){ +var parser = require('./parser'); +var writer = require('./writer'); + +exports.write = writer; +exports.parse = parser.parse; +exports.parseParams = parser.parseParams; +exports.parseFmtpConfig = parser.parseFmtpConfig; // Alias of parseParams(). +exports.parsePayloads = parser.parsePayloads; +exports.parseRemoteCandidates = parser.parseRemoteCandidates; +exports.parseImageAttributes = parser.parseImageAttributes; +exports.parseSimulcastStreamList = parser.parseSimulcastStreamList; + +},{"./parser":38,"./writer":39}],38:[function(require,module,exports){ +var toIntIfInt = function (v) { + return String(Number(v)) === v ? Number(v) : v; +}; + +var attachProperties = function (match, location, names, rawName) { + if (rawName && !names) { + location[rawName] = toIntIfInt(match[1]); + } + else { + for (var i = 0; i < names.length; i += 1) { + if (match[i+1] != null) { + location[names[i]] = toIntIfInt(match[i+1]); + } + } + } +}; + +var parseReg = function (obj, location, content) { + var needsBlank = obj.name && obj.names; + if (obj.push && !location[obj.push]) { + location[obj.push] = []; + } + else if (needsBlank && !location[obj.name]) { + location[obj.name] = {}; + } + var keyLocation = obj.push ? + {} : // blank object that will be pushed + needsBlank ? location[obj.name] : location; // otherwise, named location or root + + attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name); + + if (obj.push) { + location[obj.push].push(keyLocation); + } +}; + +var grammar = require('./grammar'); +var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/); + +exports.parse = function (sdp) { + var session = {} + , media = [] + , location = session; // points at where properties go under (one of the above) + + // parse lines we understand + sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) { + var type = l[0]; + var content = l.slice(2); + if (type === 'm') { + media.push({rtp: [], fmtp: []}); + location = media[media.length-1]; // point at latest media line + } + + for (var j = 0; j < (grammar[type] || []).length; j += 1) { + var obj = grammar[type][j]; + if (obj.reg.test(content)) { + return parseReg(obj, location, content); + } + } + }); + + session.media = media; // link it up + return session; +}; + +var paramReducer = function (acc, expr) { + var s = expr.split(/=(.+)/, 2); + if (s.length === 2) { + acc[s[0]] = toIntIfInt(s[1]); + } else if (s.length === 1 && expr.length > 1) { + acc[s[0]] = undefined; + } + return acc; +}; + +exports.parseParams = function (str) { + return str.split(/;\s?/).reduce(paramReducer, {}); +}; + +// For backward compatibility - alias will be removed in 3.0.0 +exports.parseFmtpConfig = exports.parseParams; + +exports.parsePayloads = function (str) { + return str.toString().split(' ').map(Number); +}; + +exports.parseRemoteCandidates = function (str) { + var candidates = []; + var parts = str.split(' ').map(toIntIfInt); + for (var i = 0; i < parts.length; i += 3) { + candidates.push({ + component: parts[i], + ip: parts[i + 1], + port: parts[i + 2] + }); + } + return candidates; +}; + +exports.parseImageAttributes = function (str) { + return str.split(' ').map(function (item) { + return item.substring(1, item.length-1).split(',').reduce(paramReducer, {}); + }); +}; + +exports.parseSimulcastStreamList = function (str) { + return str.split(';').map(function (stream) { + return stream.split(',').map(function (format) { + var scid, paused = false; + + if (format[0] !== '~') { + scid = toIntIfInt(format); + } else { + scid = toIntIfInt(format.substring(1, format.length)); + paused = true; + } + + return { + scid: scid, + paused: paused + }; + }); + }); +}; + +},{"./grammar":36}],39:[function(require,module,exports){ +var grammar = require('./grammar'); + +// customized util.format - discards excess arguments and can void middle ones +var formatRegExp = /%[sdv%]/g; +var format = function (formatStr) { + var i = 1; + var args = arguments; + var len = args.length; + return formatStr.replace(formatRegExp, function (x) { + if (i >= len) { + return x; // missing argument + } + var arg = args[i]; + i += 1; + switch (x) { + case '%%': + return '%'; + case '%s': + return String(arg); + case '%d': + return Number(arg); + case '%v': + return ''; + } + }); + // NB: we discard excess arguments - they are typically undefined from makeLine +}; + +var makeLine = function (type, obj, location) { + var str = obj.format instanceof Function ? + (obj.format(obj.push ? location : location[obj.name])) : + obj.format; + + var args = [type + '=' + str]; + if (obj.names) { + for (var i = 0; i < obj.names.length; i += 1) { + var n = obj.names[i]; + if (obj.name) { + args.push(location[obj.name][n]); + } + else { // for mLine and push attributes + args.push(location[obj.names[i]]); + } + } + } + else { + args.push(location[obj.name]); + } + return format.apply(null, args); +}; + +// RFC specified order +// TODO: extend this with all the rest +var defaultOuterOrder = [ + 'v', 'o', 's', 'i', + 'u', 'e', 'p', 'c', + 'b', 't', 'r', 'z', 'a' +]; +var defaultInnerOrder = ['i', 'c', 'b', 'a']; + + +module.exports = function (session, opts) { + opts = opts || {}; + // ensure certain properties exist + if (session.version == null) { + session.version = 0; // 'v=0' must be there (only defined version atm) + } + if (session.name == null) { + session.name = ' '; // 's= ' must be there if no meaningful name set + } + session.media.forEach(function (mLine) { + if (mLine.payloads == null) { + mLine.payloads = ''; + } + }); + + var outerOrder = opts.outerOrder || defaultOuterOrder; + var innerOrder = opts.innerOrder || defaultInnerOrder; + var sdp = []; + + // loop through outerOrder for matching properties on session + outerOrder.forEach(function (type) { + grammar[type].forEach(function (obj) { + if (obj.name in session && session[obj.name] != null) { + sdp.push(makeLine(type, obj, session)); + } + else if (obj.push in session && session[obj.push] != null) { + session[obj.push].forEach(function (el) { + sdp.push(makeLine(type, obj, el)); + }); + } + }); + }); + + // then for each media line, follow the innerOrder + session.media.forEach(function (mLine) { + sdp.push(makeLine('m', grammar.m[0], mLine)); + + innerOrder.forEach(function (type) { + grammar[type].forEach(function (obj) { + if (obj.name in mLine && mLine[obj.name] != null) { + sdp.push(makeLine(type, obj, mLine)); + } + else if (obj.push in mLine && mLine[obj.push] != null) { + mLine[obj.push].forEach(function (el) { + sdp.push(makeLine(type, obj, el)); + }); + } + }); + }); + }); + + return sdp.join('\r\n') + '\r\n'; +}; + +},{"./grammar":36}],40:[function(require,module,exports){ +module.exports={ + "name": "jssip", + "title": "JsSIP", + "description": "the Javascript SIP library", + "version": "3.7.5", + "homepage": "https://jssip.net", + "author": "José Luis Millán (https://github.com/jmillan)", + "contributors": [ + "Iñaki Baz Castillo (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.14.34", + "debug": "^4.3.1", + "events": "^3.3.0", + "sdp-transform": "^2.14.1" + }, + "devDependencies": { + "@babel/core": "^7.13.10", + "@babel/preset-env": "^7.13.10", + "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) +}); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 6d3fe9ca2..a71b08059 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.data={},n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n.is_terminated=!1,n.terminated_reason=void 0,n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){"pending"===this._state&&(f('set "active" state'),this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=_,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,f||(f=[]),r.headers=f.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){this._dialogTerminated("send un-subscribe");var e=["Event: ".concat(this.event_name),"Expires: 0"];this._send(null,e)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var e=["Event: ".concat(this.event_name),"Expires: 0"];this._send(null,e)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.d.ts b/lib/Notifier.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/lib/Notifier.js b/lib/Notifier.js index 5b6490dd5..fa0ce39ec 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -10,7 +10,10 @@ module.exports = class Notifier extends EventEmitter { constructor(ua, { subscribe, content_type, headers, credential, pending }) { + debug('new'); + super(); + this._ua = ua; this.expires_timestamp = null; this.expires_timer = null; @@ -19,20 +22,25 @@ module.exports = class Notifier extends EventEmitter this.is_first_notify_response = true; this.id = null; this.event_name = subscribe.getHeader('event'); - this.content_type = content_type; + if (!content_type) + { throw new TypeError('content_type is undefined'); + } + + this.content_type = content_type; this.expires = parseInt(subscribe.getHeader('expires')); this.credential = credential; + const user = subscribe.to.uri.user; const domain = subscribe.to.uri.host; this.contact = ``; this.rcseq = subscribe.cseq; - this.data = {}; // Custom session empty object for high level use. this.headers = headers ? headers : []; this.target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); + this.params = { from : subscribe.to, from_tag : subscribe.to_tag, @@ -41,14 +49,21 @@ module.exports = class Notifier extends EventEmitter call_id : subscribe.call_id, cseq : Math.floor((Math.random() * 10000) + 1) }; + this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + debug('add dialog id=', this.id); this._ua.newDialog(this); + this._setExpiresTimestamp(); this._setExpiresTimer(); - subscribe.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); this.is_terminated = false; this.terminated_reason = undefined; + + // Custom session empty object for high level use. + this.data = {}; + + subscribe.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); } /** @@ -77,8 +92,11 @@ module.exports = class Notifier extends EventEmitter { this.is_first_notify_response = false; this.route_set = response.getHeaders('record-route').reverse(); + if (this.route_set.length > 0) + { this.params.route_set = this.route_set; + } } } else if (response.status_code >= 300) @@ -91,10 +109,11 @@ module.exports = class Notifier extends EventEmitter { if (request.method !== JsSIP_C.SUBSCRIBE) { - request.reply(405); // Method Not Allowed + request.reply(405); return; } + let h = request.getHeader('expires'); if (h === undefined || h === null) @@ -102,6 +121,7 @@ module.exports = class Notifier extends EventEmitter h = '900'; // Missed header Expires. RFC 6665 3.1.1. Set default expires value debug(`Missed expires header. Set by default ${h}`); } + this.expires = parseInt(h); request.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); @@ -128,15 +148,18 @@ module.exports = class Notifier extends EventEmitter */ setActiveState() { + debug('setActiveState()'); + if (this._state === 'pending') { - debug('set "active" state'); this._state = 'active'; } } sendNotify(body = null) { + debug('sendNotify()'); + let subs_state = this._state; if (this._state !== 'terminated') @@ -152,10 +175,12 @@ module.exports = class Notifier extends EventEmitter headers.push(`Subscription-State: ${subs_state}`); headers.push(`Event: ${this.event_name}`); + if (body) { headers.push(`Content-Type: ${this.content_type}`); } + this.params.cseq++; this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); @@ -163,8 +188,13 @@ module.exports = class Notifier extends EventEmitter sendFinalNotify(body = null, reason = null) { + debug('sendFinalNotify()'); + if (this.is_final_notify_sent) + { return; + } + this.is_final_notify_sent = true; this._dialogTerminated('send final notify'); this.terminated_reason = reason; @@ -180,18 +210,23 @@ module.exports = class Notifier extends EventEmitter * Private API. */ _dialogTerminated(reason) - { + { if (this.is_terminated) + { return; + } + this.is_terminated = true; this._state = 'terminated'; clearTimeout(this.expires_timer); + // If delay needed ? setTimeout(() => { debug('remove dialog id=', this.id); this._ua.destroyDialog(this); }, 32000); + debug(`emit "terminated" ${reason}"`); this.emit('terminated', reason); } @@ -214,7 +249,10 @@ module.exports = class Notifier extends EventEmitter setTimeout(() => { if (this.is_final_notify_sent) + { return; + } + this.terminated_reason = 'timeout'; this.is_final_notify_sent = true; this.sendNotify(); diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/lib/Subscriber.js b/lib/Subscriber.js index c8bb0779a..a80c2a60b 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -11,28 +11,59 @@ module.exports = class Subscriber extends EventEmitter constructor(ua, target, { event_name, accept, expires, content_type, allow_events, params, headers, credential }) { + debug('new'); + super(); + this._ua = ua; + if (!target) + { throw new TypeError('target is undefined'); + } + this.target = target; + if (!event_name) + { throw new TypeError('event_name is undefined'); + } + this.event_name = event_name; + if (!accept) + { throw new TypeError('accept is undefined'); + } + this.accept = accept; + if (!expires) + { expires = 900; + } + this.expires = expires; - this.allow_events = allow_events; // optional - this.content_type = content_type; // used to subscribe with body + this.allow_events = allow_events; + + // used to subscribe with body + this.content_type = content_type; + if (!params) + { throw new TypeError('params is undefined'); + } + if (!params.from_uri) + { throw new TypeError('params.from_uri is undefined'); + } + if (!params.to_uri) + { throw new TypeError('params.to_uri is undefined'); + } + this.params = params; params.from_tag = Utils.newTag(); params.to_tag = null; @@ -40,24 +71,42 @@ module.exports = class Subscriber extends EventEmitter params.cseq = Math.floor((Math.random() * 10000) + 1); this.contact = ``; // this.contact = ``; - this.credential = credential; // optional - this._state = 'init'; // init, notify_wait, pending, active, terminated - this.id = null; // dialog id - this.expires_timer = null; // to update subscription + + // Optional, used if credential is different from REGISTER/INVITE + this.credential = credential; + + // dialog state: init, notify_wait, pending, active, terminated + this._state = 'init'; + + // dialog id + this.id = null; + + // to refresh subscription + this.expires_timer = null; this.expires_timestamp = null; + if (!headers) + { headers = []; + } + this.headers = headers.concat([ `Event: ${this.event_name}`, `Accept: ${this.accept}`, `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); + if (this.allowEvents) + { this.headers.push(`Allow-Events: ${this.allowEvents}`); + } + this.is_terminated = false; this.route_set = null; - this.data = {}; // Custom session empty object for high level use. + + // Custom session empty object for high level use. + this.data = {}; } /** @@ -86,11 +135,16 @@ module.exports = class Subscriber extends EventEmitter { this.params.to_tag = response.to_tag; this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + debug('added dialog id=', this.id); this._ua.newDialog(this); + this.route_set = response.getHeaders('record-route').reverse(); + if (this.route_set.length > 0) + { this.params.route_set = this.route_set; + } } const expires = this._getExpires(response); @@ -100,6 +154,7 @@ module.exports = class Subscriber extends EventEmitter return; } + if (expires > 0) { this.expires_timestamp = new Date().getTime() + (expires * 1000); @@ -116,19 +171,21 @@ module.exports = class Subscriber extends EventEmitter { if (request.method !== JsSIP_C.NOTIFY) { - request.reply(405); // Method Not Allowed + request.reply(405); return; } + const subs_state = request.parseHeader('subscription-state'); if (!subs_state) { debugerror('missed header Subscription-State'); - request.reply(400); // Bad request + request.reply(400); return; } + request.reply(200); const new_state = subs_state.state.toLowerCase(); @@ -137,22 +194,25 @@ module.exports = class Subscriber extends EventEmitter if (prev_state !== 'terminated' && new_state !== 'terminated') { this._state = new_state; + if (subs_state.expires !== undefined) { const expires = subs_state.expires; const expires_timestamp = new Date().getTime() + (expires * 1000); const max_time_deviation = 2000; - // expiration shorter and the difference is not too small + // expiration time is shorter and the difference is not too small if (this.expires_timestamp - expires_timestamp > max_time_deviation) { debug('update sending re-SUBSCRIBE time'); + clearTimeout(this.expires_timer); this.expires_timestamp = expires_timestamp; this._scheduleSubscribe(this._calculateTimeoutMs(expires)); } } } + if (prev_state !== 'active' && new_state === 'active') { debug('emit "active"'); @@ -170,8 +230,11 @@ module.exports = class Subscriber extends EventEmitter debug('emit "notify"'); this.emit('notify', is_final, request, body, content_type); } + if (is_final) + { this._dialogTerminated('receive final notify'); + } } /** @@ -179,21 +242,30 @@ module.exports = class Subscriber extends EventEmitter */ subscribe(body = null) { + debug('subscribe()'); + if (this._state === 'init') + { this._state = 'notify_wait'; + } const headers = this.headers.slice(); if (body) { - if (!this.content_type) + if (!this.content_type) + { throw new TypeError('content_type is undefined'); + } headers.push(`Content-Type: ${this.content_type}`); } + this._send(body, headers); } unsubscribe() { + debug('unsubscribe()'); + this._dialogTerminated('send un-subscribe'); const headers = [ `Event: ${this.event_name}`, @@ -213,17 +285,24 @@ module.exports = class Subscriber extends EventEmitter */ _dialogTerminated(reason) { - if (this.is_terminated) // to prevent duplicate call + // to prevent duplicate emit terminated + if (this.is_terminated) + { return; + } + this.is_terminated = true; this._state = 'terminated'; clearTimeout(this.expires_timer); - // remove dialog from dialogs table with some delay, to allow receive end NOTIFY + + // remove dialog from dialogs table with some delay, to allow receiving final NOTIFY setTimeout(() => { debug('removed dialog id=', this.id); + this._ua.destroyDialog(this); }, 32000); + debug(`emit "terminated" ${reason}"`); this.emit('terminated', reason); } @@ -251,6 +330,7 @@ module.exports = class Subscriber extends EventEmitter _scheduleSubscribe(timeout) { debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); + this.expires_timer = setTimeout(() => { this.expires_timer = undefined; From b9119ff87d824f7333ef92b49f8b10098d881e6f Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 21 May 2021 13:54:21 +0300 Subject: [PATCH 06/70] style changed --- dist/jssip.js | 28594 ++++++++++++++++++++++++++++++++++++++++++ dist/jssip.min.js | 2 +- lib/Notifier.d.ts | 0 lib/Notifier.js | 53 +- lib/Subscriber.d.ts | 0 lib/Subscriber.js | 106 +- 6 files changed, 28734 insertions(+), 21 deletions(-) create mode 100644 dist/jssip.js create mode 100644 lib/Notifier.d.ts create mode 100644 lib/Subscriber.d.ts diff --git a/dist/jssip.js b/dist/jssip.js new file mode 100644 index 000000000..a741e02ef --- /dev/null +++ b/dist/jssip.js @@ -0,0 +1,28594 @@ +/* + * JsSIP v3.7.5 + * the Javascript SIP library + * Copyright: 2012-2021 José Luis Millán (https://github.com/jmillan) + * Homepage: https://jssip.net + * License: MIT + */ + +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var Utils = require('./Utils'); + +var JsSIP_C = require('./Constants'); + +var Grammar = require('./Grammar'); + +var URI = require('./URI'); + +var Socket = require('./Socket'); + +var Exceptions = require('./Exceptions'); // Default settings. + + +exports.settings = { + // SIP authentication. + authorization_user: null, + password: null, + realm: null, + ha1: null, + authorization_jwt: null, + // SIP account. + display_name: null, + uri: null, + contact_uri: null, + // SIP instance id (GRUU). + instance_id: null, + // Preloaded SIP Route header field. + use_preloaded_route: false, + // Session parameters. + session_timers: true, + session_timers_refresh_method: JsSIP_C.UPDATE, + session_timers_force_refresher: false, + no_answer_timeout: 60, + // Registration parameters. + register: true, + register_expires: 600, + registrar_server: null, + // Connection options. + sockets: null, + connection_recovery_max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL, + connection_recovery_min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL, + + /* + * Host address. + * Value to be set in Via sent_by and host part of Contact FQDN. + */ + via_host: "".concat(Utils.createRandomToken(12), ".invalid") +}; // Configuration checks. + +var checks = { + mandatory: { + sockets: function sockets(_sockets2) { + /* Allow defining sockets parameter as: + * Socket: socket + * Array of Socket: [socket1, socket2] + * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}] + * Array of Objects and Socket: [{socket: socket1}, socket2] + */ + var _sockets = []; + + if (Socket.isSocket(_sockets2)) { + _sockets.push({ + socket: _sockets2 + }); + } else if (Array.isArray(_sockets2) && _sockets2.length) { + var _iterator = _createForOfIteratorHelper(_sockets2), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var socket = _step.value; + + if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) { + _sockets.push(socket); + } else if (Socket.isSocket(socket)) { + _sockets.push({ + socket: socket + }); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } else { + return; + } + + return _sockets; + }, + uri: function uri(_uri) { + if (!/^sip:/i.test(_uri)) { + _uri = "".concat(JsSIP_C.SIP, ":").concat(_uri); + } + + var parsed = URI.parse(_uri); + + if (!parsed) { + return; + } else if (!parsed.user) { + return; + } else { + return parsed; + } + } + }, + optional: { + authorization_user: function authorization_user(_authorization_user) { + if (Grammar.parse("\"".concat(_authorization_user, "\""), 'quoted_string') === -1) { + return; + } else { + return _authorization_user; + } + }, + authorization_jwt: function authorization_jwt(_authorization_jwt) { + if (typeof _authorization_jwt === 'string') { + return _authorization_jwt; + } + }, + user_agent: function user_agent(_user_agent) { + if (typeof _user_agent === 'string') { + return _user_agent; + } + }, + connection_recovery_max_interval: function connection_recovery_max_interval(_connection_recovery_max_interval) { + if (Utils.isDecimal(_connection_recovery_max_interval)) { + var value = Number(_connection_recovery_max_interval); + + if (value > 0) { + return value; + } + } + }, + connection_recovery_min_interval: function connection_recovery_min_interval(_connection_recovery_min_interval) { + if (Utils.isDecimal(_connection_recovery_min_interval)) { + var value = Number(_connection_recovery_min_interval); + + if (value > 0) { + return value; + } + } + }, + contact_uri: function contact_uri(_contact_uri) { + if (typeof _contact_uri === 'string') { + var uri = Grammar.parse(_contact_uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } + } + }, + display_name: function display_name(_display_name) { + return _display_name; + }, + instance_id: function instance_id(_instance_id) { + if (/^uuid:/i.test(_instance_id)) { + _instance_id = _instance_id.substr(5); + } + + if (Grammar.parse(_instance_id, 'uuid') === -1) { + return; + } else { + return _instance_id; + } + }, + no_answer_timeout: function no_answer_timeout(_no_answer_timeout) { + if (Utils.isDecimal(_no_answer_timeout)) { + var value = Number(_no_answer_timeout); + + if (value > 0) { + return value; + } + } + }, + session_timers: function session_timers(_session_timers) { + if (typeof _session_timers === 'boolean') { + return _session_timers; + } + }, + session_timers_refresh_method: function session_timers_refresh_method(method) { + if (typeof method === 'string') { + method = method.toUpperCase(); + + if (method === JsSIP_C.INVITE || method === JsSIP_C.UPDATE) { + return method; + } + } + }, + session_timers_force_refresher: function session_timers_force_refresher(_session_timers_force_refresher) { + if (typeof _session_timers_force_refresher === 'boolean') { + return _session_timers_force_refresher; + } + }, + password: function password(_password) { + return String(_password); + }, + realm: function realm(_realm) { + return String(_realm); + }, + ha1: function ha1(_ha) { + return String(_ha); + }, + register: function register(_register) { + if (typeof _register === 'boolean') { + return _register; + } + }, + register_expires: function register_expires(_register_expires) { + if (Utils.isDecimal(_register_expires)) { + var value = Number(_register_expires); + + if (value > 0) { + return value; + } + } + }, + registrar_server: function registrar_server(_registrar_server) { + if (!/^sip:/i.test(_registrar_server)) { + _registrar_server = "".concat(JsSIP_C.SIP, ":").concat(_registrar_server); + } + + var parsed = URI.parse(_registrar_server); + + if (!parsed) { + return; + } else if (parsed.user) { + return; + } else { + return parsed; + } + }, + use_preloaded_route: function use_preloaded_route(_use_preloaded_route) { + if (typeof _use_preloaded_route === 'boolean') { + return _use_preloaded_route; + } + } + } +}; + +exports.load = function (dst, src) { + // Check Mandatory parameters. + for (var parameter in checks.mandatory) { + if (!src.hasOwnProperty(parameter)) { + throw new Exceptions.ConfigurationError(parameter); + } else { + var value = src[parameter]; + var checked_value = checks.mandatory[parameter](value); + + if (checked_value !== undefined) { + dst[parameter] = checked_value; + } else { + throw new Exceptions.ConfigurationError(parameter, value); + } + } + } // Check Optional parameters. + + + for (var _parameter in checks.optional) { + if (src.hasOwnProperty(_parameter)) { + var _value = src[_parameter]; + /* If the parameter value is null, empty string, undefined, empty array + * or it's a number with NaN value, then apply its default value. + */ + + if (Utils.isEmpty(_value)) { + continue; + } + + var _checked_value = checks.optional[_parameter](_value); + + if (_checked_value !== undefined) { + dst[_parameter] = _checked_value; + } else { + throw new Exceptions.ConfigurationError(_parameter, _value); + } + } + } +}; +},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],2:[function(require,module,exports){ +"use strict"; + +var pkg = require('../package.json'); + +module.exports = { + USER_AGENT: "".concat(pkg.title, " ").concat(pkg.version), + // SIP scheme. + SIP: 'sip', + SIPS: 'sips', + // End and Failure causes. + causes: { + // Generic error causes. + CONNECTION_ERROR: 'Connection Error', + REQUEST_TIMEOUT: 'Request Timeout', + SIP_FAILURE_CODE: 'SIP Failure Code', + INTERNAL_ERROR: 'Internal Error', + // SIP error causes. + BUSY: 'Busy', + REJECTED: 'Rejected', + REDIRECTED: 'Redirected', + UNAVAILABLE: 'Unavailable', + NOT_FOUND: 'Not Found', + ADDRESS_INCOMPLETE: 'Address Incomplete', + INCOMPATIBLE_SDP: 'Incompatible SDP', + MISSING_SDP: 'Missing SDP', + AUTHENTICATION_ERROR: 'Authentication Error', + // Session error causes. + BYE: 'Terminated', + WEBRTC_ERROR: 'WebRTC Error', + CANCELED: 'Canceled', + NO_ANSWER: 'No Answer', + EXPIRES: 'Expires', + NO_ACK: 'No ACK', + DIALOG_ERROR: 'Dialog Error', + USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access', + BAD_MEDIA_DESCRIPTION: 'Bad Media Description', + RTP_TIMEOUT: 'RTP Timeout' + }, + SIP_ERROR_CAUSES: { + REDIRECTED: [300, 301, 302, 305, 380], + BUSY: [486, 600], + REJECTED: [403, 603], + NOT_FOUND: [404, 604], + UNAVAILABLE: [480, 410, 408, 430], + ADDRESS_INCOMPLETE: [484, 424], + INCOMPATIBLE_SDP: [488, 606], + AUTHENTICATION_ERROR: [401, 407] + }, + // SIP Methods. + 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 methods. + DTMF_TRANSPORT: { + INFO: 'INFO', + RFC2833: 'RFC2833' + }, + + /* SIP Response Reasons + * DOC: https://www.iana.org/assignments/sip-parameters + * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7 + */ + REASON_PHRASE: { + 100: 'Trying', + 180: 'Ringing', + 181: 'Call Is Being Forwarded', + 182: 'Queued', + 183: 'Session Progress', + 199: 'Early Dialog Terminated', + // draft-ietf-sipcore-199 + 200: 'OK', + 202: 'Accepted', + // RFC 3265 + 204: 'No Notification', + // RFC 5839 + 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', + // RFC 3903 + 413: 'Request Entity Too Large', + 414: 'Request-URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Unsupported URI Scheme', + 417: 'Unknown Resource-Priority', + // RFC 4412 + 420: 'Bad Extension', + 421: 'Extension Required', + 422: 'Session Interval Too Small', + // RFC 4028 + 423: 'Interval Too Brief', + 424: 'Bad Location Information', + // RFC 6442 + 428: 'Use Identity Header', + // RFC 4474 + 429: 'Provide Referrer Identity', + // RFC 3892 + 430: 'Flow Failed', + // RFC 5626 + 433: 'Anonymity Disallowed', + // RFC 5079 + 436: 'Bad Identity-Info', + // RFC 4474 + 437: 'Unsupported Certificate', + // RFC 4744 + 438: 'Invalid Identity Header', + // RFC 4744 + 439: 'First Hop Lacks Outbound Support', + // RFC 5626 + 440: 'Max-Breadth Exceeded', + // RFC 5393 + 469: 'Bad Info Package', + // draft-ietf-sipcore-info-events + 470: 'Consent Needed', + // RFC 5360 + 478: 'Unresolvable Destination', + // Custom code copied from Kamailio. + 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', + // RFC 3265 + 491: 'Request Pending', + 493: 'Undecipherable', + 494: 'Security Agreement Required', + // RFC 3329 + 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', + // RFC 3312 + 600: 'Busy Everywhere', + 603: 'Decline', + 604: 'Does Not Exist Anywhere', + 606: 'Not Acceptable' + }, + ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE', + ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay', + MAX_FORWARDS: 69, + SESSION_EXPIRES: 90, + MIN_SESSION_EXPIRES: 60, + CONNECTION_RECOVERY_MAX_INTERVAL: 30, + CONNECTION_RECOVERY_MIN_INTERVAL: 2 +}; +},{"../package.json":40}],3:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var SIPMessage = require('./SIPMessage'); + +var JsSIP_C = require('./Constants'); + +var Transactions = require('./Transactions'); + +var Dialog_RequestSender = require('./Dialog/RequestSender'); + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:Dialog'); + +var C = { + // Dialog states. + STATUS_EARLY: 1, + STATUS_CONFIRMED: 2 +}; // RFC 3261 12.1. + +module.exports = /*#__PURE__*/function () { + function Dialog(owner, message, type) { + var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; + + _classCallCheck(this, Dialog); + + this._owner = owner; + this._ua = owner._ua; + this._uac_pending_reply = false; + this._uas_pending_reply = false; + + if (!message.hasHeader('contact')) { + return { + error: 'unable to create a Dialog without Contact header field' + }; + } + + if (message instanceof SIPMessage.IncomingResponse) { + state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED; + } + + var contact = message.parseHeader('contact'); // RFC 3261 12.1.1. + + if (type === 'UAS') { + this._id = { + call_id: message.call_id, + local_tag: message.to_tag, + remote_tag: message.from_tag, + toString: function toString() { + return this.call_id + this.local_tag + this.remote_tag; + } + }; + this._state = state; + this._remote_seqnum = message.cseq; + this._local_uri = message.parseHeader('to').uri; + this._remote_uri = message.parseHeader('from').uri; + this._remote_target = contact.uri; + this._route_set = message.getHeaders('record-route'); + this._ack_seqnum = this._remote_seqnum; + } // RFC 3261 12.1.2. + else if (type === 'UAC') { + this._id = { + call_id: message.call_id, + local_tag: message.from_tag, + remote_tag: message.to_tag, + toString: function toString() { + return this.call_id + this.local_tag + this.remote_tag; + } + }; + this._state = state; + this._local_seqnum = message.cseq; + this._local_uri = message.parseHeader('from').uri; + this._remote_uri = message.parseHeader('to').uri; + this._remote_target = contact.uri; + this._route_set = message.getHeaders('record-route').reverse(); + this._ack_seqnum = null; + } + + this._ua.newDialog(this); + + debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); + } + + _createClass(Dialog, [{ + key: "id", + get: function get() { + return this._id; + } + }, { + key: "local_seqnum", + get: function get() { + return this._local_seqnum; + }, + set: function set(num) { + this._local_seqnum = num; + } + }, { + key: "owner", + get: function get() { + return this._owner; + } + }, { + key: "uac_pending_reply", + get: function get() { + return this._uac_pending_reply; + }, + set: function set(pending) { + this._uac_pending_reply = pending; + } + }, { + key: "uas_pending_reply", + get: function get() { + return this._uas_pending_reply; + } + }, { + key: "update", + value: function update(message, type) { + this._state = C.STATUS_CONFIRMED; + debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); + + if (type === 'UAC') { + // RFC 3261 13.2.2.4. + this._route_set = message.getHeaders('record-route').reverse(); + } + } + }, { + key: "terminate", + value: function terminate() { + debug("dialog ".concat(this._id.toString(), " deleted")); + + this._ua.destroyDialog(this); + } + }, { + key: "sendRequest", + value: function sendRequest(method) { + var _this = this; + + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var body = options.body || null; + + var request = this._createRequest(method, extraHeaders, body); // Increase the local CSeq on authentication. + + + eventHandlers.onAuthenticated = function () { + _this._local_seqnum += 1; + }; + + var request_sender = new Dialog_RequestSender(this, request, eventHandlers); + request_sender.send(); // Return the instance of OutgoingRequest. + + return request; + } + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + // Check in-dialog request. + if (!this._checkInDialogRequest(request)) { + return; + } // ACK received. Cleanup this._ack_seqnum. + + + if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) { + this._ack_seqnum = null; + } // INVITE received. Set this._ack_seqnum. + else if (request.method === JsSIP_C.INVITE) { + this._ack_seqnum = request.cseq; + } + + this._owner.receiveRequest(request); + } // RFC 3261 12.2.1.1. + + }, { + key: "_createRequest", + value: function _createRequest(method, extraHeaders, body) { + extraHeaders = Utils.cloneArray(extraHeaders); + + if (!this._local_seqnum) { + this._local_seqnum = Math.floor(Math.random() * 10000); + } + + var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1; + var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, { + 'cseq': cseq, + '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 + }, extraHeaders, body); + return request; + } // RFC 3261 12.2.2. + + }, { + key: "_checkInDialogRequest", + value: function _checkInDialogRequest(request) { + var _this2 = this; + + if (!this._remote_seqnum) { + this._remote_seqnum = request.cseq; + } else if (request.cseq < this._remote_seqnum) { + if (request.method === JsSIP_C.ACK) { + // We are not expecting any ACK with lower seqnum than the current one. + // Or this is not the ACK we are waiting for. + if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) { + return false; + } + } else { + request.reply(500); + return false; + } + } else if (request.cseq > this._remote_seqnum) { + this._remote_seqnum = request.cseq; + } // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-. + + + if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) { + if (this._uac_pending_reply === true) { + request.reply(491); + } else if (this._uas_pending_reply === true) { + var retryAfter = (Math.random() * 10 | 0) + 1; + request.reply(500, null, ["Retry-After:".concat(retryAfter)]); + return false; + } else { + this._uas_pending_reply = true; + + var stateChanged = function stateChanged() { + if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED || request.server_transaction.state === Transactions.C.STATUS_COMPLETED || request.server_transaction.state === Transactions.C.STATUS_TERMINATED) { + request.server_transaction.removeListener('stateChanged', stateChanged); + _this2._uas_pending_reply = false; + } + }; + + request.server_transaction.on('stateChanged', stateChanged); + } // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted. + + + if (request.hasHeader('contact')) { + request.server_transaction.on('stateChanged', function () { + if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED) { + _this2._remote_target = request.parseHeader('contact').uri; + } + }); + } + } else if (request.method === JsSIP_C.NOTIFY) { + // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted. + if (request.hasHeader('contact')) { + request.server_transaction.on('stateChanged', function () { + if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) { + _this2._remote_target = request.parseHeader('contact').uri; + } + }); + } + } + + return true; + } + }], [{ + key: "C", + get: // Expose C object. + function get() { + return C; + } + }]); + + return Dialog; +}(); +},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,"debug":32}],4:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var JsSIP_C = require('../Constants'); + +var Transactions = require('../Transactions'); + +var RTCSession = require('../RTCSession'); + +var RequestSender = require('../RequestSender'); // Default event handlers. + + +var EventHandlers = { + onRequestTimeout: function onRequestTimeout() {}, + onTransportError: function onTransportError() {}, + onSuccessResponse: function onSuccessResponse() {}, + onErrorResponse: function onErrorResponse() {}, + onAuthenticated: function onAuthenticated() {}, + onDialogError: function onDialogError() {} +}; + +module.exports = /*#__PURE__*/function () { + function DialogRequestSender(dialog, request, eventHandlers) { + _classCallCheck(this, DialogRequestSender); + + this._dialog = dialog; + this._ua = dialog._ua; + this._request = request; + this._eventHandlers = eventHandlers; // RFC3261 14.1 Modifying an Existing Session. UAC Behavior. + + this._reattempt = false; + this._reattemptTimer = null; // Define the undefined handlers. + + for (var handler in EventHandlers) { + if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { + if (!this._eventHandlers[handler]) { + this._eventHandlers[handler] = EventHandlers[handler]; + } + } + } + } + + _createClass(DialogRequestSender, [{ + key: "request", + get: function get() { + return this._request; + } + }, { + key: "send", + value: function send() { + var _this = this; + + var request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout: function onRequestTimeout() { + _this._eventHandlers.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this._eventHandlers.onTransportError(); + }, + onAuthenticated: function onAuthenticated(request) { + _this._eventHandlers.onAuthenticated(request); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this._receiveResponse(response); + } + }); + request_sender.send(); // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-. + + if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) { + this._dialog.uac_pending_reply = true; + + var stateChanged = function stateChanged() { + if (request_sender.clientTransaction.state === Transactions.C.STATUS_ACCEPTED || request_sender.clientTransaction.state === Transactions.C.STATUS_COMPLETED || request_sender.clientTransaction.state === Transactions.C.STATUS_TERMINATED) { + request_sender.clientTransaction.removeListener('stateChanged', stateChanged); + _this._dialog.uac_pending_reply = false; + } + }; + + request_sender.clientTransaction.on('stateChanged', stateChanged); + } + } + }, { + key: "_receiveResponse", + value: function _receiveResponse(response) { + var _this2 = this; + + // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog. + if (response.status_code === 408 || response.status_code === 481) { + this._eventHandlers.onDialogError(response); + } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) { + if (this._reattempt) { + if (response.status_code >= 200 && response.status_code < 300) { + this._eventHandlers.onSuccessResponse(response); + } else if (response.status_code >= 300) { + this._eventHandlers.onErrorResponse(response); + } + } else { + this._request.cseq = this._dialog.local_seqnum += 1; + this._reattemptTimer = setTimeout(function () { + // TODO: look at dialog state instead. + if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) { + _this2._reattempt = true; + + _this2._request_sender.send(); + } + }, 1000); + } + } else if (response.status_code >= 200 && response.status_code < 300) { + this._eventHandlers.onSuccessResponse(response); + } else if (response.status_code >= 300) { + this._eventHandlers.onErrorResponse(response); + } + } + }]); + + return DialogRequestSender; +}(); +},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:DigestAuthentication'); + +var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); + +debugerror.log = console.warn.bind(console); + +module.exports = /*#__PURE__*/function () { + function DigestAuthentication(credentials) { + _classCallCheck(this, DigestAuthentication); + + this._credentials = credentials; + 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; + } + + _createClass(DigestAuthentication, [{ + key: "get", + value: function get(parameter) { + switch (parameter) { + case 'realm': + return this._realm; + + case 'ha1': + return this._ha1; + + default: + debugerror('get() | cannot get "%s" parameter', parameter); + return undefined; + } + } + /** + * Performs Digest authentication given a SIP request and the challenge + * received in a response to that request. + * Returns true if auth was successfully generated, false otherwise. + */ + + }, { + key: "authenticate", + value: function authenticate(_ref, challenge) + /* test interface */ + { + var method = _ref.method, + ruri = _ref.ruri, + body = _ref.body; + var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + this._algorithm = challenge.algorithm; + this._realm = challenge.realm; + this._nonce = challenge.nonce; + this._opaque = challenge.opaque; + this._stale = challenge.stale; + + if (this._algorithm) { + if (this._algorithm !== 'MD5') { + debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); + return false; + } + } else { + this._algorithm = 'MD5'; + } + + if (!this._nonce) { + debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); + return false; + } + + if (!this._realm) { + debugerror('authenticate() | challenge without Digest realm, authentication aborted'); + return false; + } // If no plain SIP password is provided. + + + if (!this._credentials.password) { + // If ha1 is not provided we cannot authenticate. + if (!this._credentials.ha1) { + debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); + return false; + } // If the realm does not match the stored realm we cannot authenticate. + + + if (this._credentials.realm !== this._realm) { + debugerror('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); + return false; + } + } // 'qop' can contain a list of values (Array). Let's choose just one. + + + if (challenge.qop) { + if (challenge.qop.indexOf('auth-int') > -1) { + this._qop = 'auth-int'; + } else if (challenge.qop.indexOf('auth') > -1) { + this._qop = 'auth'; + } else { + // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. + debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); + return false; + } + } else { + this._qop = null; + } // Fill other attributes. + + + this._method = method; + this._uri = ruri; + this._cnonce = cnonce || Utils.createRandomToken(12); + this._nc += 1; + var hex = Number(this._nc).toString(16); + this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex; // Nc-value = 8LHEX. Max value = 'FFFFFFFF'. + + if (this._nc === 4294967296) { + this._nc = 1; + this._ncHex = '00000001'; + } // Calculate the Digest "response" value. + // If we have plain SIP password then regenerate ha1. + + + if (this._credentials.password) { + // HA1 = MD5(A1) = MD5(username:realm:password). + this._ha1 = Utils.calculateMD5("".concat(this._credentials.username, ":").concat(this._realm, ":").concat(this._credentials.password)); + } // Otherwise reuse the stored ha1. + else { + this._ha1 = this._credentials.ha1; + } + + var a2; + var ha2; + + if (this._qop === 'auth') { + // HA2 = MD5(A2) = MD5(method:digestURI). + a2 = "".concat(this._method, ":").concat(this._uri); + ha2 = Utils.calculateMD5(a2); + debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + + this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2)); + } else if (this._qop === 'auth-int') { + // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)). + a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : '')); + ha2 = Utils.calculateMD5(a2); + debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + + this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2)); + } else if (this._qop === null) { + // HA2 = MD5(A2) = MD5(method:digestURI). + a2 = "".concat(this._method, ":").concat(this._uri); + ha2 = Utils.calculateMD5(a2); + debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). + + this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2)); + } + + debug('authenticate() | response generated'); + return true; + } + /** + * Return the Proxy-Authorization or WWW-Authorization header value. + */ + + }, { + key: "toString", + value: function toString() { + var auth_params = []; + + if (!this._response) { + throw new Error('response field does not exist, cannot generate Authorization header'); + } + + auth_params.push("algorithm=".concat(this._algorithm)); + auth_params.push("username=\"".concat(this._credentials.username, "\"")); + auth_params.push("realm=\"".concat(this._realm, "\"")); + auth_params.push("nonce=\"".concat(this._nonce, "\"")); + auth_params.push("uri=\"".concat(this._uri, "\"")); + auth_params.push("response=\"".concat(this._response, "\"")); + + if (this._opaque) { + auth_params.push("opaque=\"".concat(this._opaque, "\"")); + } + + if (this._qop) { + auth_params.push("qop=".concat(this._qop)); + auth_params.push("cnonce=\"".concat(this._cnonce, "\"")); + auth_params.push("nc=".concat(this._ncHex)); + } + + return "Digest ".concat(auth_params.join(', ')); + } + }]); + + return DigestAuthentication; +}(); +},{"./Utils":28,"debug":32}],6:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } + +function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var ConfigurationError = /*#__PURE__*/function (_Error) { + _inherits(ConfigurationError, _Error); + + var _super = _createSuper(ConfigurationError); + + function ConfigurationError(parameter, value) { + var _this; + + _classCallCheck(this, ConfigurationError); + + _this = _super.call(this); + _this.code = 1; + _this.name = 'CONFIGURATION_ERROR'; + _this.parameter = parameter; + _this.value = value; + _this.message = !_this.value ? "Missing parameter: ".concat(_this.parameter) : "Invalid value ".concat(JSON.stringify(_this.value), " for parameter \"").concat(_this.parameter, "\""); + return _this; + } + + return ConfigurationError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); + +var InvalidStateError = /*#__PURE__*/function (_Error2) { + _inherits(InvalidStateError, _Error2); + + var _super2 = _createSuper(InvalidStateError); + + function InvalidStateError(status) { + var _this2; + + _classCallCheck(this, InvalidStateError); + + _this2 = _super2.call(this); + _this2.code = 2; + _this2.name = 'INVALID_STATE_ERROR'; + _this2.status = status; + _this2.message = "Invalid status: ".concat(status); + return _this2; + } + + return InvalidStateError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); + +var NotSupportedError = /*#__PURE__*/function (_Error3) { + _inherits(NotSupportedError, _Error3); + + var _super3 = _createSuper(NotSupportedError); + + function NotSupportedError(message) { + var _this3; + + _classCallCheck(this, NotSupportedError); + + _this3 = _super3.call(this); + _this3.code = 3; + _this3.name = 'NOT_SUPPORTED_ERROR'; + _this3.message = message; + return _this3; + } + + return NotSupportedError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); + +var NotReadyError = /*#__PURE__*/function (_Error4) { + _inherits(NotReadyError, _Error4); + + var _super4 = _createSuper(NotReadyError); + + function NotReadyError(message) { + var _this4; + + _classCallCheck(this, NotReadyError); + + _this4 = _super4.call(this); + _this4.code = 4; + _this4.name = 'NOT_READY_ERROR'; + _this4.message = message; + return _this4; + } + + return NotReadyError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); + +module.exports = { + ConfigurationError: ConfigurationError, + InvalidStateError: InvalidStateError, + NotSupportedError: NotSupportedError, + NotReadyError: NotReadyError +}; +},{}],7:[function(require,module,exports){ +"use strict"; + +module.exports = function () { + /* + * Generated by PEG.js 0.7.0. + * + * http://pegjs.majda.cz/ + */ + function quote(s) { + /* + * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a + * string literal except for the closing quote character, backslash, + * carriage return, line separator, paragraph separator, and line feed. + * Any character may appear in the form of an escape sequence. + * + * For portability, we also escape escape all control and non-ASCII + * characters. Note that "\0" and "\v" escape sequences are not used + * because JSHint does not like the first and IE the second. + */ + return '"' + s.replace(/\\/g, '\\\\') // backslash + .replace(/"/g, '\\"') // closing quote character + .replace(/\x08/g, '\\b') // backspace + .replace(/\t/g, '\\t') // horizontal tab + .replace(/\n/g, '\\n') // line feed + .replace(/\f/g, '\\f') // form feed + .replace(/\r/g, '\\r') // carriage return + .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"'; + } + + var result = { + /* + * Parses the input with a generated parser. If the parsing is successfull, + * returns a value explicitly or implicitly specified by the grammar from + * which the parser was generated (see |PEG.buildParser|). If the parsing is + * unsuccessful, throws |PEG.parser.SyntaxError| describing the error. + */ + parse: function parse(input, startRule) { + var parseFunctions = { + "CRLF": parse_CRLF, + "DIGIT": parse_DIGIT, + "ALPHA": parse_ALPHA, + "HEXDIG": parse_HEXDIG, + "WSP": parse_WSP, + "OCTET": parse_OCTET, + "DQUOTE": parse_DQUOTE, + "SP": parse_SP, + "HTAB": parse_HTAB, + "alphanum": parse_alphanum, + "reserved": parse_reserved, + "unreserved": parse_unreserved, + "mark": parse_mark, + "escaped": parse_escaped, + "LWS": parse_LWS, + "SWS": parse_SWS, + "HCOLON": parse_HCOLON, + "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM, + "TEXT_UTF8char": parse_TEXT_UTF8char, + "UTF8_NONASCII": parse_UTF8_NONASCII, + "UTF8_CONT": parse_UTF8_CONT, + "LHEX": parse_LHEX, + "token": parse_token, + "token_nodot": parse_token_nodot, + "separators": parse_separators, + "word": parse_word, + "STAR": parse_STAR, + "SLASH": parse_SLASH, + "EQUAL": parse_EQUAL, + "LPAREN": parse_LPAREN, + "RPAREN": parse_RPAREN, + "RAQUOT": parse_RAQUOT, + "LAQUOT": parse_LAQUOT, + "COMMA": parse_COMMA, + "SEMI": parse_SEMI, + "COLON": parse_COLON, + "LDQUOT": parse_LDQUOT, + "RDQUOT": parse_RDQUOT, + "comment": parse_comment, + "ctext": parse_ctext, + "quoted_string": parse_quoted_string, + "quoted_string_clean": parse_quoted_string_clean, + "qdtext": parse_qdtext, + "quoted_pair": parse_quoted_pair, + "SIP_URI_noparams": parse_SIP_URI_noparams, + "SIP_URI": parse_SIP_URI, + "uri_scheme": parse_uri_scheme, + "uri_scheme_sips": parse_uri_scheme_sips, + "uri_scheme_sip": parse_uri_scheme_sip, + "userinfo": parse_userinfo, + "user": parse_user, + "user_unreserved": parse_user_unreserved, + "password": parse_password, + "hostport": parse_hostport, + "host": parse_host, + "hostname": parse_hostname, + "domainlabel": parse_domainlabel, + "toplabel": parse_toplabel, + "IPv6reference": parse_IPv6reference, + "IPv6address": parse_IPv6address, + "h16": parse_h16, + "ls32": parse_ls32, + "IPv4address": parse_IPv4address, + "dec_octet": parse_dec_octet, + "port": parse_port, + "uri_parameters": parse_uri_parameters, + "uri_parameter": parse_uri_parameter, + "transport_param": parse_transport_param, + "user_param": parse_user_param, + "method_param": parse_method_param, + "ttl_param": parse_ttl_param, + "maddr_param": parse_maddr_param, + "lr_param": parse_lr_param, + "other_param": parse_other_param, + "pname": parse_pname, + "pvalue": parse_pvalue, + "paramchar": parse_paramchar, + "param_unreserved": parse_param_unreserved, + "headers": parse_headers, + "header": parse_header, + "hname": parse_hname, + "hvalue": parse_hvalue, + "hnv_unreserved": parse_hnv_unreserved, + "Request_Response": parse_Request_Response, + "Request_Line": parse_Request_Line, + "Request_URI": parse_Request_URI, + "absoluteURI": parse_absoluteURI, + "hier_part": parse_hier_part, + "net_path": parse_net_path, + "abs_path": parse_abs_path, + "opaque_part": parse_opaque_part, + "uric": parse_uric, + "uric_no_slash": parse_uric_no_slash, + "path_segments": parse_path_segments, + "segment": parse_segment, + "param": parse_param, + "pchar": parse_pchar, + "scheme": parse_scheme, + "authority": parse_authority, + "srvr": parse_srvr, + "reg_name": parse_reg_name, + "query": parse_query, + "SIP_Version": parse_SIP_Version, + "INVITEm": parse_INVITEm, + "ACKm": parse_ACKm, + "OPTIONSm": parse_OPTIONSm, + "BYEm": parse_BYEm, + "CANCELm": parse_CANCELm, + "REGISTERm": parse_REGISTERm, + "SUBSCRIBEm": parse_SUBSCRIBEm, + "NOTIFYm": parse_NOTIFYm, + "REFERm": parse_REFERm, + "Method": parse_Method, + "Status_Line": parse_Status_Line, + "Status_Code": parse_Status_Code, + "extension_code": parse_extension_code, + "Reason_Phrase": parse_Reason_Phrase, + "Allow_Events": parse_Allow_Events, + "Call_ID": parse_Call_ID, + "Contact": parse_Contact, + "contact_param": parse_contact_param, + "name_addr": parse_name_addr, + "display_name": parse_display_name, + "contact_params": parse_contact_params, + "c_p_q": parse_c_p_q, + "c_p_expires": parse_c_p_expires, + "delta_seconds": parse_delta_seconds, + "qvalue": parse_qvalue, + "generic_param": parse_generic_param, + "gen_value": parse_gen_value, + "Content_Disposition": parse_Content_Disposition, + "disp_type": parse_disp_type, + "disp_param": parse_disp_param, + "handling_param": parse_handling_param, + "Content_Encoding": parse_Content_Encoding, + "Content_Length": parse_Content_Length, + "Content_Type": parse_Content_Type, + "media_type": parse_media_type, + "m_type": parse_m_type, + "discrete_type": parse_discrete_type, + "composite_type": parse_composite_type, + "extension_token": parse_extension_token, + "x_token": parse_x_token, + "m_subtype": parse_m_subtype, + "m_parameter": parse_m_parameter, + "m_value": parse_m_value, + "CSeq": parse_CSeq, + "CSeq_value": parse_CSeq_value, + "Expires": parse_Expires, + "Event": parse_Event, + "event_type": parse_event_type, + "From": parse_From, + "from_param": parse_from_param, + "tag_param": parse_tag_param, + "Max_Forwards": parse_Max_Forwards, + "Min_Expires": parse_Min_Expires, + "Name_Addr_Header": parse_Name_Addr_Header, + "Proxy_Authenticate": parse_Proxy_Authenticate, + "challenge": parse_challenge, + "other_challenge": parse_other_challenge, + "auth_param": parse_auth_param, + "digest_cln": parse_digest_cln, + "realm": parse_realm, + "realm_value": parse_realm_value, + "domain": parse_domain, + "URI": parse_URI, + "nonce": parse_nonce, + "nonce_value": parse_nonce_value, + "opaque": parse_opaque, + "stale": parse_stale, + "algorithm": parse_algorithm, + "qop_options": parse_qop_options, + "qop_value": parse_qop_value, + "Proxy_Require": parse_Proxy_Require, + "Record_Route": parse_Record_Route, + "rec_route": parse_rec_route, + "Reason": parse_Reason, + "reason_param": parse_reason_param, + "reason_cause": parse_reason_cause, + "Require": parse_Require, + "Route": parse_Route, + "route_param": parse_route_param, + "Subscription_State": parse_Subscription_State, + "substate_value": parse_substate_value, + "subexp_params": parse_subexp_params, + "event_reason_value": parse_event_reason_value, + "Subject": parse_Subject, + "Supported": parse_Supported, + "To": parse_To, + "to_param": parse_to_param, + "Via": parse_Via, + "via_param": parse_via_param, + "via_params": parse_via_params, + "via_ttl": parse_via_ttl, + "via_maddr": parse_via_maddr, + "via_received": parse_via_received, + "via_branch": parse_via_branch, + "response_port": parse_response_port, + "rport": parse_rport, + "sent_protocol": parse_sent_protocol, + "protocol_name": parse_protocol_name, + "transport": parse_transport, + "sent_by": parse_sent_by, + "via_host": parse_via_host, + "via_port": parse_via_port, + "ttl": parse_ttl, + "WWW_Authenticate": parse_WWW_Authenticate, + "Session_Expires": parse_Session_Expires, + "s_e_expires": parse_s_e_expires, + "s_e_params": parse_s_e_params, + "s_e_refresher": parse_s_e_refresher, + "extension_header": parse_extension_header, + "header_value": parse_header_value, + "message_body": parse_message_body, + "uuid_URI": parse_uuid_URI, + "uuid": parse_uuid, + "hex4": parse_hex4, + "hex8": parse_hex8, + "hex12": parse_hex12, + "Refer_To": parse_Refer_To, + "Replaces": parse_Replaces, + "call_id": parse_call_id, + "replaces_param": parse_replaces_param, + "to_tag": parse_to_tag, + "from_tag": parse_from_tag, + "early_flag": parse_early_flag + }; + + if (startRule !== undefined) { + if (parseFunctions[startRule] === undefined) { + throw new Error("Invalid rule name: " + quote(startRule) + "."); + } + } else { + startRule = "CRLF"; + } + + var pos = 0; + var reportFailures = 0; + var rightmostFailuresPos = 0; + var rightmostFailuresExpected = []; + + function padLeft(input, padding, length) { + var result = input; + var padLength = length - input.length; + + for (var i = 0; i < padLength; i++) { + result = padding + result; + } + + return result; + } + + function escape(ch) { + var charCode = ch.charCodeAt(0); + var escapeChar; + var length; + + if (charCode <= 0xFF) { + escapeChar = 'x'; + length = 2; + } else { + escapeChar = 'u'; + length = 4; + } + + return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length); + } + + function matchFailed(failure) { + if (pos < rightmostFailuresPos) { + return; + } + + if (pos > rightmostFailuresPos) { + rightmostFailuresPos = pos; + rightmostFailuresExpected = []; + } + + rightmostFailuresExpected.push(failure); + } + + function parse_CRLF() { + var result0; + + if (input.substr(pos, 2) === "\r\n") { + result0 = "\r\n"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"\\r\\n\""); + } + } + + return result0; + } + + function parse_DIGIT() { + var result0; + + if (/^[0-9]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[0-9]"); + } + } + + return result0; + } + + function parse_ALPHA() { + var result0; + + if (/^[a-zA-Z]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[a-zA-Z]"); + } + } + + return result0; + } + + function parse_HEXDIG() { + var result0; + + if (/^[0-9a-fA-F]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[0-9a-fA-F]"); + } + } + + return result0; + } + + function parse_WSP() { + var result0; + result0 = parse_SP(); + + if (result0 === null) { + result0 = parse_HTAB(); + } + + return result0; + } + + function parse_OCTET() { + var result0; + + if (/^[\0-\xFF]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\0-\\xFF]"); + } + } + + return result0; + } + + function parse_DQUOTE() { + var result0; + + if (/^["]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\"]"); + } + } + + return result0; + } + + function parse_SP() { + var result0; + + if (input.charCodeAt(pos) === 32) { + result0 = " "; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\" \""); + } + } + + return result0; + } + + function parse_HTAB() { + var result0; + + if (input.charCodeAt(pos) === 9) { + result0 = "\t"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"\\t\""); + } + } + + return result0; + } + + function parse_alphanum() { + var result0; + + if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[a-zA-Z0-9]"); + } + } + + return result0; + } + + function parse_reserved() { + var result0; + + if (input.charCodeAt(pos) === 59) { + result0 = ";"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 64) { + result0 = "@"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_unreserved() { + var result0; + result0 = parse_alphanum(); + + if (result0 === null) { + result0 = parse_mark(); + } + + return result0; + } + + function parse_mark() { + var result0; + + if (input.charCodeAt(pos) === 45) { + result0 = "-"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 95) { + result0 = "_"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 46) { + result0 = "."; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 33) { + result0 = "!"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 126) { + result0 = "~"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 42) { + result0 = "*"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 39) { + result0 = "'"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 40) { + result0 = "("; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 41) { + result0 = ")"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_escaped() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.charCodeAt(pos) === 37) { + result0 = "%"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result0 !== null) { + result1 = parse_HEXDIG(); + + if (result1 !== null) { + result2 = parse_HEXDIG(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, escaped) { + return escaped.join(''); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_LWS() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + pos2 = pos; + result0 = []; + result1 = parse_WSP(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_WSP(); + } + + if (result0 !== null) { + result1 = parse_CRLF(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos2; + } + } else { + result0 = null; + pos = pos2; + } + + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result2 = parse_WSP(); + + if (result2 !== null) { + result1 = []; + + while (result2 !== null) { + result1.push(result2); + result2 = parse_WSP(); + } + } else { + result1 = null; + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return " "; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_SWS() { + var result0; + result0 = parse_LWS(); + result0 = result0 !== null ? result0 : ""; + return result0; + } + + function parse_HCOLON() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = []; + result1 = parse_SP(); + + if (result1 === null) { + result1 = parse_HTAB(); + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_SP(); + + if (result1 === null) { + result1 = parse_HTAB(); + } + } + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ':'; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_TEXT_UTF8_TRIM() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result1 = parse_TEXT_UTF8char(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_TEXT_UTF8char(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = []; + result3 = parse_LWS(); + + while (result3 !== null) { + result2.push(result3); + result3 = parse_LWS(); + } + + if (result2 !== null) { + result3 = parse_TEXT_UTF8char(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = []; + result3 = parse_LWS(); + + while (result3 !== null) { + result2.push(result3); + result3 = parse_LWS(); + } + + if (result2 !== null) { + result3 = parse_TEXT_UTF8char(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_TEXT_UTF8char() { + var result0; + + if (/^[!-~]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[!-~]"); + } + } + + if (result0 === null) { + result0 = parse_UTF8_NONASCII(); + } + + return result0; + } + + function parse_UTF8_NONASCII() { + var result0; + + if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\x80-\\uFFFF]"); + } + } + + return result0; + } + + function parse_UTF8_CONT() { + var result0; + + if (/^[\x80-\xBF]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\x80-\\xBF]"); + } + } + + return result0; + } + + function parse_LHEX() { + var result0; + result0 = parse_DIGIT(); + + if (result0 === null) { + if (/^[a-f]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[a-f]"); + } + } + } + + return result0; + } + + function parse_token() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + } + } + } + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + } + } + } + } + } + } + } + } + } + } + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_token_nodot() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + } + } + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + } + } + } + } + } + } + } + } + } + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_separators() { + var result0; + + if (input.charCodeAt(pos) === 40) { + result0 = "("; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 41) { + result0 = ")"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 60) { + result0 = "<"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"<\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 62) { + result0 = ">"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\">\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 64) { + result0 = "@"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 59) { + result0 = ";"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 92) { + result0 = "\\"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"\\\\\""); + } + } + + if (result0 === null) { + result0 = parse_DQUOTE(); + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 91) { + result0 = "["; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 93) { + result0 = "]"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 123) { + result0 = "{"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"{\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 125) { + result0 = "}"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"}\""); + } + } + + if (result0 === null) { + result0 = parse_SP(); + + if (result0 === null) { + result0 = parse_HTAB(); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_word() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 40) { + result1 = "("; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 41) { + result1 = ")"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 60) { + result1 = "<"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"<\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 62) { + result1 = ">"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\">\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 92) { + result1 = "\\"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"\\\\\""); + } + } + + if (result1 === null) { + result1 = parse_DQUOTE(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 47) { + result1 = "/"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 91) { + result1 = "["; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 93) { + result1 = "]"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 63) { + result1 = "?"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 123) { + result1 = "{"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"{\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 125) { + result1 = "}"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"}\""); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_alphanum(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 33) { + result1 = "!"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 37) { + result1 = "%"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"%\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 95) { + result1 = "_"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 96) { + result1 = "`"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"`\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 39) { + result1 = "'"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"'\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 126) { + result1 = "~"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"~\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 40) { + result1 = "("; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 41) { + result1 = ")"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 60) { + result1 = "<"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"<\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 62) { + result1 = ">"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\">\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 92) { + result1 = "\\"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"\\\\\""); + } + } + + if (result1 === null) { + result1 = parse_DQUOTE(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 47) { + result1 = "/"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 91) { + result1 = "["; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 93) { + result1 = "]"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 63) { + result1 = "?"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 123) { + result1 = "{"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"{\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 125) { + result1 = "}"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"}\""); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_STAR() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 42) { + result1 = "*"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"*\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "*"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_SLASH() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 47) { + result1 = "/"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "/"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_EQUAL() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "="; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_LPAREN() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 40) { + result1 = "("; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"(\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "("; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_RPAREN() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 41) { + result1 = ")"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\")\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ")"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_RAQUOT() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.charCodeAt(pos) === 62) { + result0 = ">"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\">\""); + } + } + + if (result0 !== null) { + result1 = parse_SWS(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ">"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_LAQUOT() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 60) { + result1 = "<"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"<\""); + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "<"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_COMMA() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ","; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_SEMI() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ";"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_COLON() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_SWS(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return ":"; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_LDQUOT() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + result1 = parse_DQUOTE(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "\""; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_RDQUOT() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DQUOTE(); + + if (result0 !== null) { + result1 = parse_SWS(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return "\""; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_comment() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_LPAREN(); + + if (result0 !== null) { + result1 = []; + result2 = parse_ctext(); + + if (result2 === null) { + result2 = parse_quoted_pair(); + + if (result2 === null) { + result2 = parse_comment(); + } + } + + while (result2 !== null) { + result1.push(result2); + result2 = parse_ctext(); + + if (result2 === null) { + result2 = parse_quoted_pair(); + + if (result2 === null) { + result2 = parse_comment(); + } + } + } + + if (result1 !== null) { + result2 = parse_RPAREN(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_ctext() { + var result0; + + if (/^[!-']/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[!-']"); + } + } + + if (result0 === null) { + if (/^[*-[]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[*-[]"); + } + } + + if (result0 === null) { + if (/^[\]-~]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\]-~]"); + } + } + + if (result0 === null) { + result0 = parse_UTF8_NONASCII(); + + if (result0 === null) { + result0 = parse_LWS(); + } + } + } + } + + return result0; + } + + function parse_quoted_string() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + result1 = parse_DQUOTE(); + + if (result1 !== null) { + result2 = []; + result3 = parse_qdtext(); + + if (result3 === null) { + result3 = parse_quoted_pair(); + } + + while (result3 !== null) { + result2.push(result3); + result3 = parse_qdtext(); + + if (result3 === null) { + result3 = parse_quoted_pair(); + } + } + + if (result2 !== null) { + result3 = parse_DQUOTE(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_quoted_string_clean() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_SWS(); + + if (result0 !== null) { + result1 = parse_DQUOTE(); + + if (result1 !== null) { + result2 = []; + result3 = parse_qdtext(); + + if (result3 === null) { + result3 = parse_quoted_pair(); + } + + while (result3 !== null) { + result2.push(result3); + result3 = parse_qdtext(); + + if (result3 === null) { + result3 = parse_quoted_pair(); + } + } + + if (result2 !== null) { + result3 = parse_DQUOTE(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var trimmed = input.substring(pos, offset).trim(); + return trimmed.substring(1, trimmed.length - 1) // remove outer quotes + .replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g, '$1'); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_qdtext() { + var result0; + result0 = parse_LWS(); + + if (result0 === null) { + if (input.charCodeAt(pos) === 33) { + result0 = "!"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"!\""); + } + } + + if (result0 === null) { + if (/^[#-[]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[#-[]"); + } + } + + if (result0 === null) { + if (/^[\]-~]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[\\]-~]"); + } + } + + if (result0 === null) { + result0 = parse_UTF8_NONASCII(); + } + } + } + } + + return result0; + } + + function parse_quoted_pair() { + var result0, result1; + var pos0; + pos0 = pos; + + if (input.charCodeAt(pos) === 92) { + result0 = "\\"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"\\\\\""); + } + } + + if (result0 !== null) { + if (/^[\0-\t]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[\\0-\\t]"); + } + } + + if (result1 === null) { + if (/^[\x0B-\f]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[\\x0B-\\f]"); + } + } + + if (result1 === null) { + if (/^[\x0E-]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[\\x0E-]"); + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_SIP_URI_noparams() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_uri_scheme(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_userinfo(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_hostport(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + try { + data.uri = new URI(data.scheme, data.user, data.host, data.port); + delete data.scheme; + delete data.user; + delete data.host; + delete data.host_type; + delete data.port; + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_SIP_URI() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_uri_scheme(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_userinfo(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_hostport(); + + if (result3 !== null) { + result4 = parse_uri_parameters(); + + if (result4 !== null) { + result5 = parse_headers(); + result5 = result5 !== null ? result5 : ""; + + if (result5 !== null) { + result0 = [result0, result1, result2, result3, result4, result5]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var header; + + try { + data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers); + delete data.scheme; + delete data.user; + delete data.host; + delete data.host_type; + delete data.port; + delete data.uri_params; + + if (startRule === 'SIP_URI') { + data = data.uri; + } + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_uri_scheme() { + var result0; + result0 = parse_uri_scheme_sips(); + + if (result0 === null) { + result0 = parse_uri_scheme_sip(); + } + + return result0; + } + + function parse_uri_scheme_sips() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 4).toLowerCase() === "sips") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"sips\""); + } + } + + if (result0 !== null) { + result0 = function (offset, scheme) { + data.scheme = scheme.toLowerCase(); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_uri_scheme_sip() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 3).toLowerCase() === "sip") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"sip\""); + } + } + + if (result0 !== null) { + result0 = function (offset, scheme) { + data.scheme = scheme.toLowerCase(); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_userinfo() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_user(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_password(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + if (input.charCodeAt(pos) === 64) { + result2 = "@"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.user = decodeURIComponent(input.substring(pos - 1, offset)); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_user() { + var result0, result1; + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + result1 = parse_user_unreserved(); + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + result1 = parse_user_unreserved(); + } + } + } + } else { + result0 = null; + } + + return result0; + } + + function parse_user_unreserved() { + var result0; + + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 59) { + result0 = ";"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_password() { + var result0, result1; + var pos0; + pos0 = pos; + result0 = []; + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 38) { + result1 = "&"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 36) { + result1 = "$"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 38) { + result1 = "&"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 36) { + result1 = "$"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.password = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_hostport() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + result0 = parse_host(); + + if (result0 !== null) { + pos1 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_port(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos1; + } + } else { + result1 = null; + pos = pos1; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_host() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_hostname(); + + if (result0 === null) { + result0 = parse_IPv4address(); + + if (result0 === null) { + result0 = parse_IPv6reference(); + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.host = input.substring(pos, offset).toLowerCase(); + return data.host; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_hostname() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = []; + pos2 = pos; + result1 = parse_domainlabel(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + while (result1 !== null) { + result0.push(result1); + pos2 = pos; + result1 = parse_domainlabel(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + } + + if (result0 !== null) { + result1 = parse_toplabel(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.host_type = 'domain'; + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_domainlabel() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_alphanum(); + + if (result0 !== null) { + result1 = []; + result2 = parse_alphanum(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + } + } + + while (result2 !== null) { + result1.push(result2); + result2 = parse_alphanum(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_toplabel() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_ALPHA(); + + if (result0 !== null) { + result1 = []; + result2 = parse_alphanum(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + } + } + + while (result2 !== null) { + result1.push(result2); + result2 = parse_alphanum(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 95) { + result2 = "_"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"_\""); + } + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_IPv6reference() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.charCodeAt(pos) === 91) { + result0 = "["; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result0 !== null) { + result1 = parse_IPv6address(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 93) { + result2 = "]"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.host_type = 'IPv6'; + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_IPv6address() { + var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + if (input.charCodeAt(pos) === 58) { + result7 = ":"; + pos++; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result7 !== null) { + result8 = parse_h16(); + + if (result8 !== null) { + if (input.charCodeAt(pos) === 58) { + result9 = ":"; + pos++; + } else { + result9 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result9 !== null) { + result10 = parse_h16(); + + if (result10 !== null) { + if (input.charCodeAt(pos) === 58) { + result11 = ":"; + pos++; + } else { + result11 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result11 !== null) { + result12 = parse_ls32(); + + if (result12 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + if (input.charCodeAt(pos) === 58) { + result8 = ":"; + pos++; + } else { + result8 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result8 !== null) { + result9 = parse_h16(); + + if (result9 !== null) { + if (input.charCodeAt(pos) === 58) { + result10 = ":"; + pos++; + } else { + result10 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result10 !== null) { + result11 = parse_ls32(); + + if (result11 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + if (input.charCodeAt(pos) === 58) { + result8 = ":"; + pos++; + } else { + result8 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result8 !== null) { + result9 = parse_ls32(); + + if (result9 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_ls32(); + + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_ls32(); + + if (result5 !== null) { + result0 = [result0, result1, result2, result3, result4, result5]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_ls32(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_ls32(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + + if (input.substr(pos, 2) === "::") { + result0 = "::"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result0 !== null) { + result1 = parse_h16(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + if (input.substr(pos, 2) === "::") { + result1 = "::"; + pos += 2; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + if (input.charCodeAt(pos) === 58) { + result7 = ":"; + pos++; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result7 !== null) { + result8 = parse_h16(); + + if (result8 !== null) { + if (input.charCodeAt(pos) === 58) { + result9 = ":"; + pos++; + } else { + result9 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result9 !== null) { + result10 = parse_ls32(); + + if (result10 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + if (input.substr(pos, 2) === "::") { + result2 = "::"; + pos += 2; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + if (input.charCodeAt(pos) === 58) { + result8 = ":"; + pos++; + } else { + result8 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result8 !== null) { + result9 = parse_ls32(); + + if (result9 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + if (input.substr(pos, 2) === "::") { + result3 = "::"; + pos += 2; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + if (input.charCodeAt(pos) === 58) { + result7 = ":"; + pos++; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result7 !== null) { + result8 = parse_ls32(); + + if (result8 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + if (input.substr(pos, 2) === "::") { + result4 = "::"; + pos += 2; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_ls32(); + + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos2; + } + } else { + result4 = null; + pos = pos2; + } + + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + if (input.substr(pos, 2) === "::") { + result5 = "::"; + pos += 2; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result5 !== null) { + result6 = parse_ls32(); + + if (result6 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos2; + } + } else { + result4 = null; + pos = pos2; + } + + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + + result5 = result5 !== null ? result5 : ""; + + if (result5 !== null) { + if (input.substr(pos, 2) === "::") { + result6 = "::"; + pos += 2; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + pos1 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result2 = ":"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result2 !== null) { + result3 = parse_h16(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result3 = ":"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result3 !== null) { + result4 = parse_h16(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos2; + } + } else { + result3 = null; + pos = pos2; + } + + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result4 = ":"; + pos++; + } else { + result4 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result4 !== null) { + result5 = parse_h16(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos2; + } + } else { + result4 = null; + pos = pos2; + } + + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result5 = ":"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result5 !== null) { + result6 = parse_h16(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + + result5 = result5 !== null ? result5 : ""; + + if (result5 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 58) { + result6 = ":"; + pos++; + } else { + result6 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result6 !== null) { + result7 = parse_h16(); + + if (result7 !== null) { + result6 = [result6, result7]; + } else { + result6 = null; + pos = pos2; + } + } else { + result6 = null; + pos = pos2; + } + + result6 = result6 !== null ? result6 : ""; + + if (result6 !== null) { + if (input.substr(pos, 2) === "::") { + result7 = "::"; + pos += 2; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\"::\""); + } + } + + if (result7 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.host_type = 'IPv6'; + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_h16() { + var result0, result1, result2, result3; + var pos0; + pos0 = pos; + result0 = parse_HEXDIG(); + + if (result0 !== null) { + result1 = parse_HEXDIG(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_HEXDIG(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_HEXDIG(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_ls32() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_h16(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_h16(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + result0 = parse_IPv4address(); + } + + return result0; + } + + function parse_IPv4address() { + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_dec_octet(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 !== null) { + result2 = parse_dec_octet(); + + if (result2 !== null) { + if (input.charCodeAt(pos) === 46) { + result3 = "."; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result3 !== null) { + result4 = parse_dec_octet(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 46) { + result5 = "."; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result5 !== null) { + result6 = parse_dec_octet(); + + if (result6 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.host_type = 'IPv4'; + return input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_dec_octet() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 2) === "25") { + result0 = "25"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"25\""); + } + } + + if (result0 !== null) { + if (/^[0-5]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[0-5]"); + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + + if (input.charCodeAt(pos) === 50) { + result0 = "2"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"2\""); + } + } + + if (result0 !== null) { + if (/^[0-4]/.test(input.charAt(pos))) { + result1 = input.charAt(pos); + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("[0-4]"); + } + } + + if (result1 !== null) { + result2 = parse_DIGIT(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + + if (input.charCodeAt(pos) === 49) { + result0 = "1"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"1\""); + } + } + + if (result0 !== null) { + result1 = parse_DIGIT(); + + if (result1 !== null) { + result2 = parse_DIGIT(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + + if (/^[1-9]/.test(input.charAt(pos))) { + result0 = input.charAt(pos); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("[1-9]"); + } + } + + if (result0 !== null) { + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + result0 = parse_DIGIT(); + } + } + } + } + + return result0; + } + + function parse_port() { + var result0, result1, result2, result3, result4; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DIGIT(); + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_DIGIT(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_DIGIT(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result4 = parse_DIGIT(); + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, port) { + port = parseInt(port.join('')); + data.port = port; + return port; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_uri_parameters() { + var result0, result1, result2; + var pos0; + result0 = []; + pos0 = pos; + + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 !== null) { + result2 = parse_uri_parameter(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos0; + } + } else { + result1 = null; + pos = pos0; + } + + while (result1 !== null) { + result0.push(result1); + pos0 = pos; + + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 !== null) { + result2 = parse_uri_parameter(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos0; + } + } else { + result1 = null; + pos = pos0; + } + } + + return result0; + } + + function parse_uri_parameter() { + var result0; + result0 = parse_transport_param(); + + if (result0 === null) { + result0 = parse_user_param(); + + if (result0 === null) { + result0 = parse_method_param(); + + if (result0 === null) { + result0 = parse_ttl_param(); + + if (result0 === null) { + result0 = parse_maddr_param(); + + if (result0 === null) { + result0 = parse_lr_param(); + + if (result0 === null) { + result0 = parse_other_param(); + } + } + } + } + } + } + + return result0; + } + + function parse_transport_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 10).toLowerCase() === "transport=") { + result0 = input.substr(pos, 10); + pos += 10; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"transport=\""); + } + } + + if (result0 !== null) { + if (input.substr(pos, 3).toLowerCase() === "udp") { + result1 = input.substr(pos, 3); + pos += 3; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"udp\""); + } + } + + if (result1 === null) { + if (input.substr(pos, 3).toLowerCase() === "tcp") { + result1 = input.substr(pos, 3); + pos += 3; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"tcp\""); + } + } + + if (result1 === null) { + if (input.substr(pos, 4).toLowerCase() === "sctp") { + result1 = input.substr(pos, 4); + pos += 4; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"sctp\""); + } + } + + if (result1 === null) { + if (input.substr(pos, 3).toLowerCase() === "tls") { + result1 = input.substr(pos, 3); + pos += 3; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"tls\""); + } + } + + if (result1 === null) { + result1 = parse_token(); + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, transport) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['transport'] = transport.toLowerCase(); + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_user_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 5).toLowerCase() === "user=") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"user=\""); + } + } + + if (result0 !== null) { + if (input.substr(pos, 5).toLowerCase() === "phone") { + result1 = input.substr(pos, 5); + pos += 5; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"phone\""); + } + } + + if (result1 === null) { + if (input.substr(pos, 2).toLowerCase() === "ip") { + result1 = input.substr(pos, 2); + pos += 2; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"ip\""); + } + } + + if (result1 === null) { + result1 = parse_token(); + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, user) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['user'] = user.toLowerCase(); + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_method_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 7).toLowerCase() === "method=") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"method=\""); + } + } + + if (result0 !== null) { + result1 = parse_Method(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, method) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['method'] = method; + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_ttl_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 4).toLowerCase() === "ttl=") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"ttl=\""); + } + } + + if (result0 !== null) { + result1 = parse_ttl(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, ttl) { + if (!data.params) data.params = {}; + data.params['ttl'] = ttl; + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_maddr_param() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6).toLowerCase() === "maddr=") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"maddr=\""); + } + } + + if (result0 !== null) { + result1 = parse_host(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, maddr) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['maddr'] = maddr; + }(pos0, result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_lr_param() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 2).toLowerCase() === "lr") { + result0 = input.substr(pos, 2); + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"lr\""); + } + } + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + if (!data.uri_params) data.uri_params = {}; + data.uri_params['lr'] = undefined; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_other_param() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_pname(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 !== null) { + result2 = parse_pvalue(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, param, value) { + if (!data.uri_params) data.uri_params = {}; + + if (typeof value === 'undefined') { + value = undefined; + } else { + value = value[1]; + } + + data.uri_params[param.toLowerCase()] = value; + }(pos0, result0[0], result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_pname() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_paramchar(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_paramchar(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, pname) { + return pname.join(''); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_pvalue() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_paramchar(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_paramchar(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, pvalue) { + return pvalue.join(''); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_paramchar() { + var result0; + result0 = parse_param_unreserved(); + + if (result0 === null) { + result0 = parse_unreserved(); + + if (result0 === null) { + result0 = parse_escaped(); + } + } + + return result0; + } + + function parse_param_unreserved() { + var result0; + + if (input.charCodeAt(pos) === 91) { + result0 = "["; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 93) { + result0 = "]"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_headers() { + var result0, result1, result2, result3, result4; + var pos0, pos1; + pos0 = pos; + + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 !== null) { + result1 = parse_header(); + + if (result1 !== null) { + result2 = []; + pos1 = pos; + + if (input.charCodeAt(pos) === 38) { + result3 = "&"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result3 !== null) { + result4 = parse_header(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos1; + } + } else { + result3 = null; + pos = pos1; + } + + while (result3 !== null) { + result2.push(result3); + pos1 = pos; + + if (input.charCodeAt(pos) === 38) { + result3 = "&"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result3 !== null) { + result4 = parse_header(); + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos1; + } + } else { + result3 = null; + pos = pos1; + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_header() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_hname(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 !== null) { + result2 = parse_hvalue(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, hname, hvalue) { + hname = hname.join('').toLowerCase(); + hvalue = hvalue.join(''); + if (!data.uri_headers) data.uri_headers = {}; + + if (!data.uri_headers[hname]) { + data.uri_headers[hname] = [hvalue]; + } else { + data.uri_headers[hname].push(hvalue); + } + }(pos0, result0[0], result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_hname() { + var result0, result1; + result1 = parse_hnv_unreserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_hnv_unreserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + } + } + } + } else { + result0 = null; + } + + return result0; + } + + function parse_hvalue() { + var result0, result1; + result0 = []; + result1 = parse_hnv_unreserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + } + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_hnv_unreserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + } + } + } + + return result0; + } + + function parse_hnv_unreserved() { + var result0; + + if (input.charCodeAt(pos) === 91) { + result0 = "["; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"[\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 93) { + result0 = "]"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"]\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_Request_Response() { + var result0; + result0 = parse_Status_Line(); + + if (result0 === null) { + result0 = parse_Request_Line(); + } + + return result0; + } + + function parse_Request_Line() { + var result0, result1, result2, result3, result4; + var pos0; + pos0 = pos; + result0 = parse_Method(); + + if (result0 !== null) { + result1 = parse_SP(); + + if (result1 !== null) { + result2 = parse_Request_URI(); + + if (result2 !== null) { + result3 = parse_SP(); + + if (result3 !== null) { + result4 = parse_SIP_Version(); + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Request_URI() { + var result0; + result0 = parse_SIP_URI(); + + if (result0 === null) { + result0 = parse_absoluteURI(); + } + + return result0; + } + + function parse_absoluteURI() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_scheme(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 !== null) { + result2 = parse_hier_part(); + + if (result2 === null) { + result2 = parse_opaque_part(); + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_hier_part() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + result0 = parse_net_path(); + + if (result0 === null) { + result0 = parse_abs_path(); + } + + if (result0 !== null) { + pos1 = pos; + + if (input.charCodeAt(pos) === 63) { + result1 = "?"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result1 !== null) { + result2 = parse_query(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos1; + } + } else { + result1 = null; + pos = pos1; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_net_path() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 2) === "//") { + result0 = "//"; + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"//\""); + } + } + + if (result0 !== null) { + result1 = parse_authority(); + + if (result1 !== null) { + result2 = parse_abs_path(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_abs_path() { + var result0, result1; + var pos0; + pos0 = pos; + + if (input.charCodeAt(pos) === 47) { + result0 = "/"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result0 !== null) { + result1 = parse_path_segments(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_opaque_part() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_uric_no_slash(); + + if (result0 !== null) { + result1 = []; + result2 = parse_uric(); + + while (result2 !== null) { + result1.push(result2); + result2 = parse_uric(); + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_uric() { + var result0; + result0 = parse_reserved(); + + if (result0 === null) { + result0 = parse_unreserved(); + + if (result0 === null) { + result0 = parse_escaped(); + } + } + + return result0; + } + + function parse_uric_no_slash() { + var result0; + result0 = parse_unreserved(); + + if (result0 === null) { + result0 = parse_escaped(); + + if (result0 === null) { + if (input.charCodeAt(pos) === 59) { + result0 = ";"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 63) { + result0 = "?"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"?\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 64) { + result0 = "@"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_path_segments() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_segment(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + + if (input.charCodeAt(pos) === 47) { + result2 = "/"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result2 !== null) { + result3 = parse_segment(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + + if (input.charCodeAt(pos) === 47) { + result2 = "/"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result2 !== null) { + result3 = parse_segment(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_segment() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = []; + result1 = parse_pchar(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_pchar(); + } + + if (result0 !== null) { + result1 = []; + pos1 = pos; + + if (input.charCodeAt(pos) === 59) { + result2 = ";"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result2 !== null) { + result3 = parse_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + + if (input.charCodeAt(pos) === 59) { + result2 = ";"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result2 !== null) { + result3 = parse_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_param() { + var result0, result1; + result0 = []; + result1 = parse_pchar(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_pchar(); + } + + return result0; + } + + function parse_pchar() { + var result0; + result0 = parse_unreserved(); + + if (result0 === null) { + result0 = parse_escaped(); + + if (result0 === null) { + if (input.charCodeAt(pos) === 58) { + result0 = ":"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 64) { + result0 = "@"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 38) { + result0 = "&"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 61) { + result0 = "="; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 43) { + result0 = "+"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 36) { + result0 = "$"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result0 === null) { + if (input.charCodeAt(pos) === 44) { + result0 = ","; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + } + } + } + } + } + } + } + } + + return result0; + } + + function parse_scheme() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_ALPHA(); + + if (result0 !== null) { + result1 = []; + result2 = parse_ALPHA(); + + if (result2 === null) { + result2 = parse_DIGIT(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 43) { + result2 = "+"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + } + } + } + } + + while (result2 !== null) { + result1.push(result2); + result2 = parse_ALPHA(); + + if (result2 === null) { + result2 = parse_DIGIT(); + + if (result2 === null) { + if (input.charCodeAt(pos) === 43) { + result2 = "+"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 45) { + result2 = "-"; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result2 === null) { + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.scheme = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_authority() { + var result0; + result0 = parse_srvr(); + + if (result0 === null) { + result0 = parse_reg_name(); + } + + return result0; + } + + function parse_srvr() { + var result0, result1; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_userinfo(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_hostport(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + result0 = result0 !== null ? result0 : ""; + return result0; + } + + function parse_reg_name() { + var result0, result1; + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 36) { + result1 = "$"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 38) { + result1 = "&"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + } + } + } + } + } + } + } + } + } + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + if (input.charCodeAt(pos) === 36) { + result1 = "$"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"$\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 44) { + result1 = ","; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 59) { + result1 = ";"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\";\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 58) { + result1 = ":"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\":\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 38) { + result1 = "&"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"&\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 61) { + result1 = "="; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"=\""); + } + } + + if (result1 === null) { + if (input.charCodeAt(pos) === 43) { + result1 = "+"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"+\""); + } + } + } + } + } + } + } + } + } + } + } + } + } else { + result0 = null; + } + + return result0; + } + + function parse_query() { + var result0, result1; + result0 = []; + result1 = parse_uric(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_uric(); + } + + return result0; + } + + function parse_SIP_Version() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 3).toLowerCase() === "sip") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SIP\""); + } + } + + if (result0 !== null) { + if (input.charCodeAt(pos) === 47) { + result1 = "/"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"/\""); + } + } + + if (result1 !== null) { + result3 = parse_DIGIT(); + + if (result3 !== null) { + result2 = []; + + while (result3 !== null) { + result2.push(result3); + result3 = parse_DIGIT(); + } + } else { + result2 = null; + } + + if (result2 !== null) { + if (input.charCodeAt(pos) === 46) { + result3 = "."; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result3 !== null) { + result5 = parse_DIGIT(); + + if (result5 !== null) { + result4 = []; + + while (result5 !== null) { + result4.push(result5); + result5 = parse_DIGIT(); + } + } else { + result4 = null; + } + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.sip_version = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_INVITEm() { + var result0; + + if (input.substr(pos, 6) === "INVITE") { + result0 = "INVITE"; + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"INVITE\""); + } + } + + return result0; + } + + function parse_ACKm() { + var result0; + + if (input.substr(pos, 3) === "ACK") { + result0 = "ACK"; + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"ACK\""); + } + } + + return result0; + } + + function parse_OPTIONSm() { + var result0; + + if (input.substr(pos, 7) === "OPTIONS") { + result0 = "OPTIONS"; + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"OPTIONS\""); + } + } + + return result0; + } + + function parse_BYEm() { + var result0; + + if (input.substr(pos, 3) === "BYE") { + result0 = "BYE"; + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"BYE\""); + } + } + + return result0; + } + + function parse_CANCELm() { + var result0; + + if (input.substr(pos, 6) === "CANCEL") { + result0 = "CANCEL"; + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"CANCEL\""); + } + } + + return result0; + } + + function parse_REGISTERm() { + var result0; + + if (input.substr(pos, 8) === "REGISTER") { + result0 = "REGISTER"; + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"REGISTER\""); + } + } + + return result0; + } + + function parse_SUBSCRIBEm() { + var result0; + + if (input.substr(pos, 9) === "SUBSCRIBE") { + result0 = "SUBSCRIBE"; + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SUBSCRIBE\""); + } + } + + return result0; + } + + function parse_NOTIFYm() { + var result0; + + if (input.substr(pos, 6) === "NOTIFY") { + result0 = "NOTIFY"; + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"NOTIFY\""); + } + } + + return result0; + } + + function parse_REFERm() { + var result0; + + if (input.substr(pos, 5) === "REFER") { + result0 = "REFER"; + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"REFER\""); + } + } + + return result0; + } + + function parse_Method() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_INVITEm(); + + if (result0 === null) { + result0 = parse_ACKm(); + + if (result0 === null) { + result0 = parse_OPTIONSm(); + + if (result0 === null) { + result0 = parse_BYEm(); + + if (result0 === null) { + result0 = parse_CANCELm(); + + if (result0 === null) { + result0 = parse_REGISTERm(); + + if (result0 === null) { + result0 = parse_SUBSCRIBEm(); + + if (result0 === null) { + result0 = parse_NOTIFYm(); + + if (result0 === null) { + result0 = parse_REFERm(); + + if (result0 === null) { + result0 = parse_token(); + } + } + } + } + } + } + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.method = input.substring(pos, offset); + return data.method; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Status_Line() { + var result0, result1, result2, result3, result4; + var pos0; + pos0 = pos; + result0 = parse_SIP_Version(); + + if (result0 !== null) { + result1 = parse_SP(); + + if (result1 !== null) { + result2 = parse_Status_Code(); + + if (result2 !== null) { + result3 = parse_SP(); + + if (result3 !== null) { + result4 = parse_Reason_Phrase(); + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Status_Code() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_extension_code(); + + if (result0 !== null) { + result0 = function (offset, status_code) { + data.status_code = parseInt(status_code.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_extension_code() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_DIGIT(); + + if (result0 !== null) { + result1 = parse_DIGIT(); + + if (result1 !== null) { + result2 = parse_DIGIT(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Reason_Phrase() { + var result0, result1; + var pos0; + pos0 = pos; + result0 = []; + result1 = parse_reserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + result1 = parse_UTF8_NONASCII(); + + if (result1 === null) { + result1 = parse_UTF8_CONT(); + + if (result1 === null) { + result1 = parse_SP(); + + if (result1 === null) { + result1 = parse_HTAB(); + } + } + } + } + } + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_reserved(); + + if (result1 === null) { + result1 = parse_unreserved(); + + if (result1 === null) { + result1 = parse_escaped(); + + if (result1 === null) { + result1 = parse_UTF8_NONASCII(); + + if (result1 === null) { + result1 = parse_UTF8_CONT(); + + if (result1 === null) { + result1 = parse_SP(); + + if (result1 === null) { + result1 = parse_HTAB(); + } + } + } + } + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.reason_phrase = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Allow_Events() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_event_type(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_event_type(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_event_type(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Call_ID() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_word(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 !== null) { + result2 = parse_word(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Contact() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + result0 = parse_STAR(); + + if (result0 === null) { + pos1 = pos; + result0 = parse_contact_param(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_contact_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_contact_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } + + if (result0 !== null) { + result0 = function (offset) { + var idx, length; + length = data.multi_header.length; + + for (idx = 0; idx < length; idx++) { + if (data.multi_header[idx].parsed === null) { + data = null; + break; + } + } + + if (data !== null) { + data = data.multi_header; + } else { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_contact_param() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_SIP_URI_noparams(); + + if (result0 === null) { + result0 = parse_name_addr(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_contact_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_contact_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var header; + if (!data.multi_header) data.multi_header = []; + + try { + header = new NameAddrHeader(data.uri, data.display_name, data.params); + delete data.uri; + delete data.display_name; + delete data.params; + } catch (e) { + header = null; + } + + data.multi_header.push({ + 'possition': pos, + 'offset': offset, + 'parsed': header + }); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_name_addr() { + var result0, result1, result2, result3; + var pos0; + pos0 = pos; + result0 = parse_display_name(); + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_LAQUOT(); + + if (result1 !== null) { + result2 = parse_SIP_URI(); + + if (result2 !== null) { + result3 = parse_RAQUOT(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_display_name() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_LWS(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_LWS(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 === null) { + result0 = parse_quoted_string_clean(); + } + + if (result0 !== null) { + result0 = function (offset, display_name) { + if (typeof display_name === 'string') { + // quoted_string_clean + data.display_name = display_name; + } else { + // token ( LWS token )* + data.display_name = display_name[1].reduce(function (acc, cur) { + return acc + cur[0] + cur[1]; + }, display_name[0]); + } + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_contact_params() { + var result0; + result0 = parse_c_p_q(); + + if (result0 === null) { + result0 = parse_c_p_expires(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + } + + return result0; + } + + function parse_c_p_q() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 1).toLowerCase() === "q") { + result0 = input.substr(pos, 1); + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"q\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_qvalue(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, q) { + if (!data.params) data.params = {}; + data.params['q'] = q; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_c_p_expires() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 7).toLowerCase() === "expires") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"expires\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_delta_seconds(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, expires) { + if (!data.params) data.params = {}; + data.params['expires'] = expires; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_delta_seconds() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_DIGIT(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, delta_seconds) { + return parseInt(delta_seconds.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_qvalue() { + var result0, result1, result2, result3, result4; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + + if (input.charCodeAt(pos) === 48) { + result0 = "0"; + pos++; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"0\""); + } + } + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 46) { + result1 = "."; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_DIGIT(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result4 = parse_DIGIT(); + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + result1 = [result1, result2, result3, result4]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + return parseFloat(input.substring(pos, offset)); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_generic_param() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_token(); + + if (result0 !== null) { + pos2 = pos; + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_gen_value(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, param, value) { + if (!data.params) data.params = {}; + + if (typeof value === 'undefined') { + value = undefined; + } else { + value = value[1]; + } + + data.params[param.toLowerCase()] = value; + }(pos0, result0[0], result0[1]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_gen_value() { + var result0; + result0 = parse_token(); + + if (result0 === null) { + result0 = parse_host(); + + if (result0 === null) { + result0 = parse_quoted_string(); + } + } + + return result0; + } + + function parse_Content_Disposition() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_disp_type(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_disp_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_disp_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_disp_type() { + var result0; + + if (input.substr(pos, 6).toLowerCase() === "render") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"render\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 7).toLowerCase() === "session") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"session\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 4).toLowerCase() === "icon") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"icon\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 5).toLowerCase() === "alert") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"alert\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + } + } + + return result0; + } + + function parse_disp_param() { + var result0; + result0 = parse_handling_param(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_handling_param() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 8).toLowerCase() === "handling") { + result0 = input.substr(pos, 8); + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"handling\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + if (input.substr(pos, 8).toLowerCase() === "optional") { + result2 = input.substr(pos, 8); + pos += 8; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"optional\""); + } + } + + if (result2 === null) { + if (input.substr(pos, 8).toLowerCase() === "required") { + result2 = input.substr(pos, 8); + pos += 8; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"required\""); + } + } + + if (result2 === null) { + result2 = parse_token(); + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Content_Encoding() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Content_Length() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_DIGIT(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, length) { + data = parseInt(length.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Content_Type() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_media_type(); + + if (result0 !== null) { + result0 = function (offset) { + data = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_media_type() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + result0 = parse_m_type(); + + if (result0 !== null) { + result1 = parse_SLASH(); + + if (result1 !== null) { + result2 = parse_m_subtype(); + + if (result2 !== null) { + result3 = []; + pos1 = pos; + result4 = parse_SEMI(); + + if (result4 !== null) { + result5 = parse_m_parameter(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + + while (result4 !== null) { + result3.push(result4); + pos1 = pos; + result4 = parse_SEMI(); + + if (result4 !== null) { + result5 = parse_m_parameter(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + } + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_m_type() { + var result0; + result0 = parse_discrete_type(); + + if (result0 === null) { + result0 = parse_composite_type(); + } + + return result0; + } + + function parse_discrete_type() { + var result0; + + if (input.substr(pos, 4).toLowerCase() === "text") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"text\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 5).toLowerCase() === "image") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"image\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 5).toLowerCase() === "audio") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"audio\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 5).toLowerCase() === "video") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"video\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 11).toLowerCase() === "application") { + result0 = input.substr(pos, 11); + pos += 11; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"application\""); + } + } + + if (result0 === null) { + result0 = parse_extension_token(); + } + } + } + } + } + + return result0; + } + + function parse_composite_type() { + var result0; + + if (input.substr(pos, 7).toLowerCase() === "message") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"message\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 9).toLowerCase() === "multipart") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"multipart\""); + } + } + + if (result0 === null) { + result0 = parse_extension_token(); + } + } + + return result0; + } + + function parse_extension_token() { + var result0; + result0 = parse_token(); + + if (result0 === null) { + result0 = parse_x_token(); + } + + return result0; + } + + function parse_x_token() { + var result0, result1; + var pos0; + pos0 = pos; + + if (input.substr(pos, 2).toLowerCase() === "x-") { + result0 = input.substr(pos, 2); + pos += 2; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"x-\""); + } + } + + if (result0 !== null) { + result1 = parse_token(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_m_subtype() { + var result0; + result0 = parse_extension_token(); + + if (result0 === null) { + result0 = parse_token(); + } + + return result0; + } + + function parse_m_parameter() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_m_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_m_value() { + var result0; + result0 = parse_token(); + + if (result0 === null) { + result0 = parse_quoted_string(); + } + + return result0; + } + + function parse_CSeq() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_CSeq_value(); + + if (result0 !== null) { + result1 = parse_LWS(); + + if (result1 !== null) { + result2 = parse_Method(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_CSeq_value() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_DIGIT(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, cseq_value) { + data.value = parseInt(cseq_value.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Expires() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_delta_seconds(); + + if (result0 !== null) { + result0 = function (offset, expires) { + data = expires; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Event() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_event_type(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, event_type) { + data.event = event_type.join('').toLowerCase(); + }(pos0, result0[0]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_event_type() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token_nodot(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result2 !== null) { + result3 = parse_token_nodot(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + + if (input.charCodeAt(pos) === 46) { + result2 = "."; + pos++; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\".\""); + } + } + + if (result2 !== null) { + result3 = parse_token_nodot(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_From() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_SIP_URI_noparams(); + + if (result0 === null) { + result0 = parse_name_addr(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_from_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_from_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var tag = data.tag; + + try { + data = new NameAddrHeader(data.uri, data.display_name, data.params); + + if (tag) { + data.setParam('tag', tag); + } + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_from_param() { + var result0; + result0 = parse_tag_param(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_tag_param() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 3).toLowerCase() === "tag") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"tag\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, tag) { + data.tag = tag; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Max_Forwards() { + var result0, result1; + var pos0; + pos0 = pos; + result1 = parse_DIGIT(); + + if (result1 !== null) { + result0 = []; + + while (result1 !== null) { + result0.push(result1); + result1 = parse_DIGIT(); + } + } else { + result0 = null; + } + + if (result0 !== null) { + result0 = function (offset, forwards) { + data = parseInt(forwards.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Min_Expires() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_delta_seconds(); + + if (result0 !== null) { + result0 = function (offset, min_expires) { + data = min_expires; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Name_Addr_Header() { + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = []; + result1 = parse_display_name(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_display_name(); + } + + if (result0 !== null) { + result1 = parse_LAQUOT(); + + if (result1 !== null) { + result2 = parse_SIP_URI(); + + if (result2 !== null) { + result3 = parse_RAQUOT(); + + if (result3 !== null) { + result4 = []; + pos2 = pos; + result5 = parse_SEMI(); + + if (result5 !== null) { + result6 = parse_generic_param(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + + while (result5 !== null) { + result4.push(result5); + pos2 = pos; + result5 = parse_SEMI(); + + if (result5 !== null) { + result6 = parse_generic_param(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + } + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + try { + data = new NameAddrHeader(data.uri, data.display_name, data.params); + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Proxy_Authenticate() { + var result0; + result0 = parse_challenge(); + return result0; + } + + function parse_challenge() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + + if (input.substr(pos, 6).toLowerCase() === "digest") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"Digest\""); + } + } + + if (result0 !== null) { + result1 = parse_LWS(); + + if (result1 !== null) { + result2 = parse_digest_cln(); + + if (result2 !== null) { + result3 = []; + pos1 = pos; + result4 = parse_COMMA(); + + if (result4 !== null) { + result5 = parse_digest_cln(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + + while (result4 !== null) { + result3.push(result4); + pos1 = pos; + result4 = parse_COMMA(); + + if (result4 !== null) { + result5 = parse_digest_cln(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + } + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + if (result0 === null) { + result0 = parse_other_challenge(); + } + + return result0; + } + + function parse_other_challenge() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = parse_LWS(); + + if (result1 !== null) { + result2 = parse_auth_param(); + + if (result2 !== null) { + result3 = []; + pos1 = pos; + result4 = parse_COMMA(); + + if (result4 !== null) { + result5 = parse_auth_param(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + + while (result4 !== null) { + result3.push(result4); + pos1 = pos; + result4 = parse_COMMA(); + + if (result4 !== null) { + result5 = parse_auth_param(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + } + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_auth_param() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 === null) { + result2 = parse_quoted_string(); + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_digest_cln() { + var result0; + result0 = parse_realm(); + + if (result0 === null) { + result0 = parse_domain(); + + if (result0 === null) { + result0 = parse_nonce(); + + if (result0 === null) { + result0 = parse_opaque(); + + if (result0 === null) { + result0 = parse_stale(); + + if (result0 === null) { + result0 = parse_algorithm(); + + if (result0 === null) { + result0 = parse_qop_options(); + + if (result0 === null) { + result0 = parse_auth_param(); + } + } + } + } + } + } + } + + return result0; + } + + function parse_realm() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 5).toLowerCase() === "realm") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"realm\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_realm_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_realm_value() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_quoted_string_clean(); + + if (result0 !== null) { + result0 = function (offset, realm) { + data.realm = realm; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_domain() { + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1; + pos0 = pos; + + if (input.substr(pos, 6).toLowerCase() === "domain") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"domain\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_LDQUOT(); + + if (result2 !== null) { + result3 = parse_URI(); + + if (result3 !== null) { + result4 = []; + pos1 = pos; + result6 = parse_SP(); + + if (result6 !== null) { + result5 = []; + + while (result6 !== null) { + result5.push(result6); + result6 = parse_SP(); + } + } else { + result5 = null; + } + + if (result5 !== null) { + result6 = parse_URI(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos1; + } + } else { + result5 = null; + pos = pos1; + } + + while (result5 !== null) { + result4.push(result5); + pos1 = pos; + result6 = parse_SP(); + + if (result6 !== null) { + result5 = []; + + while (result6 !== null) { + result5.push(result6); + result6 = parse_SP(); + } + } else { + result5 = null; + } + + if (result5 !== null) { + result6 = parse_URI(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos1; + } + } else { + result5 = null; + pos = pos1; + } + } + + if (result4 !== null) { + result5 = parse_RDQUOT(); + + if (result5 !== null) { + result0 = [result0, result1, result2, result3, result4, result5]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_URI() { + var result0; + result0 = parse_absoluteURI(); + + if (result0 === null) { + result0 = parse_abs_path(); + } + + return result0; + } + + function parse_nonce() { + var result0, result1, result2; + var pos0; + pos0 = pos; + + if (input.substr(pos, 5).toLowerCase() === "nonce") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"nonce\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_nonce_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_nonce_value() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_quoted_string_clean(); + + if (result0 !== null) { + result0 = function (offset, nonce) { + data.nonce = nonce; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_opaque() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6).toLowerCase() === "opaque") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"opaque\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_quoted_string_clean(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, opaque) { + data.opaque = opaque; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_stale() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + + if (input.substr(pos, 5).toLowerCase() === "stale") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"stale\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + pos1 = pos; + + if (input.substr(pos, 4).toLowerCase() === "true") { + result2 = input.substr(pos, 4); + pos += 4; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"true\""); + } + } + + if (result2 !== null) { + result2 = function (offset) { + data.stale = true; + }(pos1); + } + + if (result2 === null) { + pos = pos1; + } + + if (result2 === null) { + pos1 = pos; + + if (input.substr(pos, 5).toLowerCase() === "false") { + result2 = input.substr(pos, 5); + pos += 5; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"false\""); + } + } + + if (result2 !== null) { + result2 = function (offset) { + data.stale = false; + }(pos1); + } + + if (result2 === null) { + pos = pos1; + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_algorithm() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 9).toLowerCase() === "algorithm") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"algorithm\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + if (input.substr(pos, 3).toLowerCase() === "md5") { + result2 = input.substr(pos, 3); + pos += 3; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"MD5\""); + } + } + + if (result2 === null) { + if (input.substr(pos, 8).toLowerCase() === "md5-sess") { + result2 = input.substr(pos, 8); + pos += 8; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"MD5-sess\""); + } + } + + if (result2 === null) { + result2 = parse_token(); + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, algorithm) { + data.algorithm = algorithm.toUpperCase(); + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_qop_options() { + var result0, result1, result2, result3, result4, result5, result6; + var pos0, pos1, pos2; + pos0 = pos; + + if (input.substr(pos, 3).toLowerCase() === "qop") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"qop\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_LDQUOT(); + + if (result2 !== null) { + pos1 = pos; + result3 = parse_qop_value(); + + if (result3 !== null) { + result4 = []; + pos2 = pos; + + if (input.charCodeAt(pos) === 44) { + result5 = ","; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result5 !== null) { + result6 = parse_qop_value(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + + while (result5 !== null) { + result4.push(result5); + pos2 = pos; + + if (input.charCodeAt(pos) === 44) { + result5 = ","; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\",\""); + } + } + + if (result5 !== null) { + result6 = parse_qop_value(); + + if (result6 !== null) { + result5 = [result5, result6]; + } else { + result5 = null; + pos = pos2; + } + } else { + result5 = null; + pos = pos2; + } + } + + if (result4 !== null) { + result3 = [result3, result4]; + } else { + result3 = null; + pos = pos1; + } + } else { + result3 = null; + pos = pos1; + } + + if (result3 !== null) { + result4 = parse_RDQUOT(); + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_qop_value() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 8).toLowerCase() === "auth-int") { + result0 = input.substr(pos, 8); + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"auth-int\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 4).toLowerCase() === "auth") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"auth\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + + if (result0 !== null) { + result0 = function (offset, qop_value) { + data.qop || (data.qop = []); + data.qop.push(qop_value.toLowerCase()); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Proxy_Require() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Record_Route() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_rec_route(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_rec_route(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_rec_route(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var idx, length; + length = data.multi_header.length; + + for (idx = 0; idx < length; idx++) { + if (data.multi_header[idx].parsed === null) { + data = null; + break; + } + } + + if (data !== null) { + data = data.multi_header; + } else { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_rec_route() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_name_addr(); + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var header; + if (!data.multi_header) data.multi_header = []; + + try { + header = new NameAddrHeader(data.uri, data.display_name, data.params); + delete data.uri; + delete data.display_name; + delete data.params; + } catch (e) { + header = null; + } + + data.multi_header.push({ + 'possition': pos, + 'offset': offset, + 'parsed': header + }); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Reason() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 3).toLowerCase() === "sip") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SIP\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_reason_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_reason_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, protocol) { + data.protocol = protocol.toLowerCase(); + if (!data.params) data.params = {}; + + if (data.params.text && data.params.text[0] === '"') { + var text = data.params.text; + data.text = text.substring(1, text.length - 1); + delete data.params.text; + } + }(pos0, result0[0]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_reason_param() { + var result0; + result0 = parse_reason_cause(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_reason_cause() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 5).toLowerCase() === "cause") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"cause\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result3 = parse_DIGIT(); + + if (result3 !== null) { + result2 = []; + + while (result3 !== null) { + result2.push(result3); + result3 = parse_DIGIT(); + } + } else { + result2 = null; + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, cause) { + data.cause = parseInt(cause.join('')); + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Require() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Route() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_route_param(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_route_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_route_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_route_param() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_name_addr(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Subscription_State() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_substate_value(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_subexp_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_subexp_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_substate_value() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 6).toLowerCase() === "active") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"active\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 7).toLowerCase() === "pending") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"pending\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 10).toLowerCase() === "terminated") { + result0 = input.substr(pos, 10); + pos += 10; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"terminated\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.state = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_subexp_params() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6).toLowerCase() === "reason") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"reason\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_event_reason_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, reason) { + if (typeof reason !== 'undefined') data.reason = reason; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 7).toLowerCase() === "expires") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"expires\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_delta_seconds(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, expires) { + if (typeof expires !== 'undefined') data.expires = expires; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + if (result0 === null) { + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 11).toLowerCase() === "retry_after") { + result0 = input.substr(pos, 11); + pos += 11; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"retry_after\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_delta_seconds(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, retry_after) { + if (typeof retry_after !== 'undefined') data.retry_after = retry_after; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + if (result0 === null) { + result0 = parse_generic_param(); + } + } + } + + return result0; + } + + function parse_event_reason_value() { + var result0; + + if (input.substr(pos, 11).toLowerCase() === "deactivated") { + result0 = input.substr(pos, 11); + pos += 11; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"deactivated\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 9).toLowerCase() === "probation") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"probation\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 8).toLowerCase() === "rejected") { + result0 = input.substr(pos, 8); + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"rejected\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 7).toLowerCase() === "timeout") { + result0 = input.substr(pos, 7); + pos += 7; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"timeout\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 6).toLowerCase() === "giveup") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"giveup\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 10).toLowerCase() === "noresource") { + result0 = input.substr(pos, 10); + pos += 10; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"noresource\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 9).toLowerCase() === "invariant") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"invariant\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + } + } + } + } + } + + return result0; + } + + function parse_Subject() { + var result0; + result0 = parse_TEXT_UTF8_TRIM(); + result0 = result0 !== null ? result0 : ""; + return result0; + } + + function parse_Supported() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_token(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + result0 = result0 !== null ? result0 : ""; + return result0; + } + + function parse_To() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_SIP_URI_noparams(); + + if (result0 === null) { + result0 = parse_name_addr(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_to_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_to_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + var tag = data.tag; + + try { + data = new NameAddrHeader(data.uri, data.display_name, data.params); + + if (tag) { + data.setParam('tag', tag); + } + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_to_param() { + var result0; + result0 = parse_tag_param(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_Via() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_via_param(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_via_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_COMMA(); + + if (result2 !== null) { + result3 = parse_via_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_via_param() { + var result0, result1, result2, result3, result4, result5; + var pos0, pos1; + pos0 = pos; + result0 = parse_sent_protocol(); + + if (result0 !== null) { + result1 = parse_LWS(); + + if (result1 !== null) { + result2 = parse_sent_by(); + + if (result2 !== null) { + result3 = []; + pos1 = pos; + result4 = parse_SEMI(); + + if (result4 !== null) { + result5 = parse_via_params(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + + while (result4 !== null) { + result3.push(result4); + pos1 = pos; + result4 = parse_SEMI(); + + if (result4 !== null) { + result5 = parse_via_params(); + + if (result5 !== null) { + result4 = [result4, result5]; + } else { + result4 = null; + pos = pos1; + } + } else { + result4 = null; + pos = pos1; + } + } + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_via_params() { + var result0; + result0 = parse_via_ttl(); + + if (result0 === null) { + result0 = parse_via_maddr(); + + if (result0 === null) { + result0 = parse_via_received(); + + if (result0 === null) { + result0 = parse_via_branch(); + + if (result0 === null) { + result0 = parse_response_port(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + } + } + } + } + + return result0; + } + + function parse_via_ttl() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 3).toLowerCase() === "ttl") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"ttl\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_ttl(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_ttl_value) { + data.ttl = via_ttl_value; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_via_maddr() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 5).toLowerCase() === "maddr") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"maddr\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_host(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_maddr) { + data.maddr = via_maddr; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_via_received() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 8).toLowerCase() === "received") { + result0 = input.substr(pos, 8); + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"received\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_IPv4address(); + + if (result2 === null) { + result2 = parse_IPv6address(); + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_received) { + data.received = via_received; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_via_branch() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6).toLowerCase() === "branch") { + result0 = input.substr(pos, 6); + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"branch\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_branch) { + data.branch = via_branch; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_response_port() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + + if (input.substr(pos, 5).toLowerCase() === "rport") { + result0 = input.substr(pos, 5); + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"rport\""); + } + } + + if (result0 !== null) { + pos1 = pos; + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_rport(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos1; + } + } else { + result1 = null; + pos = pos1; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_rport() { + var result0, result1, result2, result3, result4; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DIGIT(); + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_DIGIT(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_DIGIT(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result4 = parse_DIGIT(); + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, rport) { + data.rport = parseInt(rport.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_sent_protocol() { + var result0, result1, result2, result3, result4; + var pos0; + pos0 = pos; + result0 = parse_protocol_name(); + + if (result0 !== null) { + result1 = parse_SLASH(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result3 = parse_SLASH(); + + if (result3 !== null) { + result4 = parse_transport(); + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_protocol_name() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 3).toLowerCase() === "sip") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SIP\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + + if (result0 !== null) { + result0 = function (offset, via_protocol) { + data.protocol = via_protocol; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_transport() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 3).toLowerCase() === "udp") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"UDP\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 3).toLowerCase() === "tcp") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"TCP\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 3).toLowerCase() === "tls") { + result0 = input.substr(pos, 3); + pos += 3; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"TLS\""); + } + } + + if (result0 === null) { + if (input.substr(pos, 4).toLowerCase() === "sctp") { + result0 = input.substr(pos, 4); + pos += 4; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"SCTP\""); + } + } + + if (result0 === null) { + result0 = parse_token(); + } + } + } + } + + if (result0 !== null) { + result0 = function (offset, via_transport) { + data.transport = via_transport; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_sent_by() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + result0 = parse_via_host(); + + if (result0 !== null) { + pos1 = pos; + result1 = parse_COLON(); + + if (result1 !== null) { + result2 = parse_via_port(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos1; + } + } else { + result1 = null; + pos = pos1; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_via_host() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_IPv4address(); + + if (result0 === null) { + result0 = parse_IPv6reference(); + + if (result0 === null) { + result0 = parse_hostname(); + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.host = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_via_port() { + var result0, result1, result2, result3, result4; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DIGIT(); + result0 = result0 !== null ? result0 : ""; + + if (result0 !== null) { + result1 = parse_DIGIT(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result3 = parse_DIGIT(); + result3 = result3 !== null ? result3 : ""; + + if (result3 !== null) { + result4 = parse_DIGIT(); + result4 = result4 !== null ? result4 : ""; + + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, via_sent_by_port) { + data.port = parseInt(via_sent_by_port.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_ttl() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_DIGIT(); + + if (result0 !== null) { + result1 = parse_DIGIT(); + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result2 = parse_DIGIT(); + result2 = result2 !== null ? result2 : ""; + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, ttl) { + return parseInt(ttl.join('')); + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_WWW_Authenticate() { + var result0; + result0 = parse_challenge(); + return result0; + } + + function parse_Session_Expires() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_s_e_expires(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_s_e_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_s_e_params(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_s_e_expires() { + var result0; + var pos0; + pos0 = pos; + result0 = parse_delta_seconds(); + + if (result0 !== null) { + result0 = function (offset, expires) { + data.expires = expires; + }(pos0, result0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_s_e_params() { + var result0; + result0 = parse_s_e_refresher(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + + return result0; + } + + function parse_s_e_refresher() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 9).toLowerCase() === "refresher") { + result0 = input.substr(pos, 9); + pos += 9; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"refresher\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + if (input.substr(pos, 3).toLowerCase() === "uac") { + result2 = input.substr(pos, 3); + pos += 3; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"uac\""); + } + } + + if (result2 === null) { + if (input.substr(pos, 3).toLowerCase() === "uas") { + result2 = input.substr(pos, 3); + pos += 3; + } else { + result2 = null; + + if (reportFailures === 0) { + matchFailed("\"uas\""); + } + } + } + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, s_e_refresher_value) { + data.refresher = s_e_refresher_value.toLowerCase(); + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_extension_header() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_token(); + + if (result0 !== null) { + result1 = parse_HCOLON(); + + if (result1 !== null) { + result2 = parse_header_value(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_header_value() { + var result0, result1; + result0 = []; + result1 = parse_TEXT_UTF8char(); + + if (result1 === null) { + result1 = parse_UTF8_CONT(); + + if (result1 === null) { + result1 = parse_LWS(); + } + } + + while (result1 !== null) { + result0.push(result1); + result1 = parse_TEXT_UTF8char(); + + if (result1 === null) { + result1 = parse_UTF8_CONT(); + + if (result1 === null) { + result1 = parse_LWS(); + } + } + } + + return result0; + } + + function parse_message_body() { + var result0, result1; + result0 = []; + result1 = parse_OCTET(); + + while (result1 !== null) { + result0.push(result1); + result1 = parse_OCTET(); + } + + return result0; + } + + function parse_uuid_URI() { + var result0, result1; + var pos0; + pos0 = pos; + + if (input.substr(pos, 5) === "uuid:") { + result0 = "uuid:"; + pos += 5; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"uuid:\""); + } + } + + if (result0 !== null) { + result1 = parse_uuid(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_uuid() { + var result0, result1, result2, result3, result4, result5, result6, result7, result8; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + result0 = parse_hex8(); + + if (result0 !== null) { + if (input.charCodeAt(pos) === 45) { + result1 = "-"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result1 !== null) { + result2 = parse_hex4(); + + if (result2 !== null) { + if (input.charCodeAt(pos) === 45) { + result3 = "-"; + pos++; + } else { + result3 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result3 !== null) { + result4 = parse_hex4(); + + if (result4 !== null) { + if (input.charCodeAt(pos) === 45) { + result5 = "-"; + pos++; + } else { + result5 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result5 !== null) { + result6 = parse_hex4(); + + if (result6 !== null) { + if (input.charCodeAt(pos) === 45) { + result7 = "-"; + pos++; + } else { + result7 = null; + + if (reportFailures === 0) { + matchFailed("\"-\""); + } + } + + if (result7 !== null) { + result8 = parse_hex12(); + + if (result8 !== null) { + result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, uuid) { + data = input.substring(pos + 5, offset); + }(pos0, result0[0]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_hex4() { + var result0, result1, result2, result3; + var pos0; + pos0 = pos; + result0 = parse_HEXDIG(); + + if (result0 !== null) { + result1 = parse_HEXDIG(); + + if (result1 !== null) { + result2 = parse_HEXDIG(); + + if (result2 !== null) { + result3 = parse_HEXDIG(); + + if (result3 !== null) { + result0 = [result0, result1, result2, result3]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_hex8() { + var result0, result1; + var pos0; + pos0 = pos; + result0 = parse_hex4(); + + if (result0 !== null) { + result1 = parse_hex4(); + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_hex12() { + var result0, result1, result2; + var pos0; + pos0 = pos; + result0 = parse_hex4(); + + if (result0 !== null) { + result1 = parse_hex4(); + + if (result1 !== null) { + result2 = parse_hex4(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_Refer_To() { + var result0, result1, result2, result3; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_SIP_URI_noparams(); + + if (result0 === null) { + result0 = parse_name_addr(); + } + + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_generic_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos2; + } + } else { + result2 = null; + pos = pos2; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + try { + data = new NameAddrHeader(data.uri, data.display_name, data.params); + } catch (e) { + data = -1; + } + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_Replaces() { + var result0, result1, result2, result3; + var pos0, pos1; + pos0 = pos; + result0 = parse_call_id(); + + if (result0 !== null) { + result1 = []; + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_replaces_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + result2 = parse_SEMI(); + + if (result2 !== null) { + result3 = parse_replaces_param(); + + if (result3 !== null) { + result2 = [result2, result3]; + } else { + result2 = null; + pos = pos1; + } + } else { + result2 = null; + pos = pos1; + } + } + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos0; + } + } else { + result0 = null; + pos = pos0; + } + + return result0; + } + + function parse_call_id() { + var result0, result1, result2; + var pos0, pos1, pos2; + pos0 = pos; + pos1 = pos; + result0 = parse_word(); + + if (result0 !== null) { + pos2 = pos; + + if (input.charCodeAt(pos) === 64) { + result1 = "@"; + pos++; + } else { + result1 = null; + + if (reportFailures === 0) { + matchFailed("\"@\""); + } + } + + if (result1 !== null) { + result2 = parse_word(); + + if (result2 !== null) { + result1 = [result1, result2]; + } else { + result1 = null; + pos = pos2; + } + } else { + result1 = null; + pos = pos2; + } + + result1 = result1 !== null ? result1 : ""; + + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset) { + data.call_id = input.substring(pos, offset); + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_replaces_param() { + var result0; + result0 = parse_to_tag(); + + if (result0 === null) { + result0 = parse_from_tag(); + + if (result0 === null) { + result0 = parse_early_flag(); + + if (result0 === null) { + result0 = parse_generic_param(); + } + } + } + + return result0; + } + + function parse_to_tag() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 6) === "to-tag") { + result0 = "to-tag"; + pos += 6; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"to-tag\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, to_tag) { + data.to_tag = to_tag; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_from_tag() { + var result0, result1, result2; + var pos0, pos1; + pos0 = pos; + pos1 = pos; + + if (input.substr(pos, 8) === "from-tag") { + result0 = "from-tag"; + pos += 8; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"from-tag\""); + } + } + + if (result0 !== null) { + result1 = parse_EQUAL(); + + if (result1 !== null) { + result2 = parse_token(); + + if (result2 !== null) { + result0 = [result0, result1, result2]; + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + } else { + result0 = null; + pos = pos1; + } + + if (result0 !== null) { + result0 = function (offset, from_tag) { + data.from_tag = from_tag; + }(pos0, result0[2]); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function parse_early_flag() { + var result0; + var pos0; + pos0 = pos; + + if (input.substr(pos, 10) === "early-only") { + result0 = "early-only"; + pos += 10; + } else { + result0 = null; + + if (reportFailures === 0) { + matchFailed("\"early-only\""); + } + } + + if (result0 !== null) { + result0 = function (offset) { + data.early_only = true; + }(pos0); + } + + if (result0 === null) { + pos = pos0; + } + + return result0; + } + + function cleanupExpected(expected) { + expected.sort(); + var lastExpected = null; + var cleanExpected = []; + + for (var i = 0; i < expected.length; i++) { + if (expected[i] !== lastExpected) { + cleanExpected.push(expected[i]); + lastExpected = expected[i]; + } + } + + return cleanExpected; + } + + function computeErrorPosition() { + /* + * The first idea was to use |String.split| to break the input up to the + * error position along newlines and derive the line and column from + * there. However IE's |split| implementation is so broken that it was + * enough to prevent it. + */ + var line = 1; + var column = 1; + var seenCR = false; + + for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) { + var ch = input.charAt(i); + + if (ch === "\n") { + if (!seenCR) { + line++; + } + + column = 1; + seenCR = false; + } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { + line++; + column = 1; + seenCR = true; + } else { + column++; + seenCR = false; + } + } + + return { + line: line, + column: column + }; + } + + var URI = require('./URI'); + + var NameAddrHeader = require('./NameAddrHeader'); + + var data = {}; + var result = parseFunctions[startRule](); + /* + * The parser is now in one of the following three states: + * + * 1. The parser successfully parsed the whole input. + * + * - |result !== null| + * - |pos === input.length| + * - |rightmostFailuresExpected| may or may not contain something + * + * 2. The parser successfully parsed only a part of the input. + * + * - |result !== null| + * - |pos < input.length| + * - |rightmostFailuresExpected| may or may not contain something + * + * 3. The parser did not successfully parse any part of the input. + * + * - |result === null| + * - |pos === 0| + * - |rightmostFailuresExpected| contains at least one failure + * + * All code following this comment (including called functions) must + * handle these states. + */ + + if (result === null || pos !== input.length) { + var offset = Math.max(pos, rightmostFailuresPos); + var found = offset < input.length ? input.charAt(offset) : null; + var errorPosition = computeErrorPosition(); + new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column); + return -1; + } + + return data; + }, + + /* Returns the parser source code. */ + toSource: function toSource() { + return this._source; + } + }; + /* Thrown when a parser encounters a syntax error. */ + + result.SyntaxError = function (expected, found, offset, line, column) { + function buildMessage(expected, found) { + var expectedHumanized, foundHumanized; + + switch (expected.length) { + case 0: + expectedHumanized = "end of input"; + break; + + case 1: + expectedHumanized = expected[0]; + break; + + default: + expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1]; + } + + foundHumanized = found ? quote(found) : "end of input"; + return "Expected " + expectedHumanized + " but " + foundHumanized + " found."; + } + + this.name = "SyntaxError"; + this.expected = expected; + this.found = found; + this.message = buildMessage(expected, found); + this.offset = offset; + this.line = line; + this.column = column; + }; + + result.SyntaxError.prototype = Error.prototype; + return result; +}(); +},{"./NameAddrHeader":10,"./URI":27}],8:[function(require,module,exports){ +"use strict"; + +var pkg = require('../package.json'); + +var C = require('./Constants'); + +var Exceptions = require('./Exceptions'); + +var Utils = require('./Utils'); + +var UA = require('./UA'); + +var URI = require('./URI'); + +var NameAddrHeader = require('./NameAddrHeader'); + +var Grammar = require('./Grammar'); + +var WebSocketInterface = require('./WebSocketInterface'); + +var debug = require('debug')('JsSIP'); + +debug('version %s', pkg.version); +/** + * Expose the JsSIP module. + */ + +module.exports = { + C: C, + Exceptions: Exceptions, + Utils: Utils, + UA: UA, + URI: URI, + NameAddrHeader: NameAddrHeader, + WebSocketInterface: WebSocketInterface, + Grammar: Grammar, + // Expose the debug module. + debug: require('debug'), + + get name() { + return pkg.title; + }, + + get version() { + return pkg.version; + } + +}; +},{"../package.json":40,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":26,"./URI":27,"./Utils":28,"./WebSocketInterface":29,"debug":32}],9:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var SIPMessage = require('./SIPMessage'); + +var Utils = require('./Utils'); + +var RequestSender = require('./RequestSender'); + +var Exceptions = require('./Exceptions'); + +var debug = require('debug')('JsSIP:Message'); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Message, _EventEmitter); + + var _super = _createSuper(Message); + + function Message(ua) { + var _this; + + _classCallCheck(this, Message); + + _this = _super.call(this); + _this._ua = ua; + _this._request = null; + _this._closed = false; + _this._direction = null; + _this._local_identity = null; + _this._remote_identity = null; // Whether an incoming message has been replied. + + _this._is_replied = false; // Custom message empty object for high level use. + + _this._data = {}; + return _this; + } + + _createClass(Message, [{ + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "send", + value: function send(target, body) { + var _this2 = this; + + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + var originalTarget = target; + + if (target === undefined || body === undefined) { + throw new TypeError('Not enough arguments'); + } // Check target validity. + + + target = this._ua.normalizeTarget(target); + + if (!target) { + throw new TypeError("Invalid target: ".concat(originalTarget)); + } // Get call options. + + + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var contentType = options.contentType || 'text/plain'; // Set event handlers. + + for (var event in eventHandlers) { + if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { + this.on(event, eventHandlers[event]); + } + } + + extraHeaders.push("Content-Type: ".concat(contentType)); + this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, null, extraHeaders); + + if (body) { + this._request.body = body; + } + + var request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout: function onRequestTimeout() { + _this2._onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this2._onTransportError(); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this2._receiveResponse(response); + } + }); + + this._newMessage('local', this._request); + + request_sender.send(); + } + }, { + key: "init_incoming", + value: function init_incoming(request) { + this._request = request; + + this._newMessage('remote', request); // Reply with a 200 OK if the user didn't reply. + + + if (!this._is_replied) { + this._is_replied = true; + request.reply(200); + } + + this._close(); + } + /** + * Accept the incoming Message + * Only valid for incoming Messages + */ + + }, { + key: "accept", + value: function accept() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var body = options.body; + + if (this._direction !== 'incoming') { + throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message'); + } + + if (this._is_replied) { + throw new Error('incoming Message already replied'); + } + + this._is_replied = true; + + this._request.reply(200, null, extraHeaders, body); + } + /** + * Reject the incoming Message + * Only valid for incoming Messages + */ + + }, { + key: "reject", + value: function reject() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var status_code = options.status_code || 480; + var reason_phrase = options.reason_phrase; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var body = options.body; + + if (this._direction !== 'incoming') { + throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message'); + } + + if (this._is_replied) { + throw new Error('incoming Message already replied'); + } + + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } + + this._is_replied = true; + + this._request.reply(status_code, reason_phrase, extraHeaders, body); + } + }, { + key: "_receiveResponse", + value: function _receiveResponse(response) { + if (this._closed) { + return; + } + + switch (true) { + case /^1[0-9]{2}$/.test(response.status_code): + // Ignore provisional responses. + break; + + case /^2[0-9]{2}$/.test(response.status_code): + this._succeeded('remote', response); + + break; + + default: + { + var cause = Utils.sipErrorCause(response.status_code); + + this._failed('remote', response, cause); + + break; + } + } + } + }, { + key: "_onRequestTimeout", + value: function _onRequestTimeout() { + if (this._closed) { + return; + } + + this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT); + } + }, { + key: "_onTransportError", + value: function _onTransportError() { + if (this._closed) { + return; + } + + this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); + } + }, { + key: "_close", + value: function _close() { + this._closed = true; + + this._ua.destroyMessage(this); + } + /** + * Internal Callbacks + */ + + }, { + key: "_newMessage", + value: function _newMessage(originator, request) { + if (originator === 'remote') { + this._direction = 'incoming'; + this._local_identity = request.to; + this._remote_identity = request.from; + } else if (originator === 'local') { + this._direction = 'outgoing'; + this._local_identity = request.from; + this._remote_identity = request.to; + } + + this._ua.newMessage(this, { + originator: originator, + message: this, + request: request + }); + } + }, { + key: "_failed", + value: function _failed(originator, response, cause) { + debug('MESSAGE failed'); + + this._close(); + + debug('emit "failed"'); + this.emit('failed', { + originator: originator, + response: response || null, + cause: cause + }); + } + }, { + key: "_succeeded", + value: function _succeeded(originator, response) { + debug('MESSAGE succeeded'); + + this._close(); + + debug('emit "succeeded"'); + this.emit('succeeded', { + originator: originator, + response: response + }); + } + }]); + + return Message; +}(EventEmitter); +},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],10:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var URI = require('./URI'); + +var Grammar = require('./Grammar'); + +module.exports = /*#__PURE__*/function () { + function NameAddrHeader(uri, display_name, parameters) { + _classCallCheck(this, NameAddrHeader); + + // Checks. + if (!uri || !(uri instanceof URI)) { + throw new TypeError('missing or invalid "uri" parameter'); + } // Initialize parameters. + + + this._uri = uri; + this._parameters = {}; + this.display_name = display_name; + + for (var param in parameters) { + if (Object.prototype.hasOwnProperty.call(parameters, param)) { + this.setParam(param, parameters[param]); + } + } + } + + _createClass(NameAddrHeader, [{ + key: "uri", + get: function get() { + return this._uri; + } + }, { + key: "display_name", + get: function get() { + return this._display_name; + }, + set: function set(value) { + this._display_name = value === 0 ? '0' : value; + } + }, { + key: "setParam", + value: function setParam(key, value) { + if (key) { + this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString(); + } + } + }, { + key: "getParam", + value: function getParam(key) { + if (key) { + return this._parameters[key.toLowerCase()]; + } + } + }, { + key: "hasParam", + value: function hasParam(key) { + if (key) { + return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false; + } + } + }, { + key: "deleteParam", + value: function deleteParam(parameter) { + parameter = parameter.toLowerCase(); + + if (this._parameters.hasOwnProperty(parameter)) { + var value = this._parameters[parameter]; + delete this._parameters[parameter]; + return value; + } + } + }, { + key: "clearParams", + value: function clearParams() { + this._parameters = {}; + } + }, { + key: "clone", + value: function clone() { + return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters))); + } + }, { + key: "_quote", + value: function _quote(str) { + return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + } + }, { + key: "toString", + value: function toString() { + var body = this._display_name ? "\"".concat(this._quote(this._display_name), "\" ") : ''; + body += "<".concat(this._uri.toString(), ">"); + + for (var parameter in this._parameters) { + if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) { + body += ";".concat(parameter); + + if (this._parameters[parameter] !== null) { + body += "=".concat(this._parameters[parameter]); + } + } + } + + return body; + } + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a NameAddrHeader instance or undefined if + * it is an invalid NameAddrHeader. + */ + function parse(name_addr_header) { + name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); + + if (name_addr_header !== -1) { + return name_addr_header; + } else { + return undefined; + } + } + }]); + + return NameAddrHeader; +}(); +},{"./Grammar":7,"./URI":27}],11:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:Notifier'); + +var debugerror = require('debug')('JsSIP:ERROR:Notifier'); + +debugerror.log = console.warn.bind(console); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Notifier, _EventEmitter); + + var _super = _createSuper(Notifier); + + function Notifier(ua, _ref) { + var _this; + + var subscribe = _ref.subscribe, + content_type = _ref.content_type, + headers = _ref.headers, + credential = _ref.credential, + pending = _ref.pending; + + _classCallCheck(this, Notifier); + + debug('new'); + _this = _super.call(this); + _this._ua = ua; + _this.expires_timestamp = null; + _this.expires_timer = null; + _this._state = pending ? 'pending' : 'active'; + _this.is_final_notify_sent = false; + _this.is_first_notify_response = true; + _this.id = null; + _this.event_name = subscribe.getHeader('event'); + + if (!content_type) { + throw new TypeError('content_type is undefined'); + } + + _this.content_type = content_type; + _this.expires = parseInt(subscribe.getHeader('expires')); + _this.credential = credential; + var user = subscribe.to.uri.user; + var domain = subscribe.to.uri.host; + _this.contact = ""); + _this.rcseq = subscribe.cseq; + _this.headers = headers ? headers : []; + _this.target = subscribe.from.uri.user; + subscribe.to_tag = Utils.newTag(); + _this.params = { + from: subscribe.to, + from_tag: subscribe.to_tag, + to: subscribe.from, + to_tag: subscribe.from_tag, + call_id: subscribe.call_id, + cseq: Math.floor(Math.random() * 10000 + 1) + }; + _this.id = "".concat(_this.params.call_id).concat(_this.params.from_tag).concat(_this.params.to_tag); + debug('add dialog id=', _this.id); + + _this._ua.newDialog(_assertThisInitialized(_this)); + + _this._setExpiresTimestamp(); + + _this._setExpiresTimer(); + + _this.is_terminated = false; + _this.terminated_reason = undefined; // Custom session empty object for high level use. + + _this.data = {}; + subscribe.reply(200, null, ["Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); + return _this; + } + /** + * Callbacks + */ + + + _createClass(Notifier, [{ + key: "onAuthenticated", + value: function onAuthenticated() { + this.params.cseq++; + } + }, { + key: "onRequestTimeout", + value: function onRequestTimeout() { + this._dialogTerminated('notify response timeout'); + } + }, { + key: "onTransportError", + value: function onTransportError() { + this._dialogTerminated('notify transport error'); + } + }, { + key: "onReceiveResponse", + value: function onReceiveResponse(response) { + if (response.status_code >= 200 && response.status_code < 300) { + if (this.is_first_notify_response) { + this.is_first_notify_response = false; + this.route_set = response.getHeaders('record-route').reverse(); + + if (this.route_set.length > 0) { + this.params.route_set = this.route_set; + } + } + } else if (response.status_code >= 300) { + this._dialogTerminated('receive notify non-OK response'); + } + } + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + if (request.method !== JsSIP_C.SUBSCRIBE) { + request.reply(405); + return; + } + + var h = request.getHeader('expires'); + + if (h === undefined || h === null) { + h = '900'; // Missed header Expires. RFC 6665 3.1.1. Set default expires value + + debug("Missed expires header. Set by default ".concat(h)); + } + + this.expires = parseInt(h); + request.reply(200, null, ["Expires: ".concat(this.expires), "Contact: ".concat(this.contact)]); + var body = request.body; + var content_type = request.getHeader('content-type'); + var is_unsubscribe = this.expires === 0; + debug('emit "subscribe"'); + this.emit('subscribe', is_unsubscribe, request, body, content_type); + + if (is_unsubscribe) { + this._dialogTerminated('receive un-subscribe'); + } else { + this._setExpiresTimestamp(); + + this._setExpiresTimer(); + } + } + /** + * User API + */ + + }, { + key: "setActiveState", + value: function setActiveState() { + debug('setActiveState()'); + + if (this._state === 'pending') { + this._state = 'active'; + } + } + }, { + key: "sendNotify", + value: function sendNotify() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + debug('sendNotify()'); + var subs_state = this._state; + + if (this._state !== 'terminated') { + subs_state += ";expires=".concat(this._getExpiresTimestamp()); + } else if (this.terminated_reason) { + subs_state += ";reason=".concat(this.terminated_reason); + } + + var headers = this.headers.slice(); + headers.push("Subscription-State: ".concat(subs_state)); + headers.push("Event: ".concat(this.event_name)); + + if (body) { + headers.push("Content-Type: ".concat(this.content_type)); + } + + this.params.cseq++; + + this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); + } + }, { + key: "sendFinalNotify", + value: function sendFinalNotify() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + debug('sendFinalNotify()'); + + if (this.is_final_notify_sent) { + return; + } + + this.is_final_notify_sent = true; + + this._dialogTerminated('send final notify'); + + this.terminated_reason = reason; + this.sendNotify(body); + } + }, { + key: "state", + get: function get() { + return this._state; + } + /** + * Private API. + */ + + }, { + key: "_dialogTerminated", + value: function _dialogTerminated(reason) { + var _this2 = this; + + if (this.is_terminated) { + return; + } + + this.is_terminated = true; + this._state = 'terminated'; + clearTimeout(this.expires_timer); // If delay needed ? + + setTimeout(function () { + debug('remove dialog id=', _this2.id); + + _this2._ua.destroyDialog(_this2); + }, 32000); + debug("emit \"terminated\" ".concat(reason, "\"")); + this.emit('terminated', reason); + } + }, { + key: "_setExpiresTimestamp", + value: function _setExpiresTimestamp() { + this.expires_timestamp = new Date().getTime() + this.expires * 1000; + } + }, { + key: "_getExpiresTimestamp", + value: function _getExpiresTimestamp() { + var delta = Math.floor((this.expires_timestamp - new Date().getTime()) / 1000); + return delta >= 0 ? delta : 0; + } + }, { + key: "_setExpiresTimer", + value: function _setExpiresTimer() { + var _this3 = this; + + clearTimeout(this.expires_timer); + setTimeout(function () { + if (_this3.is_final_notify_sent) { + return; + } + + _this3.terminated_reason = 'timeout'; + _this3.is_final_notify_sent = true; + + _this3.sendNotify(); + + _this3._dialogTerminated('subscription expired'); + }, this.expires * 1000); + } + }]); + + return Notifier; +}(EventEmitter); +},{"./Constants":2,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ +"use strict"; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var Grammar = require('./Grammar'); + +var SIPMessage = require('./SIPMessage'); + +var debugerror = require('debug')('JsSIP:ERROR:Parser'); + +debugerror.log = console.warn.bind(console); +/** + * Parse SIP Message + */ + +exports.parseMessage = function (data, ua) { + var message; + var bodyStart; + var headerEnd = data.indexOf('\r\n'); + + if (headerEnd === -1) { + debugerror('parseMessage() | no CRLF found, not a SIP message'); + return; + } // Parse first line. Check if it is a Request or a Reply. + + + var firstLine = data.substring(0, headerEnd); + var parsed = Grammar.parse(firstLine, 'Request_Response'); + + if (parsed === -1) { + debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); + return; + } else if (!parsed.status_code) { + message = new SIPMessage.IncomingRequest(ua); + message.method = parsed.method; + message.ruri = parsed.uri; + } else { + message = new SIPMessage.IncomingResponse(); + message.status_code = parsed.status_code; + message.reason_phrase = parsed.reason_phrase; + } + + message.data = data; + var headerStart = headerEnd + 2; + /* Loop over every line in data. Detect the end of each header and parse + * it or simply add to the headers collection. + */ + + while (true) { + headerEnd = getHeader(data, headerStart); // The SIP message has normally finished. + + if (headerEnd === -2) { + bodyStart = headerStart + 2; + break; + } // Data.indexOf returned -1 due to a malformed message. + else if (headerEnd === -1) { + debugerror('parseMessage() | malformed message'); + return; + } + + parsed = parseHeader(message, data, headerStart, headerEnd); + + if (parsed !== true) { + debugerror('parseMessage() |', parsed.error); + return; + } + + headerStart = headerEnd + 2; + } + /* RFC3261 18.3. + * If there are additional bytes in the transport packet + * beyond the end of the body, they MUST be discarded. + */ + + + if (message.hasHeader('content-length')) { + var contentLength = message.getHeader('content-length'); + message.body = data.substr(bodyStart, contentLength); + } else { + message.body = data.substring(bodyStart); + } + + return message; +}; +/** + * Extract and parse every header of a SIP message. + */ + + +function getHeader(data, headerStart) { + // 'start' position of the header. + var start = headerStart; // 'end' position of the header. + + var end = 0; // 'partial end' position of the header. + + var partialEnd = 0; // End of message. + + if (data.substring(start, start + 2).match(/(^\r\n)/)) { + return -2; + } + + while (end === 0) { + // Partial End of Header. + partialEnd = data.indexOf('\r\n', start); // 'indexOf' returns -1 if the value to be found never occurs. + + if (partialEnd === -1) { + return partialEnd; + } + + if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) { + // Not the end of the message. Continue from the next position. + start = partialEnd + 2; + } else { + end = partialEnd; + } + } + + return end; +} + +function parseHeader(message, data, headerStart, headerEnd) { + var parsed; + var hcolonIndex = data.indexOf(':', headerStart); + var headerName = data.substring(headerStart, hcolonIndex).trim(); + var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim(); // If header-field is well-known, parse it. + + switch (headerName.toLowerCase()) { + case 'via': + case 'v': + message.addHeader('via', headerValue); + + if (message.getHeaders('via').length === 1) { + parsed = message.parseHeader('Via'); + + if (parsed) { + message.via = parsed; + message.via_branch = parsed.branch; + } + } else { + parsed = 0; + } + + break; + + case 'from': + case 'f': + message.setHeader('from', headerValue); + parsed = message.parseHeader('from'); + + if (parsed) { + message.from = parsed; + message.from_tag = parsed.getParam('tag'); + } + + break; + + case 'to': + case 't': + message.setHeader('to', headerValue); + parsed = message.parseHeader('to'); + + if (parsed) { + message.to = parsed; + message.to_tag = parsed.getParam('tag'); + } + + break; + + case 'record-route': + parsed = Grammar.parse(headerValue, 'Record_Route'); + + if (parsed === -1) { + parsed = undefined; + } else { + var _iterator = _createForOfIteratorHelper(parsed), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var header = _step.value; + message.addHeader('record-route', headerValue.substring(header.possition, header.offset)); + message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed; + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + + break; + + case 'call-id': + case 'i': + message.setHeader('call-id', headerValue); + parsed = message.parseHeader('call-id'); + + if (parsed) { + message.call_id = headerValue; + } + + break; + + case 'contact': + case 'm': + parsed = Grammar.parse(headerValue, 'Contact'); + + if (parsed === -1) { + parsed = undefined; + } else { + var _iterator2 = _createForOfIteratorHelper(parsed), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var _header = _step2.value; + message.addHeader('contact', headerValue.substring(_header.possition, _header.offset)); + message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed; + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + + break; + + case 'content-length': + case 'l': + message.setHeader('content-length', headerValue); + parsed = message.parseHeader('content-length'); + break; + + case 'content-type': + case 'c': + message.setHeader('content-type', headerValue); + parsed = message.parseHeader('content-type'); + break; + + case 'cseq': + message.setHeader('cseq', headerValue); + parsed = message.parseHeader('cseq'); + + if (parsed) { + message.cseq = parsed.value; + } + + if (message instanceof SIPMessage.IncomingResponse) { + message.method = parsed.method; + } + + break; + + case 'max-forwards': + message.setHeader('max-forwards', headerValue); + parsed = message.parseHeader('max-forwards'); + break; + + case 'www-authenticate': + message.setHeader('www-authenticate', headerValue); + parsed = message.parseHeader('www-authenticate'); + break; + + case 'proxy-authenticate': + message.setHeader('proxy-authenticate', headerValue); + parsed = message.parseHeader('proxy-authenticate'); + break; + + case 'session-expires': + case 'x': + message.setHeader('session-expires', headerValue); + parsed = message.parseHeader('session-expires'); + + if (parsed) { + message.session_expires = parsed.expires; + message.session_expires_refresher = parsed.refresher; + } + + break; + + case 'refer-to': + case 'r': + message.setHeader('refer-to', headerValue); + parsed = message.parseHeader('refer-to'); + + if (parsed) { + message.refer_to = parsed; + } + + break; + + case 'replaces': + message.setHeader('replaces', headerValue); + parsed = message.parseHeader('replaces'); + + if (parsed) { + message.replaces = parsed; + } + + break; + + case 'event': + case 'o': + message.setHeader('event', headerValue); + parsed = message.parseHeader('event'); + + if (parsed) { + message.event = parsed; + } + + break; + + default: + // Do not parse this header. + message.addHeader(headerName, headerValue); + parsed = 0; + } + + if (parsed === undefined) { + return { + error: "error parsing header \"".concat(headerName, "\"") + }; + } else { + return true; + } +} +},{"./Grammar":7,"./SIPMessage":20,"debug":32}],13:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +/* globals RTCPeerConnection: false, RTCSessionDescription: false */ +var EventEmitter = require('events').EventEmitter; + +var sdp_transform = require('sdp-transform'); + +var JsSIP_C = require('./Constants'); + +var Exceptions = require('./Exceptions'); + +var Transactions = require('./Transactions'); + +var Utils = require('./Utils'); + +var Timers = require('./Timers'); + +var SIPMessage = require('./SIPMessage'); + +var Dialog = require('./Dialog'); + +var RequestSender = require('./RequestSender'); + +var RTCSession_DTMF = require('./RTCSession/DTMF'); + +var RTCSession_Info = require('./RTCSession/Info'); + +var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier'); + +var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); + +var URI = require('./URI'); + +var debug = require('debug')('JsSIP:RTCSession'); + +var debugerror = require('debug')('JsSIP:ERROR:RTCSession'); + +debugerror.log = console.warn.bind(console); +var C = { + // RTCSession states. + 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 +}; +/** + * Local variables. + */ + +var holdMediaTypes = ['audio', 'video']; + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(RTCSession, _EventEmitter); + + var _super = _createSuper(RTCSession); + + function RTCSession(ua) { + var _this; + + _classCallCheck(this, RTCSession); + + debug('new'); + _this = _super.call(this); + _this._id = null; + _this._ua = ua; + _this._status = C.STATUS_NULL; + _this._dialog = null; + _this._earlyDialogs = {}; + _this._contact = null; + _this._from_tag = null; + _this._to_tag = null; // The RTCPeerConnection instance (public attribute). + + _this._connection = null; // Prevent races on serial PeerConnction operations. + + _this._connectionPromiseQueue = Promise.resolve(); // Incoming/Outgoing request being currently processed. + + _this._request = null; // Cancel state for initial outgoing request. + + _this._is_canceled = false; + _this._cancel_reason = ''; // RTCSession confirmation flag. + + _this._is_confirmed = false; // Is late SDP being negotiated. + + _this._late_sdp = false; // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()). + + _this._rtcOfferConstraints = null; + _this._rtcAnswerConstraints = null; // Local MediaStream. + + _this._localMediaStream = null; + _this._localMediaStreamLocallyGenerated = false; // Flag to indicate PeerConnection ready for new actions. + + _this._rtcReady = true; // SIP Timers. + + _this._timers = { + ackTimer: null, + expiresTimer: null, + invite2xxTimer: null, + userNoAnswerTimer: null + }; // Session info. + + _this._direction = null; + _this._local_identity = null; + _this._remote_identity = null; + _this._start_time = null; + _this._end_time = null; + _this._tones = null; // Mute/Hold state. + + _this._audioMuted = false; + _this._videoMuted = false; + _this._localHold = false; + _this._remoteHold = false; // Session Timers (RFC 4028). + + _this._sessionTimers = { + enabled: _this._ua.configuration.session_timers, + refreshMethod: _this._ua.configuration.session_timers_refresh_method, + defaultExpires: JsSIP_C.SESSION_EXPIRES, + currentExpires: null, + running: false, + refresher: false, + timer: null // A setTimeout. + + }; // Map of ReferSubscriber instances indexed by the REFER's CSeq number. + + _this._referSubscribers = {}; // Custom session empty object for high level use. + + _this._data = {}; + return _this; + } + /** + * User API + */ + // Expose RTCSession constants as a property of the RTCSession instance. + + + _createClass(RTCSession, [{ + key: "C", + get: function get() { + return C; + } // Expose session failed/ended causes as a property of the RTCSession instance. + + }, { + key: "causes", + get: function get() { + return JsSIP_C.causes; + } + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "connection", + get: function get() { + return this._connection; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "start_time", + get: function get() { + return this._start_time; + } + }, { + key: "end_time", + get: function get() { + return this._end_time; + } + }, { + key: "data", + get: function get() { + return this._data; + }, + set: function set(_data) { + this._data = _data; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "isInProgress", + value: function isInProgress() { + switch (this._status) { + case C.STATUS_NULL: + case C.STATUS_INVITE_SENT: + case C.STATUS_1XX_RECEIVED: + case C.STATUS_INVITE_RECEIVED: + case C.STATUS_WAITING_FOR_ANSWER: + return true; + + default: + return false; + } + } + }, { + key: "isEstablished", + value: function isEstablished() { + switch (this._status) { + case C.STATUS_ANSWERED: + case C.STATUS_WAITING_FOR_ACK: + case C.STATUS_CONFIRMED: + return true; + + default: + return false; + } + } + }, { + key: "isEnded", + value: function isEnded() { + switch (this._status) { + case C.STATUS_CANCELED: + case C.STATUS_TERMINATED: + return true; + + default: + return false; + } + } + }, { + key: "isMuted", + value: function isMuted() { + return { + audio: this._audioMuted, + video: this._videoMuted + }; + } + }, { + key: "isOnHold", + value: function isOnHold() { + return { + local: this._localHold, + remote: this._remoteHold + }; + } + }, { + key: "connect", + value: function connect(target) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var initCallback = arguments.length > 2 ? arguments[2] : undefined; + debug('connect()'); + var originalTarget = target; + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var mediaConstraints = Utils.cloneObject(options.mediaConstraints, { + audio: true, + video: true + }); + var mediaStream = options.mediaStream || null; + var pcConfig = Utils.cloneObject(options.pcConfig, { + iceServers: [] + }); + var rtcConstraints = options.rtcConstraints || null; + var rtcOfferConstraints = options.rtcOfferConstraints || null; + this._rtcOfferConstraints = rtcOfferConstraints; + this._rtcAnswerConstraints = options.rtcAnswerConstraints || null; + this._data = options.data || this._data; // Check target. + + if (target === undefined) { + throw new TypeError('Not enough arguments'); + } // Check Session Status. + + + if (this._status !== C.STATUS_NULL) { + throw new Exceptions.InvalidStateError(this._status); + } // Check WebRTC support. + + + if (!window.RTCPeerConnection) { + throw new Exceptions.NotSupportedError('WebRTC not supported'); + } // Check target validity. + + + target = this._ua.normalizeTarget(target); + + if (!target) { + throw new TypeError("Invalid target: ".concat(originalTarget)); + } // Session Timers. + + + if (this._sessionTimers.enabled) { + if (Utils.isDecimal(options.sessionTimersExpires)) { + if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) { + this._sessionTimers.defaultExpires = options.sessionTimersExpires; + } else { + this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES; + } + } + } // Set event handlers. + + + for (var event in eventHandlers) { + if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { + this.on(event, eventHandlers[event]); + } + } // Session parameter initialization. + + + this._from_tag = Utils.newTag(); // Set anonymous property. + + var anonymous = options.anonymous || false; + var requestParams = { + from_tag: this._from_tag + }; + this._contact = this._ua.contact.toString({ + anonymous: anonymous, + outbound: true + }); + + if (anonymous) { + requestParams.from_display_name = 'Anonymous'; + requestParams.from_uri = new URI('sip', 'anonymous', 'anonymous.invalid'); + extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())); + extraHeaders.push('Privacy: id'); + } else if (options.fromUserName) { + requestParams.from_uri = new URI('sip', options.fromUserName, this._ua.configuration.uri.host); + extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())); + } + + if (options.fromDisplayName) { + requestParams.from_display_name = options.fromDisplayName; + } + + extraHeaders.push("Contact: ".concat(this._contact)); + extraHeaders.push('Content-Type: application/sdp'); + + if (this._sessionTimers.enabled) { + extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher ? ';refresher=uac' : '')); + } + + this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders); + this._id = this._request.call_id + this._from_tag; // Create a new RTCPeerConnection instance. + + this._createRTCConnection(pcConfig, rtcConstraints); // Set internal properties. + + + this._direction = 'outgoing'; + this._local_identity = this._request.from; + this._remote_identity = this._request.to; // User explicitly provided a newRTCSession callback for this session. + + if (initCallback) { + initCallback(this); + } + + this._newRTCSession('local', this._request); + + this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream); + } + }, { + key: "init_incoming", + value: function init_incoming(request, initCallback) { + var _this2 = this; + + debug('init_incoming()'); + var expires; + var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type. + + if (request.body && contentType !== 'application/sdp') { + request.reply(415); + return; + } // Session parameter initialization. + + + this._status = C.STATUS_INVITE_RECEIVED; + this._from_tag = request.from_tag; + this._id = request.call_id + this._from_tag; + this._request = request; + this._contact = this._ua.contact.toString(); // Get the Expires header value if exists. + + if (request.hasHeader('expires')) { + expires = request.getHeader('expires') * 1000; + } + /* Set the to_tag before + * replying a response code that will create a dialog. + */ + + + request.to_tag = Utils.newTag(); // An error on dialog creation will fire 'failed' event. + + if (!this._createDialog(request, 'UAS', true)) { + request.reply(500, 'Missing Contact header field'); + return; + } + + if (request.body) { + this._late_sdp = false; + } else { + this._late_sdp = true; + } + + this._status = C.STATUS_WAITING_FOR_ANSWER; // Set userNoAnswerTimer. + + this._timers.userNoAnswerTimer = setTimeout(function () { + request.reply(408); + + _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER); + }, this._ua.configuration.no_answer_timeout); + /* Set expiresTimer + * RFC3261 13.3.1 + */ + + if (expires) { + this._timers.expiresTimer = setTimeout(function () { + if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) { + request.reply(487); + + _this2._failed('system', null, JsSIP_C.causes.EXPIRES); + } + }, expires); + } // Set internal properties. + + + this._direction = 'incoming'; + this._local_identity = request.to; + this._remote_identity = request.from; // A init callback was specifically defined. + + if (initCallback) { + initCallback(this); + } // Fire 'newRTCSession' event. + + + this._newRTCSession('remote', request); // The user may have rejected the call in the 'newRTCSession' event. + + + if (this._status === C.STATUS_TERMINATED) { + return; + } // Reply 180. + + + request.reply(180, null, ["Contact: ".concat(this._contact)]); // Fire 'progress' event. + // TODO: Document that 'response' field in 'progress' event is null for incoming calls. + + this._progress('local', null); + } + /** + * Answer the call. + */ + + }, { + key: "answer", + value: function answer() { + var _this3 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + debug('answer()'); + var request = this._request; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var mediaConstraints = Utils.cloneObject(options.mediaConstraints); + var mediaStream = options.mediaStream || null; + var pcConfig = Utils.cloneObject(options.pcConfig, { + iceServers: [] + }); + var rtcConstraints = options.rtcConstraints || null; + var rtcAnswerConstraints = options.rtcAnswerConstraints || null; + var rtcOfferConstraints = Utils.cloneObject(options.rtcOfferConstraints); + var tracks; + var peerHasAudioLine = false; + var peerHasVideoLine = false; + var peerOffersFullAudio = false; + var peerOffersFullVideo = false; + this._rtcAnswerConstraints = rtcAnswerConstraints; + this._rtcOfferConstraints = options.rtcOfferConstraints || null; + this._data = options.data || this._data; // Check Session Direction and Status. + + if (this._direction !== 'incoming') { + throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession'); + } // Check Session status. + + + if (this._status !== C.STATUS_WAITING_FOR_ANSWER) { + throw new Exceptions.InvalidStateError(this._status); + } // Session Timers. + + + if (this._sessionTimers.enabled) { + if (Utils.isDecimal(options.sessionTimersExpires)) { + if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) { + this._sessionTimers.defaultExpires = options.sessionTimersExpires; + } else { + this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES; + } + } + } + + this._status = C.STATUS_ANSWERED; // An error on dialog creation will fire 'failed' event. + + if (!this._createDialog(request, 'UAS')) { + request.reply(500, 'Error creating dialog'); + return; + } + + clearTimeout(this._timers.userNoAnswerTimer); + extraHeaders.unshift("Contact: ".concat(this._contact)); // Determine incoming media from incoming SDP offer (if any). + + var sdp = request.parseSDP(); // Make sure sdp.media is an array, not the case if there is only one media. + + if (!Array.isArray(sdp.media)) { + sdp.media = [sdp.media]; + } // Go through all medias in SDP to find offered capabilities to answer with. + + + var _iterator = _createForOfIteratorHelper(sdp.media), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var m = _step.value; + + if (m.type === 'audio') { + peerHasAudioLine = true; + + if (!m.direction || m.direction === 'sendrecv') { + peerOffersFullAudio = true; + } + } + + if (m.type === 'video') { + peerHasVideoLine = true; + + if (!m.direction || m.direction === 'sendrecv') { + peerOffersFullVideo = true; + } + } + } // Remove audio from mediaStream if suggested by mediaConstraints. + + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + if (mediaStream && mediaConstraints.audio === false) { + tracks = mediaStream.getAudioTracks(); + + var _iterator2 = _createForOfIteratorHelper(tracks), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var track = _step2.value; + mediaStream.removeTrack(track); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } // Remove video from mediaStream if suggested by mediaConstraints. + + + if (mediaStream && mediaConstraints.video === false) { + tracks = mediaStream.getVideoTracks(); + + var _iterator3 = _createForOfIteratorHelper(tracks), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _track = _step3.value; + mediaStream.removeTrack(_track); + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } // Set audio constraints based on incoming stream if not supplied. + + + if (!mediaStream && mediaConstraints.audio === undefined) { + mediaConstraints.audio = peerOffersFullAudio; + } // Set video constraints based on incoming stream if not supplied. + + + if (!mediaStream && mediaConstraints.video === undefined) { + mediaConstraints.video = peerOffersFullVideo; + } // Don't ask for audio if the incoming offer has no audio section. + + + if (!mediaStream && !peerHasAudioLine && !rtcOfferConstraints.offerToReceiveAudio) { + mediaConstraints.audio = false; + } // Don't ask for video if the incoming offer has no video section. + + + if (!mediaStream && !peerHasVideoLine && !rtcOfferConstraints.offerToReceiveVideo) { + mediaConstraints.video = false; + } // Create a new RTCPeerConnection instance. + // TODO: This may throw an error, should react. + + + this._createRTCConnection(pcConfig, rtcConstraints); + + Promise.resolve() // Handle local MediaStream. + .then(function () { + // A local MediaStream is given, use it. + if (mediaStream) { + return mediaStream; + } // Audio and/or video requested, prompt getUserMedia. + else if (mediaConstraints.audio || mediaConstraints.video) { + _this3._localMediaStreamLocallyGenerated = true; + return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) { + if (_this3._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + request.reply(480); + + _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); + + debugerror('emit "getusermediafailed" [error:%o]', error); + + _this3.emit('getusermediafailed', error); + + throw new Error('getUserMedia() failed'); + }); + } + }) // Attach MediaStream to RTCPeerconnection. + .then(function (stream) { + if (_this3._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this3._localMediaStream = stream; + + if (stream) { + stream.getTracks().forEach(function (track) { + _this3._connection.addTrack(track, stream); + }); + } + }) // Set remote description. + .then(function () { + if (_this3._late_sdp) { + return; + } + + var e = { + originator: 'remote', + type: 'offer', + sdp: request.body + }; + debug('emit "sdp"'); + + _this3.emit('sdp', e); + + var offer = new RTCSessionDescription({ + type: 'offer', + sdp: e.sdp + }); + _this3._connectionPromiseQueue = _this3._connectionPromiseQueue.then(function () { + return _this3._connection.setRemoteDescription(offer); + })["catch"](function (error) { + request.reply(488); + + _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); + + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this3.emit('peerconnection:setremotedescriptionfailed', error); + + throw new Error('peerconnection.setRemoteDescription() failed'); + }); + return _this3._connectionPromiseQueue; + }) // Create local description. + .then(function () { + if (_this3._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } // TODO: Is this event already useful? + + + _this3._connecting(request); + + if (!_this3._late_sdp) { + return _this3._createLocalDescription('answer', rtcAnswerConstraints)["catch"](function () { + request.reply(500); + throw new Error('_createLocalDescription() failed'); + }); + } else { + return _this3._createLocalDescription('offer', _this3._rtcOfferConstraints)["catch"](function () { + request.reply(500); + throw new Error('_createLocalDescription() failed'); + }); + } + }) // Send reply. + .then(function (desc) { + if (_this3._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this3._handleSessionTimersInIncomingRequest(request, extraHeaders); + + request.reply(200, null, extraHeaders, desc, function () { + _this3._status = C.STATUS_WAITING_FOR_ACK; + + _this3._setInvite2xxTimer(request, desc); + + _this3._setACKTimer(); + + _this3._accepted('local'); + }, function () { + _this3._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); + }); + })["catch"](function (error) { + if (_this3._status === C.STATUS_TERMINATED) { + return; + } + + debugerror(error); + }); + } + /** + * Terminate the call. + */ + + }, { + key: "terminate", + value: function terminate() { + var _this4 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + debug('terminate()'); + var cause = options.cause || JsSIP_C.causes.BYE; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var body = options.body; + var cancel_reason; + var status_code = options.status_code; + var reason_phrase = options.reason_phrase; // Check Session Status. + + if (this._status === C.STATUS_TERMINATED) { + throw new Exceptions.InvalidStateError(this._status); + } + + switch (this._status) { + // - UAC - + case C.STATUS_NULL: + case C.STATUS_INVITE_SENT: + case C.STATUS_1XX_RECEIVED: + debug('canceling session'); + + if (status_code && (status_code < 200 || status_code >= 700)) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } else if (status_code) { + reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; + cancel_reason = "SIP ;cause=".concat(status_code, " ;text=\"").concat(reason_phrase, "\""); + } // Check Session Status. + + + if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) { + this._is_canceled = true; + this._cancel_reason = cancel_reason; + } else if (this._status === C.STATUS_1XX_RECEIVED) { + this._request.cancel(cancel_reason); + } + + this._status = C.STATUS_CANCELED; + + this._failed('local', null, JsSIP_C.causes.CANCELED); + + break; + // - UAS - + + case C.STATUS_WAITING_FOR_ANSWER: + case C.STATUS_ANSWERED: + debug('rejecting session'); + status_code = status_code || 480; + + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } + + this._request.reply(status_code, reason_phrase, extraHeaders, body); + + this._failed('local', null, JsSIP_C.causes.REJECTED); + + break; + + case C.STATUS_WAITING_FOR_ACK: + case C.STATUS_CONFIRMED: + debug('terminating session'); + reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; + + if (status_code && (status_code < 200 || status_code >= 700)) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } else if (status_code) { + extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\"")); + } + /* RFC 3261 section 15 (Terminating a session): + * + * "...the callee's UA MUST NOT send a BYE on a confirmed dialog + * until it has received an ACK for its 2xx response or until the server + * transaction times out." + */ + + + if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) { + // Save the dialog for later restoration. + var dialog = this._dialog; // Send the BYE as soon as the ACK is received... + + this.receiveRequest = function (_ref) { + var method = _ref.method; + + if (method === JsSIP_C.ACK) { + _this4.sendRequest(JsSIP_C.BYE, { + extraHeaders: extraHeaders, + body: body + }); + + dialog.terminate(); + } + }; // .., or when the INVITE transaction times out + + + this._request.server_transaction.on('stateChanged', function () { + if (_this4._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) { + _this4.sendRequest(JsSIP_C.BYE, { + extraHeaders: extraHeaders, + body: body + }); + + dialog.terminate(); + } + }); + + this._ended('local', null, cause); // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-). + + + this._dialog = dialog; // Restore the dialog into 'ua' so the ACK can reach 'this' session. + + this._ua.newDialog(dialog); + } else { + this.sendRequest(JsSIP_C.BYE, { + extraHeaders: extraHeaders, + body: body + }); + + this._ended('local', null, cause); + } + + } + } + }, { + key: "sendDTMF", + value: function sendDTMF(tones) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + debug('sendDTMF() | tones: %s', tones); + var position = 0; + var duration = options.duration || null; + var interToneGap = options.interToneGap || null; + var transportType = options.transportType || JsSIP_C.DTMF_TRANSPORT.INFO; + + if (tones === undefined) { + throw new TypeError('Not enough arguments'); + } // Check Session Status. + + + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { + throw new Exceptions.InvalidStateError(this._status); + } // Check Transport type. + + + if (transportType !== JsSIP_C.DTMF_TRANSPORT.INFO && transportType !== JsSIP_C.DTMF_TRANSPORT.RFC2833) { + throw new TypeError("invalid transportType: ".concat(transportType)); + } // Convert to string. + + + if (typeof tones === 'number') { + tones = tones.toString(); + } // Check tones. + + + if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) { + throw new TypeError("Invalid tones: ".concat(tones)); + } // Check duration. + + + if (duration && !Utils.isDecimal(duration)) { + throw new TypeError("Invalid tone duration: ".concat(duration)); + } else if (!duration) { + duration = RTCSession_DTMF.C.DEFAULT_DURATION; + } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { + debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); + duration = RTCSession_DTMF.C.MIN_DURATION; + } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { + debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); + duration = RTCSession_DTMF.C.MAX_DURATION; + } else { + duration = Math.abs(duration); + } + + options.duration = duration; // Check interToneGap. + + if (interToneGap && !Utils.isDecimal(interToneGap)) { + throw new TypeError("Invalid interToneGap: ".concat(interToneGap)); + } else if (!interToneGap) { + interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP; + } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { + debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); + interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; + } else { + interToneGap = Math.abs(interToneGap); + } // RFC2833. Let RTCDTMFSender enqueue the DTMFs. + + + if (transportType === JsSIP_C.DTMF_TRANSPORT.RFC2833) { + // Send DTMF in current audio RTP stream. + var sender = this._getDTMFRTPSender(); + + if (sender) { + // Add remaining buffered tones. + tones = sender.toneBuffer + tones; // Insert tones. + + sender.insertDTMF(tones, duration, interToneGap); + } + + return; + } + + if (this._tones) { + // Tones are already queued, just add to the queue. + this._tones += tones; + return; + } + + this._tones = tones; // Send the first tone. + + _sendDTMF.call(this); + + function _sendDTMF() { + var _this5 = this; + + var timeout; + + if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) { + // Stop sending DTMF. + this._tones = null; + return; + } + + var tone = this._tones[position]; + position += 1; + + if (tone === ',') { + timeout = 2000; + } else { + // Send DTMF via SIP INFO messages. + var dtmf = new RTCSession_DTMF(this); + options.eventHandlers = { + onFailed: function onFailed() { + _this5._tones = null; + } + }; + dtmf.send(tone, options); + timeout = duration + interToneGap; + } // Set timeout for the next tone. + + + setTimeout(_sendDTMF.bind(this), timeout); + } + } + }, { + key: "sendInfo", + value: function sendInfo(contentType, body) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + debug('sendInfo()'); // Check Session Status. + + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { + throw new Exceptions.InvalidStateError(this._status); + } + + var info = new RTCSession_Info(this); + info.send(contentType, body, options); + } + /** + * Mute + */ + + }, { + key: "mute", + value: function mute() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { + audio: true, + video: false + }; + debug('mute()'); + var audioMuted = false, + videoMuted = false; + + if (this._audioMuted === false && options.audio) { + audioMuted = true; + this._audioMuted = true; + + this._toggleMuteAudio(true); + } + + if (this._videoMuted === false && options.video) { + videoMuted = true; + this._videoMuted = true; + + this._toggleMuteVideo(true); + } + + if (audioMuted === true || videoMuted === true) { + this._onmute({ + audio: audioMuted, + video: videoMuted + }); + } + } + /** + * Unmute + */ + + }, { + key: "unmute", + value: function unmute() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { + audio: true, + video: true + }; + debug('unmute()'); + var audioUnMuted = false, + videoUnMuted = false; + + if (this._audioMuted === true && options.audio) { + audioUnMuted = true; + this._audioMuted = false; + + if (this._localHold === false) { + this._toggleMuteAudio(false); + } + } + + if (this._videoMuted === true && options.video) { + videoUnMuted = true; + this._videoMuted = false; + + if (this._localHold === false) { + this._toggleMuteVideo(false); + } + } + + if (audioUnMuted === true || videoUnMuted === true) { + this._onunmute({ + audio: audioUnMuted, + video: videoUnMuted + }); + } + } + /** + * Hold + */ + + }, { + key: "hold", + value: function hold() { + var _this6 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var done = arguments.length > 1 ? arguments[1] : undefined; + debug('hold()'); + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (this._localHold === true) { + return false; + } + + if (!this._isReadyToReOffer()) { + return false; + } + + this._localHold = true; + + this._onhold('local'); + + var eventHandlers = { + succeeded: function succeeded() { + if (done) { + done(); + } + }, + failed: function failed() { + _this6.terminate({ + cause: JsSIP_C.causes.WEBRTC_ERROR, + status_code: 500, + reason_phrase: 'Hold Failed' + }); + } + }; + + if (options.useUpdate) { + this._sendUpdate({ + sdpOffer: true, + eventHandlers: eventHandlers, + extraHeaders: options.extraHeaders + }); + } else { + this._sendReinvite({ + eventHandlers: eventHandlers, + extraHeaders: options.extraHeaders + }); + } + + return true; + } + }, { + key: "unhold", + value: function unhold() { + var _this7 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var done = arguments.length > 1 ? arguments[1] : undefined; + debug('unhold()'); + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (this._localHold === false) { + return false; + } + + if (!this._isReadyToReOffer()) { + return false; + } + + this._localHold = false; + + this._onunhold('local'); + + var eventHandlers = { + succeeded: function succeeded() { + if (done) { + done(); + } + }, + failed: function failed() { + _this7.terminate({ + cause: JsSIP_C.causes.WEBRTC_ERROR, + status_code: 500, + reason_phrase: 'Unhold Failed' + }); + } + }; + + if (options.useUpdate) { + this._sendUpdate({ + sdpOffer: true, + eventHandlers: eventHandlers, + extraHeaders: options.extraHeaders + }); + } else { + this._sendReinvite({ + eventHandlers: eventHandlers, + extraHeaders: options.extraHeaders + }); + } + + return true; + } + }, { + key: "renegotiate", + value: function renegotiate() { + var _this8 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var done = arguments.length > 1 ? arguments[1] : undefined; + debug('renegotiate()'); + var rtcOfferConstraints = options.rtcOfferConstraints || null; + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (!this._isReadyToReOffer()) { + return false; + } + + var eventHandlers = { + succeeded: function succeeded() { + if (done) { + done(); + } + }, + failed: function failed() { + _this8.terminate({ + cause: JsSIP_C.causes.WEBRTC_ERROR, + status_code: 500, + reason_phrase: 'Media Renegotiation Failed' + }); + } + }; + + this._setLocalMediaStatus(); + + if (options.useUpdate) { + this._sendUpdate({ + sdpOffer: true, + eventHandlers: eventHandlers, + rtcOfferConstraints: rtcOfferConstraints, + extraHeaders: options.extraHeaders + }); + } else { + this._sendReinvite({ + eventHandlers: eventHandlers, + rtcOfferConstraints: rtcOfferConstraints, + extraHeaders: options.extraHeaders + }); + } + + return true; + } + /** + * Refer + */ + + }, { + key: "refer", + value: function refer(target, options) { + var _this9 = this; + + debug('refer()'); + var originalTarget = target; + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } // Check target validity. + + + target = this._ua.normalizeTarget(target); + + if (!target) { + throw new TypeError("Invalid target: ".concat(originalTarget)); + } + + var referSubscriber = new RTCSession_ReferSubscriber(this); + referSubscriber.sendRefer(target, options); // Store in the map. + + var id = referSubscriber.id; + this._referSubscribers[id] = referSubscriber; // Listen for ending events so we can remove it from the map. + + referSubscriber.on('requestFailed', function () { + delete _this9._referSubscribers[id]; + }); + referSubscriber.on('accepted', function () { + delete _this9._referSubscribers[id]; + }); + referSubscriber.on('failed', function () { + delete _this9._referSubscribers[id]; + }); + return referSubscriber; + } + /** + * Send a generic in-dialog Request + */ + + }, { + key: "sendRequest", + value: function sendRequest(method, options) { + debug('sendRequest()'); + return this._dialog.sendRequest(method, options); + } + /** + * In dialog Request Reception + */ + + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + var _this10 = this; + + debug('receiveRequest()'); + + if (request.method === JsSIP_C.CANCEL) { + /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL + * was in progress and that the UAC MAY continue with the session established by + * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the + * established session. So the CANCEL is processed only if the session is not yet + * established. + */ + + /* + * Terminate the whole session in case the user didn't accept (or yet send the answer) + * nor reject the request opening the session. + */ + if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) { + this._status = C.STATUS_CANCELED; + + this._request.reply(487); + + this._failed('remote', request, JsSIP_C.causes.CANCELED); + } + } else { + // Requests arriving here are in-dialog requests. + switch (request.method) { + case JsSIP_C.ACK: + if (this._status !== C.STATUS_WAITING_FOR_ACK) { + return; + } // Update signaling status. + + + this._status = C.STATUS_CONFIRMED; + clearTimeout(this._timers.ackTimer); + clearTimeout(this._timers.invite2xxTimer); + + if (this._late_sdp) { + if (!request.body) { + this.terminate({ + cause: JsSIP_C.causes.MISSING_SDP, + status_code: 400 + }); + break; + } + + var e = { + originator: 'remote', + type: 'answer', + sdp: request.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var answer = new RTCSessionDescription({ + type: 'answer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this10._connection.setRemoteDescription(answer); + }).then(function () { + if (!_this10._is_confirmed) { + _this10._confirmed('remote', request); + } + })["catch"](function (error) { + _this10.terminate({ + cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION, + status_code: 488 + }); + + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this10.emit('peerconnection:setremotedescriptionfailed', error); + }); + } else if (!this._is_confirmed) { + this._confirmed('remote', request); + } + + break; + + case JsSIP_C.BYE: + if (this._status === C.STATUS_CONFIRMED || this._status === C.STATUS_WAITING_FOR_ACK) { + request.reply(200); + + this._ended('remote', request, JsSIP_C.causes.BYE); + } else if (this._status === C.STATUS_INVITE_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER) { + request.reply(200); + + this._request.reply(487, 'BYE Received'); + + this._ended('remote', request, JsSIP_C.causes.BYE); + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.INVITE: + if (this._status === C.STATUS_CONFIRMED) { + if (request.hasHeader('replaces')) { + this._receiveReplaces(request); + } else { + this._receiveReinvite(request); + } + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.INFO: + if (this._status === C.STATUS_1XX_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED || this._status === C.STATUS_WAITING_FOR_ACK || this._status === C.STATUS_CONFIRMED) { + var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; + + if (contentType && contentType.match(/^application\/dtmf-relay/i)) { + new RTCSession_DTMF(this).init_incoming(request); + } else if (contentType !== undefined) { + new RTCSession_Info(this).init_incoming(request); + } else { + request.reply(415); + } + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.UPDATE: + if (this._status === C.STATUS_CONFIRMED) { + this._receiveUpdate(request); + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.REFER: + if (this._status === C.STATUS_CONFIRMED) { + this._receiveRefer(request); + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + case JsSIP_C.NOTIFY: + if (this._status === C.STATUS_CONFIRMED) { + this._receiveNotify(request); + } else { + request.reply(403, 'Wrong Status'); + } + + break; + + default: + request.reply(501); + } + } + } + /** + * Session Callbacks + */ + + }, { + key: "onTransportError", + value: function onTransportError() { + debugerror('onTransportError()'); + + if (this._status !== C.STATUS_TERMINATED) { + this.terminate({ + status_code: 500, + reason_phrase: JsSIP_C.causes.CONNECTION_ERROR, + cause: JsSIP_C.causes.CONNECTION_ERROR + }); + } + } + }, { + key: "onRequestTimeout", + value: function onRequestTimeout() { + debugerror('onRequestTimeout()'); + + if (this._status !== C.STATUS_TERMINATED) { + this.terminate({ + status_code: 408, + reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT, + cause: JsSIP_C.causes.REQUEST_TIMEOUT + }); + } + } + }, { + key: "onDialogError", + value: function onDialogError() { + debugerror('onDialogError()'); + + if (this._status !== C.STATUS_TERMINATED) { + this.terminate({ + status_code: 500, + reason_phrase: JsSIP_C.causes.DIALOG_ERROR, + cause: JsSIP_C.causes.DIALOG_ERROR + }); + } + } // Called from DTMF handler. + + }, { + key: "newDTMF", + value: function newDTMF(data) { + debug('newDTMF()'); + this.emit('newDTMF', data); + } // Called from Info handler. + + }, { + key: "newInfo", + value: function newInfo(data) { + debug('newInfo()'); + this.emit('newInfo', data); + } + /** + * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP. + */ + + }, { + key: "_isReadyToReOffer", + value: function _isReadyToReOffer() { + if (!this._rtcReady) { + debug('_isReadyToReOffer() | internal WebRTC status not ready'); + return false; + } // No established yet. + + + if (!this._dialog) { + debug('_isReadyToReOffer() | session not established yet'); + return false; + } // Another INVITE transaction is in progress. + + + if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { + debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); + return false; + } + + return true; + } + }, { + key: "_close", + value: function _close() { + debug('close()'); // Close local MediaStream if it was not given by the user. + + if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { + debug('close() | closing local MediaStream'); + Utils.closeMediaStream(this._localMediaStream); + } + + if (this._status === C.STATUS_TERMINATED) { + return; + } + + this._status = C.STATUS_TERMINATED; // Terminate RTC. + + if (this._connection) { + try { + this._connection.close(); + } catch (error) { + debugerror('close() | error closing the RTCPeerConnection: %o', error); + } + } // Terminate signaling. + // Clear SIP timers. + + + for (var timer in this._timers) { + if (Object.prototype.hasOwnProperty.call(this._timers, timer)) { + clearTimeout(this._timers[timer]); + } + } // Clear Session Timers. + + + clearTimeout(this._sessionTimers.timer); // Terminate confirmed dialog. + + if (this._dialog) { + this._dialog.terminate(); + + delete this._dialog; + } // Terminate early dialogs. + + + for (var dialog in this._earlyDialogs) { + if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) { + this._earlyDialogs[dialog].terminate(); + + delete this._earlyDialogs[dialog]; + } + } // Terminate REFER subscribers. + + + for (var subscriber in this._referSubscribers) { + if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) { + delete this._referSubscribers[subscriber]; + } + } + + this._ua.destroyRTCSession(this); + } + /** + * Private API. + */ + + /** + * RFC3261 13.3.1.4 + * Response retransmissions cannot be accomplished by transaction layer + * since it is destroyed when receiving the first 2xx answer + */ + + }, { + key: "_setInvite2xxTimer", + value: function _setInvite2xxTimer(request, body) { + var timeout = Timers.T1; + + function invite2xxRetransmission() { + if (this._status !== C.STATUS_WAITING_FOR_ACK) { + return; + } + + request.reply(200, null, ["Contact: ".concat(this._contact)], body); + + if (timeout < Timers.T2) { + timeout = timeout * 2; + + if (timeout > Timers.T2) { + timeout = Timers.T2; + } + } + + this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout); + } + + this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout); + } + /** + * RFC3261 14.2 + * If a UAS generates a 2xx response and never receives an ACK, + * it SHOULD generate a BYE to terminate the dialog. + */ + + }, { + key: "_setACKTimer", + value: function _setACKTimer() { + var _this11 = this; + + this._timers.ackTimer = setTimeout(function () { + if (_this11._status === C.STATUS_WAITING_FOR_ACK) { + debug('no ACK received, terminating the session'); + clearTimeout(_this11._timers.invite2xxTimer); + + _this11.sendRequest(JsSIP_C.BYE); + + _this11._ended('remote', null, JsSIP_C.causes.NO_ACK); + } + }, Timers.TIMER_H); + } + }, { + key: "_createRTCConnection", + value: function _createRTCConnection(pcConfig, rtcConstraints) { + var _this12 = this; + + this._connection = new RTCPeerConnection(pcConfig, rtcConstraints); + + this._connection.addEventListener('iceconnectionstatechange', function () { + var state = _this12._connection.iceConnectionState; // TODO: Do more with different states. + + if (state === 'failed') { + _this12.terminate({ + cause: JsSIP_C.causes.RTP_TIMEOUT, + status_code: 408, + reason_phrase: JsSIP_C.causes.RTP_TIMEOUT + }); + } + }); + + debug('emit "peerconnection"'); + this.emit('peerconnection', { + peerconnection: this._connection + }); + } + }, { + key: "_createLocalDescription", + value: function _createLocalDescription(type, constraints) { + var _this13 = this; + + debug('createLocalDescription()'); + if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\"")); + var connection = this._connection; + this._rtcReady = false; + return Promise.resolve() // Create Offer or Answer. + .then(function () { + if (type === 'offer') { + return connection.createOffer(constraints)["catch"](function (error) { + debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); + + _this13.emit('peerconnection:createofferfailed', error); + + return Promise.reject(error); + }); + } else { + return connection.createAnswer(constraints)["catch"](function (error) { + debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); + + _this13.emit('peerconnection:createanswerfailed', error); + + return Promise.reject(error); + }); + } + }) // Set local description. + .then(function (desc) { + return connection.setLocalDescription(desc)["catch"](function (error) { + _this13._rtcReady = true; + debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); + + _this13.emit('peerconnection:setlocaldescriptionfailed', error); + + return Promise.reject(error); + }); + }).then(function () { + // Resolve right away if 'pc.iceGatheringState' is 'complete'. + if (connection.iceGatheringState === 'complete' && (!constraints || !constraints.iceRestart)) { + _this13._rtcReady = true; + var e = { + originator: 'local', + type: type, + sdp: connection.localDescription.sdp + }; + debug('emit "sdp"'); + + _this13.emit('sdp', e); + + return Promise.resolve(e.sdp); + } // Add 'pc.onicencandidate' event handler to resolve on last candidate. + + + return new Promise(function (resolve) { + var finished = false; + var iceCandidateListener; + var iceGatheringStateListener; + + var ready = function ready() { + connection.removeEventListener('icecandidate', iceCandidateListener); + connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener); + finished = true; + _this13._rtcReady = true; + var e = { + originator: 'local', + type: type, + sdp: connection.localDescription.sdp + }; + debug('emit "sdp"'); + + _this13.emit('sdp', e); + + resolve(e.sdp); + }; + + connection.addEventListener('icecandidate', iceCandidateListener = function iceCandidateListener(event) { + var candidate = event.candidate; + + if (candidate) { + _this13.emit('icecandidate', { + candidate: candidate, + ready: ready + }); + } else if (!finished) { + ready(); + } + }); + connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = function iceGatheringStateListener() { + if (connection.iceGatheringState === 'complete' && !finished) { + ready(); + } + }); + }); + }); + } + /** + * Dialog Management + */ + + }, { + key: "_createDialog", + value: function _createDialog(message, type, early) { + var local_tag = type === 'UAS' ? message.to_tag : message.from_tag; + var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag; + var id = message.call_id + local_tag + remote_tag; + var early_dialog = this._earlyDialogs[id]; // Early Dialog. + + if (early) { + if (early_dialog) { + return true; + } else { + early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created. + + if (early_dialog.error) { + debug(early_dialog.error); + + this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); + + return false; + } else { + this._earlyDialogs[id] = early_dialog; + return true; + } + } + } // Confirmed Dialog. + else { + this._from_tag = message.from_tag; + this._to_tag = message.to_tag; // In case the dialog is in _early_ state, update it. + + if (early_dialog) { + early_dialog.update(message, type); + this._dialog = early_dialog; + delete this._earlyDialogs[id]; + return true; + } // Otherwise, create a _confirmed_ dialog. + + + var dialog = new Dialog(this, message, type); + + if (dialog.error) { + debug(dialog.error); + + this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); + + return false; + } else { + this._dialog = dialog; + return true; + } + } + } + /** + * In dialog INVITE Reception + */ + + }, { + key: "_receiveReinvite", + value: function _receiveReinvite(request) { + var _this14 = this; + + debug('receiveReinvite()'); + var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; + var data = { + request: request, + callback: undefined, + reject: reject.bind(this) + }; + var rejected = false; + + function reject() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + rejected = true; + var status_code = options.status_code || 403; + var reason_phrase = options.reason_phrase || ''; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + + if (this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } + + request.reply(status_code, reason_phrase, extraHeaders); + } // Emit 'reinvite'. + + + this.emit('reinvite', data); + + if (rejected) { + return; + } + + this._late_sdp = false; // Request without SDP. + + if (!request.body) { + this._late_sdp = true; + + if (this._remoteHold) { + this._remoteHold = false; + + this._onunhold('remote'); + } + + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this14._createLocalDescription('offer', _this14._rtcOfferConstraints); + }).then(function (sdp) { + sendAnswer.call(_this14, sdp); + })["catch"](function () { + request.reply(500); + }); + return; + } // Request with SDP. + + + if (contentType !== 'application/sdp') { + debug('invalid Content-Type'); + request.reply(415); + return; + } + + this._processInDialogSdpOffer(request) // Send answer. + .then(function (desc) { + if (_this14._status === C.STATUS_TERMINATED) { + return; + } + + sendAnswer.call(_this14, desc); + })["catch"](function (error) { + debugerror(error); + }); + + function sendAnswer(desc) { + var _this15 = this; + + var extraHeaders = ["Contact: ".concat(this._contact)]; + + this._handleSessionTimersInIncomingRequest(request, extraHeaders); + + if (this._late_sdp) { + desc = this._mangleOffer(desc); + } + + request.reply(200, null, extraHeaders, desc, function () { + _this15._status = C.STATUS_WAITING_FOR_ACK; + + _this15._setInvite2xxTimer(request, desc); + + _this15._setACKTimer(); + }); // If callback is given execute it. + + if (typeof data.callback === 'function') { + data.callback(); + } + } + } + /** + * In dialog UPDATE Reception + */ + + }, { + key: "_receiveUpdate", + value: function _receiveUpdate(request) { + var _this16 = this; + + debug('receiveUpdate()'); + var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; + var data = { + request: request, + callback: undefined, + reject: reject.bind(this) + }; + var rejected = false; + + function reject() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + rejected = true; + var status_code = options.status_code || 403; + var reason_phrase = options.reason_phrase || ''; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + + if (this._status !== C.STATUS_CONFIRMED) { + return false; + } + + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } + + request.reply(status_code, reason_phrase, extraHeaders); + } // Emit 'update'. + + + this.emit('update', data); + + if (rejected) { + return; + } + + if (!request.body) { + sendAnswer.call(this, null); + return; + } + + if (contentType !== 'application/sdp') { + debug('invalid Content-Type'); + request.reply(415); + return; + } + + this._processInDialogSdpOffer(request) // Send answer. + .then(function (desc) { + if (_this16._status === C.STATUS_TERMINATED) { + return; + } + + sendAnswer.call(_this16, desc); + })["catch"](function (error) { + debugerror(error); + }); + + function sendAnswer(desc) { + var extraHeaders = ["Contact: ".concat(this._contact)]; + + this._handleSessionTimersInIncomingRequest(request, extraHeaders); + + request.reply(200, null, extraHeaders, desc); // If callback is given execute it. + + if (typeof data.callback === 'function') { + data.callback(); + } + } + } + }, { + key: "_processInDialogSdpOffer", + value: function _processInDialogSdpOffer(request) { + var _this17 = this; + + debug('_processInDialogSdpOffer()'); + var sdp = request.parseSDP(); + var hold = false; + + var _iterator4 = _createForOfIteratorHelper(sdp.media), + _step4; + + try { + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + var m = _step4.value; + + if (holdMediaTypes.indexOf(m.type) === -1) { + continue; + } + + var direction = m.direction || sdp.direction || 'sendrecv'; + + if (direction === 'sendonly' || direction === 'inactive') { + hold = true; + } // If at least one of the streams is active don't emit 'hold'. + else { + hold = false; + break; + } + } + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); + } + + var e = { + originator: 'remote', + type: 'offer', + sdp: request.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var offer = new RTCSessionDescription({ + type: 'offer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue // Set remote description. + .then(function () { + if (_this17._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + return _this17._connection.setRemoteDescription(offer)["catch"](function (error) { + request.reply(488); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this17.emit('peerconnection:setremotedescriptionfailed', error); + + throw error; + }); + }).then(function () { + if (_this17._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + if (_this17._remoteHold === true && hold === false) { + _this17._remoteHold = false; + + _this17._onunhold('remote'); + } else if (_this17._remoteHold === false && hold === true) { + _this17._remoteHold = true; + + _this17._onhold('remote'); + } + }) // Create local description. + .then(function () { + if (_this17._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) { + request.reply(500); + debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); + throw error; + }); + })["catch"](function (error) { + debugerror('_processInDialogSdpOffer() failed [error: %o]', error); + }); + return this._connectionPromiseQueue; + } + /** + * In dialog Refer Reception + */ + + }, { + key: "_receiveRefer", + value: function _receiveRefer(request) { + var _this18 = this; + + debug('receiveRefer()'); + + if (!request.refer_to) { + debug('no Refer-To header field present in REFER'); + request.reply(400); + return; + } + + if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { + debug('Refer-To header field points to a non-SIP URI scheme'); + request.reply(416); + return; + } // Reply before the transaction timer expires. + + + request.reply(202); + var notifier = new RTCSession_ReferNotifier(this, request.cseq); + debug('emit "refer"'); // Emit 'refer'. + + this.emit('refer', { + request: request, + accept: function accept(initCallback, options) { + _accept.call(_this18, initCallback, options); + }, + reject: function reject() { + _reject.call(_this18); + } + }); + + function _accept(initCallback) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + initCallback = typeof initCallback === 'function' ? initCallback : null; + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + var session = new RTCSession(this._ua); + session.on('progress', function (_ref2) { + var response = _ref2.response; + notifier.notify(response.status_code, response.reason_phrase); + }); + session.on('accepted', function (_ref3) { + var response = _ref3.response; + notifier.notify(response.status_code, response.reason_phrase); + }); + session.on('_failed', function (_ref4) { + var message = _ref4.message, + cause = _ref4.cause; + + if (message) { + notifier.notify(message.status_code, message.reason_phrase); + } else { + notifier.notify(487, cause); + } + }); // Consider the Replaces header present in the Refer-To URI. + + if (request.refer_to.uri.hasHeader('replaces')) { + var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces')); + options.extraHeaders = Utils.cloneArray(options.extraHeaders); + options.extraHeaders.push("Replaces: ".concat(replaces)); + } + + session.connect(request.refer_to.uri.toAor(), options, initCallback); + } + + function _reject() { + notifier.notify(603); + } + } + /** + * In dialog Notify Reception + */ + + }, { + key: "_receiveNotify", + value: function _receiveNotify(request) { + debug('receiveNotify()'); + + if (!request.event) { + request.reply(400); + } + + switch (request.event.event) { + case 'refer': + { + var id; + var referSubscriber; + + if (request.event.params && request.event.params.id) { + id = request.event.params.id; + referSubscriber = this._referSubscribers[id]; + } else if (Object.keys(this._referSubscribers).length === 1) { + referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]]; + } else { + request.reply(400, 'Missing event id parameter'); + return; + } + + if (!referSubscriber) { + request.reply(481, 'Subscription does not exist'); + return; + } + + referSubscriber.receiveNotify(request); + request.reply(200); + break; + } + + default: + { + request.reply(489); + } + } + } + /** + * INVITE with Replaces Reception + */ + + }, { + key: "_receiveReplaces", + value: function _receiveReplaces(request) { + var _this20 = this; + + debug('receiveReplaces()'); + + function _accept2(initCallback) { + var _this19 = this; + + if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { + return false; + } + + var session = new RTCSession(this._ua); // Terminate the current session when the new one is confirmed. + + session.on('confirmed', function () { + _this19.terminate(); + }); + session.init_incoming(request, initCallback); + } + + function _reject2() { + debug('Replaced INVITE rejected by the user'); + request.reply(486); + } // Emit 'replace'. + + + this.emit('replaces', { + request: request, + accept: function accept(initCallback) { + _accept2.call(_this20, initCallback); + }, + reject: function reject() { + _reject2.call(_this20); + } + }); + } + /** + * Initial Request Sender + */ + + }, { + key: "_sendInitialRequest", + value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) { + var _this21 = this; + + var request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout: function onRequestTimeout() { + _this21.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this21.onTransportError(); + }, + // Update the request on authentication. + onAuthenticated: function onAuthenticated(request) { + _this21._request = request; + }, + onReceiveResponse: function onReceiveResponse(response) { + _this21._receiveInviteResponse(response); + } + }); // This Promise is resolved within the next iteration, so the app has now + // a chance to set events such as 'peerconnection' and 'connecting'. + + Promise.resolve() // Get a stream if required. + .then(function () { + // A stream is given, let the app set events such as 'peerconnection' and 'connecting'. + if (mediaStream) { + return mediaStream; + } // Request for user media access. + else if (mediaConstraints.audio || mediaConstraints.video) { + _this21._localMediaStreamLocallyGenerated = true; + return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) { + if (_this21._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); + + debugerror('emit "getusermediafailed" [error:%o]', error); + + _this21.emit('getusermediafailed', error); + + throw error; + }); + } + }).then(function (stream) { + if (_this21._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this21._localMediaStream = stream; + + if (stream) { + stream.getTracks().forEach(function (track) { + _this21._connection.addTrack(track, stream); + }); + } // TODO: should this be triggered here? + + + _this21._connecting(_this21._request); + + return _this21._createLocalDescription('offer', rtcOfferConstraints)["catch"](function (error) { + _this21._failed('local', null, JsSIP_C.causes.WEBRTC_ERROR); + + throw error; + }); + }).then(function (desc) { + if (_this21._is_canceled || _this21._status === C.STATUS_TERMINATED) { + throw new Error('terminated'); + } + + _this21._request.body = desc; + _this21._status = C.STATUS_INVITE_SENT; + debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. + + _this21.emit('sending', { + request: _this21._request + }); + + request_sender.send(); + })["catch"](function (error) { + if (_this21._status === C.STATUS_TERMINATED) { + return; + } + + debugerror(error); + }); + } + /** + * Get DTMF RTCRtpSender. + */ + + }, { + key: "_getDTMFRTPSender", + value: function _getDTMFRTPSender() { + var sender = this._connection.getSenders().find(function (rtpSender) { + return rtpSender.track && rtpSender.track.kind === 'audio'; + }); + + if (!(sender && sender.dtmf)) { + debugerror('sendDTMF() | no local audio track to send DTMF with'); + return; + } + + return sender.dtmf; + } + /** + * Reception of Response for Initial INVITE + */ + + }, { + key: "_receiveInviteResponse", + value: function _receiveInviteResponse(response) { + var _this22 = this; + + debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. + + if (this._dialog && response.status_code >= 200 && response.status_code <= 299) { + /* + * If it is a retransmission from the endpoint that established + * the dialog, send an ACK + */ + if (this._dialog.id.call_id === response.call_id && this._dialog.id.local_tag === response.from_tag && this._dialog.id.remote_tag === response.to_tag) { + this.sendRequest(JsSIP_C.ACK); + return; + } // If not, send an ACK and terminate. + else { + var dialog = new Dialog(this, response, 'UAC'); + + if (dialog.error !== undefined) { + debug(dialog.error); + return; + } + + this.sendRequest(JsSIP_C.ACK); + this.sendRequest(JsSIP_C.BYE); + return; + } + } // Proceed to cancellation if the user requested. + + + if (this._is_canceled) { + if (response.status_code >= 100 && response.status_code < 200) { + this._request.cancel(this._cancel_reason); + } else if (response.status_code >= 200 && response.status_code < 299) { + this._acceptAndTerminate(response); + } + + return; + } + + if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) { + return; + } + + switch (true) { + case /^100$/.test(response.status_code): + this._status = C.STATUS_1XX_RECEIVED; + break; + + case /^1[0-9]{2}$/.test(response.status_code): + { + // Do nothing with 1xx responses without To tag. + if (!response.to_tag) { + debug('1xx response received without to tag'); + break; + } // Create Early Dialog if 1XX comes with contact. + + + if (response.hasHeader('contact')) { + // An error on dialog creation will fire 'failed' event. + if (!this._createDialog(response, 'UAC', true)) { + break; + } + } + + this._status = C.STATUS_1XX_RECEIVED; + + if (!response.body) { + this._progress('remote', response); + + break; + } + + var e = { + originator: 'remote', + type: 'answer', + sdp: response.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var answer = new RTCSessionDescription({ + type: 'answer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this22._connection.setRemoteDescription(answer); + }).then(function () { + return _this22._progress('remote', response); + })["catch"](function (error) { + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this22.emit('peerconnection:setremotedescriptionfailed', error); + }); + break; + } + + case /^2[0-9]{2}$/.test(response.status_code): + { + this._status = C.STATUS_CONFIRMED; + + if (!response.body) { + this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP); + + this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); + + break; + } // An error on dialog creation will fire 'failed' event. + + + if (!this._createDialog(response, 'UAC')) { + break; + } + + var _e = { + originator: 'remote', + type: 'answer', + sdp: response.body + }; + debug('emit "sdp"'); + this.emit('sdp', _e); + + var _answer = new RTCSessionDescription({ + type: 'answer', + sdp: _e.sdp + }); + + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + // Be ready for 200 with SDP after a 180/183 with SDP. + // We created a SDP 'answer' for it, so check the current signaling state. + if (_this22._connection.signalingState === 'stable') { + return _this22._connection.createOffer(_this22._rtcOfferConstraints).then(function (offer) { + return _this22._connection.setLocalDescription(offer); + })["catch"](function (error) { + _this22._acceptAndTerminate(response, 500, error.toString()); + + _this22._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR); + }); + } + }).then(function () { + _this22._connection.setRemoteDescription(_answer).then(function () { + // Handle Session Timers. + _this22._handleSessionTimersInIncomingResponse(response); + + _this22._accepted('remote', response); + + _this22.sendRequest(JsSIP_C.ACK); + + _this22._confirmed('local', null); + })["catch"](function (error) { + _this22._acceptAndTerminate(response, 488, 'Not Acceptable Here'); + + _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); + + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this22.emit('peerconnection:setremotedescriptionfailed', error); + }); + }); + break; + } + + default: + { + var cause = Utils.sipErrorCause(response.status_code); + + this._failed('remote', response, cause); + } + } + } + /** + * Send Re-INVITE + */ + + }, { + key: "_sendReinvite", + value: function _sendReinvite() { + var _this23 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + debug('sendReinvite()'); + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; + var succeeded = false; + extraHeaders.push("Contact: ".concat(this._contact)); + extraHeaders.push('Content-Type: application/sdp'); // Session Timers. + + if (this._sessionTimers.running) { + extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas')); + } + + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this23._createLocalDescription('offer', rtcOfferConstraints); + }).then(function (sdp) { + sdp = _this23._mangleOffer(sdp); + var e = { + originator: 'local', + type: 'offer', + sdp: sdp + }; + debug('emit "sdp"'); + + _this23.emit('sdp', e); + + _this23.sendRequest(JsSIP_C.INVITE, { + extraHeaders: extraHeaders, + body: sdp, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + onSucceeded.call(_this23, response); + succeeded = true; + }, + onErrorResponse: function onErrorResponse(response) { + onFailed.call(_this23, response); + }, + onTransportError: function onTransportError() { + _this23.onTransportError(); // Do nothing because session ends. + + }, + onRequestTimeout: function onRequestTimeout() { + _this23.onRequestTimeout(); // Do nothing because session ends. + + }, + onDialogError: function onDialogError() { + _this23.onDialogError(); // Do nothing because session ends. + + } + } + }); + })["catch"](function () { + onFailed(); + }); + + function onSucceeded(response) { + var _this24 = this; + + if (this._status === C.STATUS_TERMINATED) { + return; + } + + this.sendRequest(JsSIP_C.ACK); // If it is a 2XX retransmission exit now. + + if (succeeded) { + return; + } // Handle Session Timers. + + + this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer. + + + if (!response.body) { + onFailed.call(this); + return; + } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') { + onFailed.call(this); + return; + } + + var e = { + originator: 'remote', + type: 'answer', + sdp: response.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var answer = new RTCSessionDescription({ + type: 'answer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this24._connection.setRemoteDescription(answer); + }).then(function () { + if (eventHandlers.succeeded) { + eventHandlers.succeeded(response); + } + })["catch"](function (error) { + onFailed.call(_this24); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this24.emit('peerconnection:setremotedescriptionfailed', error); + }); + } + + function onFailed(response) { + if (eventHandlers.failed) { + eventHandlers.failed(response); + } + } + } + /** + * Send UPDATE + */ + + }, { + key: "_sendUpdate", + value: function _sendUpdate() { + var _this25 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + debug('sendUpdate()'); + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; + var sdpOffer = options.sdpOffer || false; + var succeeded = false; + extraHeaders.push("Contact: ".concat(this._contact)); // Session Timers. + + if (this._sessionTimers.running) { + extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas')); + } + + if (sdpOffer) { + extraHeaders.push('Content-Type: application/sdp'); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this25._createLocalDescription('offer', rtcOfferConstraints); + }).then(function (sdp) { + sdp = _this25._mangleOffer(sdp); + var e = { + originator: 'local', + type: 'offer', + sdp: sdp + }; + debug('emit "sdp"'); + + _this25.emit('sdp', e); + + _this25.sendRequest(JsSIP_C.UPDATE, { + extraHeaders: extraHeaders, + body: sdp, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + onSucceeded.call(_this25, response); + succeeded = true; + }, + onErrorResponse: function onErrorResponse(response) { + onFailed.call(_this25, response); + }, + onTransportError: function onTransportError() { + _this25.onTransportError(); // Do nothing because session ends. + + }, + onRequestTimeout: function onRequestTimeout() { + _this25.onRequestTimeout(); // Do nothing because session ends. + + }, + onDialogError: function onDialogError() { + _this25.onDialogError(); // Do nothing because session ends. + + } + } + }); + })["catch"](function () { + onFailed.call(_this25); + }); + } // No SDP. + else { + this.sendRequest(JsSIP_C.UPDATE, { + extraHeaders: extraHeaders, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + onSucceeded.call(_this25, response); + }, + onErrorResponse: function onErrorResponse(response) { + onFailed.call(_this25, response); + }, + onTransportError: function onTransportError() { + _this25.onTransportError(); // Do nothing because session ends. + + }, + onRequestTimeout: function onRequestTimeout() { + _this25.onRequestTimeout(); // Do nothing because session ends. + + }, + onDialogError: function onDialogError() { + _this25.onDialogError(); // Do nothing because session ends. + + } + } + }); + } + + function onSucceeded(response) { + var _this26 = this; + + if (this._status === C.STATUS_TERMINATED) { + return; + } // If it is a 2XX retransmission exit now. + + + if (succeeded) { + return; + } // Handle Session Timers. + + + this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer. + + + if (sdpOffer) { + if (!response.body) { + onFailed.call(this); + return; + } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') { + onFailed.call(this); + return; + } + + var e = { + originator: 'remote', + type: 'answer', + sdp: response.body + }; + debug('emit "sdp"'); + this.emit('sdp', e); + var answer = new RTCSessionDescription({ + type: 'answer', + sdp: e.sdp + }); + this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () { + return _this26._connection.setRemoteDescription(answer); + }).then(function () { + if (eventHandlers.succeeded) { + eventHandlers.succeeded(response); + } + })["catch"](function (error) { + onFailed.call(_this26); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + + _this26.emit('peerconnection:setremotedescriptionfailed', error); + }); + } // No SDP answer. + else if (eventHandlers.succeeded) { + eventHandlers.succeeded(response); + } + } + + function onFailed(response) { + if (eventHandlers.failed) { + eventHandlers.failed(response); + } + } + } + }, { + key: "_acceptAndTerminate", + value: function _acceptAndTerminate(response, status_code, reason_phrase) { + debug('acceptAndTerminate()'); + var extraHeaders = []; + + if (status_code) { + reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; + extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\"")); + } // An error on dialog creation will fire 'failed' event. + + + if (this._dialog || this._createDialog(response, 'UAC')) { + this.sendRequest(JsSIP_C.ACK); + this.sendRequest(JsSIP_C.BYE, { + extraHeaders: extraHeaders + }); + } // Update session status. + + + this._status = C.STATUS_TERMINATED; + } + /** + * Correctly set the SDP direction attributes if the call is on local hold + */ + + }, { + key: "_mangleOffer", + value: function _mangleOffer(sdp) { + if (!this._localHold && !this._remoteHold) { + return sdp; + } + + sdp = sdp_transform.parse(sdp); // Local hold. + + if (this._localHold && !this._remoteHold) { + debug('mangleOffer() | me on hold, mangling offer'); + + var _iterator5 = _createForOfIteratorHelper(sdp.media), + _step5; + + try { + for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { + var m = _step5.value; + + if (holdMediaTypes.indexOf(m.type) === -1) { + continue; + } + + if (!m.direction) { + m.direction = 'sendonly'; + } else if (m.direction === 'sendrecv') { + m.direction = 'sendonly'; + } else if (m.direction === 'recvonly') { + m.direction = 'inactive'; + } + } + } catch (err) { + _iterator5.e(err); + } finally { + _iterator5.f(); + } + } // Local and remote hold. + else if (this._localHold && this._remoteHold) { + debug('mangleOffer() | both on hold, mangling offer'); + + var _iterator6 = _createForOfIteratorHelper(sdp.media), + _step6; + + try { + for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { + var _m = _step6.value; + + if (holdMediaTypes.indexOf(_m.type) === -1) { + continue; + } + + _m.direction = 'inactive'; + } + } catch (err) { + _iterator6.e(err); + } finally { + _iterator6.f(); + } + } // Remote hold. + else if (this._remoteHold) { + debug('mangleOffer() | remote on hold, mangling offer'); + + var _iterator7 = _createForOfIteratorHelper(sdp.media), + _step7; + + try { + for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { + var _m2 = _step7.value; + + if (holdMediaTypes.indexOf(_m2.type) === -1) { + continue; + } + + if (!_m2.direction) { + _m2.direction = 'recvonly'; + } else if (_m2.direction === 'sendrecv') { + _m2.direction = 'recvonly'; + } else if (_m2.direction === 'recvonly') { + _m2.direction = 'inactive'; + } + } + } catch (err) { + _iterator7.e(err); + } finally { + _iterator7.f(); + } + } + + return sdp_transform.write(sdp); + } + }, { + key: "_setLocalMediaStatus", + value: function _setLocalMediaStatus() { + var enableAudio = true, + enableVideo = true; + + if (this._localHold || this._remoteHold) { + enableAudio = false; + enableVideo = false; + } + + if (this._audioMuted) { + enableAudio = false; + } + + if (this._videoMuted) { + enableVideo = false; + } + + this._toggleMuteAudio(!enableAudio); + + this._toggleMuteVideo(!enableVideo); + } + /** + * Handle SessionTimers for an incoming INVITE or UPDATE. + * @param {IncomingRequest} request + * @param {Array} responseExtraHeaders Extra headers for the 200 response. + */ + + }, { + key: "_handleSessionTimersInIncomingRequest", + value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) { + if (!this._sessionTimers.enabled) { + return; + } + + var session_expires_refresher; + + if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) { + this._sessionTimers.currentExpires = request.session_expires; + session_expires_refresher = request.session_expires_refresher || 'uas'; + } else { + this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires; + session_expires_refresher = 'uas'; + } + + responseExtraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(session_expires_refresher)); + this._sessionTimers.refresher = session_expires_refresher === 'uas'; + + this._runSessionTimer(); + } + /** + * Handle SessionTimers for an incoming response to INVITE or UPDATE. + * @param {IncomingResponse} response + */ + + }, { + key: "_handleSessionTimersInIncomingResponse", + value: function _handleSessionTimersInIncomingResponse(response) { + if (!this._sessionTimers.enabled) { + return; + } + + var session_expires_refresher; + + if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) { + this._sessionTimers.currentExpires = response.session_expires; + session_expires_refresher = response.session_expires_refresher || 'uac'; + } else { + this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires; + session_expires_refresher = 'uac'; + } + + this._sessionTimers.refresher = session_expires_refresher === 'uac'; + + this._runSessionTimer(); + } + }, { + key: "_runSessionTimer", + value: function _runSessionTimer() { + var _this27 = this; + + var expires = this._sessionTimers.currentExpires; + this._sessionTimers.running = true; + clearTimeout(this._sessionTimers.timer); // I'm the refresher. + + if (this._sessionTimers.refresher) { + this._sessionTimers.timer = setTimeout(function () { + if (_this27._status === C.STATUS_TERMINATED) { + return; + } + + debug('runSessionTimer() | sending session refresh request'); + + if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { + _this27._sendUpdate(); + } else { + _this27._sendReinvite(); + } + }, expires * 500); // Half the given interval (as the RFC states). + } // I'm not the refresher. + else { + this._sessionTimers.timer = setTimeout(function () { + if (_this27._status === C.STATUS_TERMINATED) { + return; + } + + debugerror('runSessionTimer() | timer expired, terminating the session'); + + _this27.terminate({ + cause: JsSIP_C.causes.REQUEST_TIMEOUT, + status_code: 408, + reason_phrase: 'Session Timer Expired' + }); + }, expires * 1100); + } + } + }, { + key: "_toggleMuteAudio", + value: function _toggleMuteAudio(mute) { + var senders = this._connection.getSenders().filter(function (sender) { + return sender.track && sender.track.kind === 'audio'; + }); + + var _iterator8 = _createForOfIteratorHelper(senders), + _step8; + + try { + for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { + var sender = _step8.value; + sender.track.enabled = !mute; + } + } catch (err) { + _iterator8.e(err); + } finally { + _iterator8.f(); + } + } + }, { + key: "_toggleMuteVideo", + value: function _toggleMuteVideo(mute) { + var senders = this._connection.getSenders().filter(function (sender) { + return sender.track && sender.track.kind === 'video'; + }); + + var _iterator9 = _createForOfIteratorHelper(senders), + _step9; + + try { + for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { + var sender = _step9.value; + sender.track.enabled = !mute; + } + } catch (err) { + _iterator9.e(err); + } finally { + _iterator9.f(); + } + } + }, { + key: "_newRTCSession", + value: function _newRTCSession(originator, request) { + debug('newRTCSession()'); + + this._ua.newRTCSession(this, { + originator: originator, + session: this, + request: request + }); + } + }, { + key: "_connecting", + value: function _connecting(request) { + debug('session connecting'); + debug('emit "connecting"'); + this.emit('connecting', { + request: request + }); + } + }, { + key: "_progress", + value: function _progress(originator, response) { + debug('session progress'); + debug('emit "progress"'); + this.emit('progress', { + originator: originator, + response: response || null + }); + } + }, { + key: "_accepted", + value: function _accepted(originator, message) { + debug('session accepted'); + this._start_time = new Date(); + debug('emit "accepted"'); + this.emit('accepted', { + originator: originator, + response: message || null + }); + } + }, { + key: "_confirmed", + value: function _confirmed(originator, ack) { + debug('session confirmed'); + this._is_confirmed = true; + debug('emit "confirmed"'); + this.emit('confirmed', { + originator: originator, + ack: ack || null + }); + } + }, { + key: "_ended", + value: function _ended(originator, message, cause) { + debug('session ended'); + this._end_time = new Date(); + + this._close(); + + debug('emit "ended"'); + this.emit('ended', { + originator: originator, + message: message || null, + cause: cause + }); + } + }, { + key: "_failed", + value: function _failed(originator, message, cause) { + debug('session failed'); // Emit private '_failed' event first. + + debug('emit "_failed"'); + this.emit('_failed', { + originator: originator, + message: message || null, + cause: cause + }); + + this._close(); + + debug('emit "failed"'); + this.emit('failed', { + originator: originator, + message: message || null, + cause: cause + }); + } + }, { + key: "_onhold", + value: function _onhold(originator) { + debug('session onhold'); + + this._setLocalMediaStatus(); + + debug('emit "hold"'); + this.emit('hold', { + originator: originator + }); + } + }, { + key: "_onunhold", + value: function _onunhold(originator) { + debug('session onunhold'); + + this._setLocalMediaStatus(); + + debug('emit "unhold"'); + this.emit('unhold', { + originator: originator + }); + } + }, { + key: "_onmute", + value: function _onmute(_ref5) { + var audio = _ref5.audio, + video = _ref5.video; + debug('session onmute'); + + this._setLocalMediaStatus(); + + debug('emit "muted"'); + this.emit('muted', { + audio: audio, + video: video + }); + } + }, { + key: "_onunmute", + value: function _onunmute(_ref6) { + var audio = _ref6.audio, + video = _ref6.video; + debug('session onunmute'); + + this._setLocalMediaStatus(); + + debug('emit "unmuted"'); + this.emit('unmuted', { + audio: audio, + video: video + }); + } + }], [{ + key: "C", + get: + /** + * Expose C object. + */ + function get() { + return C; + } + }]); + + return RTCSession; +}(EventEmitter); +},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,"debug":32,"events":31,"sdp-transform":37}],14:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('../Constants'); + +var Exceptions = require('../Exceptions'); + +var Utils = require('../Utils'); + +var debug = require('debug')('JsSIP:RTCSession:DTMF'); + +var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); + +debugerror.log = console.warn.bind(console); +var C = { + MIN_DURATION: 70, + MAX_DURATION: 6000, + DEFAULT_DURATION: 100, + MIN_INTER_TONE_GAP: 50, + DEFAULT_INTER_TONE_GAP: 500 +}; + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(DTMF, _EventEmitter); + + var _super = _createSuper(DTMF); + + function DTMF(session) { + var _this; + + _classCallCheck(this, DTMF); + + _this = _super.call(this); + _this._session = session; + _this._direction = null; + _this._tone = null; + _this._duration = null; + _this._request = null; + return _this; + } + + _createClass(DTMF, [{ + key: "tone", + get: function get() { + return this._tone; + } + }, { + key: "duration", + get: function get() { + return this._duration; + } + }, { + key: "send", + value: function send(tone) { + var _this2 = this; + + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if (tone === undefined) { + throw new TypeError('Not enough arguments'); + } + + this._direction = 'outgoing'; // Check RTCSession Status. + + if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) { + throw new Exceptions.InvalidStateError(this._session.status); + } + + var extraHeaders = Utils.cloneArray(options.extraHeaders); + this.eventHandlers = Utils.cloneObject(options.eventHandlers); // Check tone type. + + if (typeof tone === 'string') { + tone = tone.toUpperCase(); + } else if (typeof tone === 'number') { + tone = tone.toString(); + } else { + throw new TypeError("Invalid tone: ".concat(tone)); + } // Check tone value. + + + if (!tone.match(/^[0-9A-DR#*]$/)) { + throw new TypeError("Invalid tone: ".concat(tone)); + } else { + this._tone = tone; + } // Duration is checked/corrected in RTCSession. + + + this._duration = options.duration; + extraHeaders.push('Content-Type: application/dtmf-relay'); + var body = "Signal=".concat(this._tone, "\r\n"); + body += "Duration=".concat(this._duration); + + this._session.newDTMF({ + originator: 'local', + dtmf: this, + request: this._request + }); + + this._session.sendRequest(JsSIP_C.INFO, { + extraHeaders: extraHeaders, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + _this2.emit('succeeded', { + originator: 'remote', + response: response + }); + }, + onErrorResponse: function onErrorResponse(response) { + if (_this2.eventHandlers.onFailed) { + _this2.eventHandlers.onFailed(); + } + + _this2.emit('failed', { + originator: 'remote', + response: response + }); + }, + onRequestTimeout: function onRequestTimeout() { + _this2._session.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this2._session.onTransportError(); + }, + onDialogError: function onDialogError() { + _this2._session.onDialogError(); + } + }, + body: body + }); + } + }, { + key: "init_incoming", + value: function init_incoming(request) { + var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/; + var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/; + this._direction = 'incoming'; + this._request = request; + request.reply(200); + + if (request.body) { + var body = request.body.split('\n'); + + if (body.length >= 1) { + if (reg_tone.test(body[0])) { + this._tone = body[0].replace(reg_tone, '$2'); + } + } + + if (body.length >= 2) { + if (reg_duration.test(body[1])) { + this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10); + } + } + } + + if (!this._duration) { + this._duration = C.DEFAULT_DURATION; + } + + if (!this._tone) { + debug('invalid INFO DTMF received, discarded'); + } else { + this._session.newDTMF({ + originator: 'remote', + dtmf: this, + request: request + }); + } + } + }]); + + return DTMF; +}(EventEmitter); +/** + * Expose C object. + */ + + +module.exports.C = C; +},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],15:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); + +debugerror.log = console.warn.bind(console); + +var JsSIP_C = require('../Constants'); + +var Exceptions = require('../Exceptions'); + +var Utils = require('../Utils'); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Info, _EventEmitter); + + var _super = _createSuper(Info); + + function Info(session) { + var _this; + + _classCallCheck(this, Info); + + _this = _super.call(this); + _this._session = session; + _this._direction = null; + _this._contentType = null; + _this._body = null; + return _this; + } + + _createClass(Info, [{ + key: "contentType", + get: function get() { + return this._contentType; + } + }, { + key: "body", + get: function get() { + return this._body; + } + }, { + key: "send", + value: function send(contentType, body) { + var _this2 = this; + + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + this._direction = 'outgoing'; + + if (contentType === undefined) { + throw new TypeError('Not enough arguments'); + } // Check RTCSession Status. + + + if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) { + throw new Exceptions.InvalidStateError(this._session.status); + } + + this._contentType = contentType; + this._body = body; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + extraHeaders.push("Content-Type: ".concat(contentType)); + + this._session.newInfo({ + originator: 'local', + info: this, + request: this.request + }); + + this._session.sendRequest(JsSIP_C.INFO, { + extraHeaders: extraHeaders, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + _this2.emit('succeeded', { + originator: 'remote', + response: response + }); + }, + onErrorResponse: function onErrorResponse(response) { + _this2.emit('failed', { + originator: 'remote', + response: response + }); + }, + onTransportError: function onTransportError() { + _this2._session.onTransportError(); + }, + onRequestTimeout: function onRequestTimeout() { + _this2._session.onRequestTimeout(); + }, + onDialogError: function onDialogError() { + _this2._session.onDialogError(); + } + }, + body: body + }); + } + }, { + key: "init_incoming", + value: function init_incoming(request) { + this._direction = 'incoming'; + this.request = request; + request.reply(200); + this._contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; + this._body = request.body; + + this._session.newInfo({ + originator: 'remote', + info: this, + request: request + }); + } + }]); + + return Info; +}(EventEmitter); +},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],16:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var JsSIP_C = require('../Constants'); + +var debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); + +var C = { + event_type: 'refer', + body_type: 'message/sipfrag;version=2.0', + expires: 300 +}; + +module.exports = /*#__PURE__*/function () { + function ReferNotifier(session, id, expires) { + _classCallCheck(this, ReferNotifier); + + this._session = session; + this._id = id; + this._expires = expires || C.expires; + this._active = true; // The creation of a Notifier results in an immediate NOTIFY. + + this.notify(100); + } + + _createClass(ReferNotifier, [{ + key: "notify", + value: function notify(code, reason) { + debug('notify()'); + + if (this._active === false) { + return; + } + + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + var state; + + if (code >= 200) { + state = 'terminated;reason=noresource'; + } else { + state = "active;expires=".concat(this._expires); + } // Put this in a try/catch block. + + + this._session.sendRequest(JsSIP_C.NOTIFY, { + extraHeaders: ["Event: ".concat(C.event_type, ";id=").concat(this._id), "Subscription-State: ".concat(state), "Content-Type: ".concat(C.body_type)], + body: "SIP/2.0 ".concat(code, " ").concat(reason), + eventHandlers: { + // If a negative response is received, subscription is canceled. + onErrorResponse: function onErrorResponse() { + this._active = false; + } + } + }); + } + }]); + + return ReferNotifier; +}(); +},{"../Constants":2,"debug":32}],17:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('../Constants'); + +var Grammar = require('../Grammar'); + +var Utils = require('../Utils'); + +var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(ReferSubscriber, _EventEmitter); + + var _super = _createSuper(ReferSubscriber); + + function ReferSubscriber(session) { + var _this; + + _classCallCheck(this, ReferSubscriber); + + _this = _super.call(this); + _this._id = null; + _this._session = session; + return _this; + } + + _createClass(ReferSubscriber, [{ + key: "id", + get: function get() { + return this._id; + } + }, { + key: "sendRefer", + value: function sendRefer(target) { + var _this2 = this; + + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + debug('sendRefer()'); + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers. + + for (var event in eventHandlers) { + if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { + this.on(event, eventHandlers[event]); + } + } // Replaces URI header field. + + + var replaces = null; + + if (options.replaces) { + replaces = options.replaces._request.call_id; + replaces += ";to-tag=".concat(options.replaces._to_tag); + replaces += ";from-tag=".concat(options.replaces._from_tag); + replaces = encodeURIComponent(replaces); + } // Refer-To header field. + + + var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">"); + extraHeaders.push(referTo); // Referred-By header field. + + var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); + extraHeaders.push(referredBy); + extraHeaders.push("Contact: ".concat(this._session.contact)); + + var request = this._session.sendRequest(JsSIP_C.REFER, { + extraHeaders: extraHeaders, + eventHandlers: { + onSuccessResponse: function onSuccessResponse(response) { + _this2._requestSucceeded(response); + }, + onErrorResponse: function onErrorResponse(response) { + _this2._requestFailed(response, JsSIP_C.causes.REJECTED); + }, + onTransportError: function onTransportError() { + _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR); + }, + onRequestTimeout: function onRequestTimeout() { + _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT); + }, + onDialogError: function onDialogError() { + _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR); + } + } + }); + + this._id = request.cseq; + } + }, { + key: "receiveNotify", + value: function receiveNotify(request) { + debug('receiveNotify()'); + + if (!request.body) { + return; + } + + var status_line = Grammar.parse(request.body.trim(), 'Status_Line'); + + if (status_line === -1) { + debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); + return; + } + + switch (true) { + case /^100$/.test(status_line.status_code): + this.emit('trying', { + request: request, + status_line: status_line + }); + break; + + case /^1[0-9]{2}$/.test(status_line.status_code): + this.emit('progress', { + request: request, + status_line: status_line + }); + break; + + case /^2[0-9]{2}$/.test(status_line.status_code): + this.emit('accepted', { + request: request, + status_line: status_line + }); + break; + + default: + this.emit('failed', { + request: request, + status_line: status_line + }); + break; + } + } + }, { + key: "_requestSucceeded", + value: function _requestSucceeded(response) { + debug('REFER succeeded'); + debug('emit "requestSucceeded"'); + this.emit('requestSucceeded', { + response: response + }); + } + }, { + key: "_requestFailed", + value: function _requestFailed(response, cause) { + debug('REFER failed'); + debug('emit "requestFailed"'); + this.emit('requestFailed', { + response: response || null, + cause: cause + }); + } + }]); + + return ReferSubscriber; +}(EventEmitter); +},{"../Constants":2,"../Grammar":7,"../Utils":28,"debug":32,"events":31}],18:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var Utils = require('./Utils'); + +var JsSIP_C = require('./Constants'); + +var SIPMessage = require('./SIPMessage'); + +var RequestSender = require('./RequestSender'); + +var debug = require('debug')('JsSIP:Registrator'); + +var MIN_REGISTER_EXPIRES = 10; // In seconds. + +module.exports = /*#__PURE__*/function () { + function Registrator(ua, transport) { + _classCallCheck(this, Registrator); + + var reg_id = 1; // Force reg_id to 1. + + this._ua = ua; + this._transport = transport; + this._registrar = ua.configuration.registrar_server; + this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2. + + this._call_id = Utils.createRandomToken(22); + this._cseq = 0; + this._to_uri = ua.configuration.uri; + this._registrationTimer = null; // Ongoing Register request. + + this._registering = false; // Set status. + + this._registered = false; // Contact header. + + this._contact = this._ua.contact.toString(); // Sip.ice media feature tag (RFC 5768). + + this._contact += ';+sip.ice'; // Custom headers for REGISTER and un-REGISTER. + + this._extraHeaders = []; // Custom Contact header params for REGISTER and un-REGISTER. + + this._extraContactParams = ''; + + if (reg_id) { + this._contact += ";reg-id=".concat(reg_id); + this._contact += ";+sip.instance=\"\""); + } + } + + _createClass(Registrator, [{ + key: "registered", + get: function get() { + return this._registered; + } + }, { + key: "setExtraHeaders", + value: function setExtraHeaders(extraHeaders) { + if (!Array.isArray(extraHeaders)) { + extraHeaders = []; + } + + this._extraHeaders = extraHeaders.slice(); + } + }, { + key: "setExtraContactParams", + value: function setExtraContactParams(extraContactParams) { + if (!(extraContactParams instanceof Object)) { + extraContactParams = {}; + } // Reset it. + + + this._extraContactParams = ''; + + for (var param_key in extraContactParams) { + if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) { + var param_value = extraContactParams[param_key]; + this._extraContactParams += ";".concat(param_key); + + if (param_value) { + this._extraContactParams += "=".concat(param_value); + } + } + } + } + }, { + key: "register", + value: function register() { + var _this = this; + + if (this._registering) { + debug('Register request in progress...'); + return; + } + + var extraHeaders = this._extraHeaders.slice(); + + extraHeaders.push("Contact: ".concat(this._contact, ";expires=").concat(this._expires).concat(this._extraContactParams)); + extraHeaders.push("Expires: ".concat(this._expires)); + var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, { + 'to_uri': this._to_uri, + 'call_id': this._call_id, + 'cseq': this._cseq += 1 + }, extraHeaders); + var request_sender = new RequestSender(this._ua, request, { + onRequestTimeout: function onRequestTimeout() { + _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT); + }, + onTransportError: function onTransportError() { + _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR); + }, + // Increase the CSeq on authentication. + onAuthenticated: function onAuthenticated() { + _this._cseq += 1; + }, + onReceiveResponse: function onReceiveResponse(response) { + // Discard responses to older REGISTER/un-REGISTER requests. + if (response.cseq !== _this._cseq) { + return; + } // Clear registration timer. + + + if (_this._registrationTimer !== null) { + clearTimeout(_this._registrationTimer); + _this._registrationTimer = null; + } + + switch (true) { + case /^1[0-9]{2}$/.test(response.status_code): + { + // Ignore provisional responses. + break; + } + + case /^2[0-9]{2}$/.test(response.status_code): + { + _this._registering = false; + + if (!response.hasHeader('Contact')) { + debug('no Contact header in response to REGISTER, response ignored'); + break; + } + + var contacts = response.headers['Contact'].reduce(function (a, b) { + return a.concat(b.parsed); + }, []); // Get the Contact pointing to us and update the expires value accordingly. + + var contact = contacts.find(function (element) { + return element.uri.user === _this._ua.contact.uri.user; + }); + + if (!contact) { + debug('no Contact header pointing to us, response ignored'); + break; + } + + var expires = contact.getParam('expires'); + + if (!expires && response.hasHeader('expires')) { + expires = response.getHeader('expires'); + } + + if (!expires) { + expires = _this._expires; + } + + expires = Number(expires); + if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES; + var timeout = expires > 64 ? expires * 1000 / 2 + Math.floor((expires / 2 - 32) * 1000 * Math.random()) : expires * 1000 - 5000; // Re-Register or emit an event before the expiration interval has elapsed. + // For that, decrease the expires value. ie: 3 seconds. + + _this._registrationTimer = setTimeout(function () { + _this._registrationTimer = null; // If there are no listeners for registrationExpiring, renew registration. + // If there are listeners, let the function listening do the register call. + + if (_this._ua.listeners('registrationExpiring').length === 0) { + _this.register(); + } else { + _this._ua.emit('registrationExpiring'); + } + }, timeout); // Save gruu values. + + if (contact.hasParam('temp-gruu')) { + _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, ''); + } + + if (contact.hasParam('pub-gruu')) { + _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, ''); + } + + if (!_this._registered) { + _this._registered = true; + + _this._ua.registered({ + response: response + }); + } + + break; + } + // Interval too brief RFC3261 10.2.8. + + case /^423$/.test(response.status_code): + { + if (response.hasHeader('min-expires')) { + // Increase our registration interval to the suggested minimum. + _this._expires = Number(response.getHeader('min-expires')); + if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES; // Attempt the registration again immediately. + + _this.register(); + } else { + // This response MUST contain a Min-Expires header field. + debug('423 response received for REGISTER without Min-Expires'); + + _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); + } + + break; + } + + default: + { + var cause = Utils.sipErrorCause(response.status_code); + + _this._registrationFailure(response, cause); + } + } + } + }); + this._registering = true; + request_sender.send(); + } + }, { + key: "unregister", + value: function unregister() { + var _this2 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + if (!this._registered) { + debug('already unregistered'); + return; + } + + this._registered = false; // Clear the registration timer. + + if (this._registrationTimer !== null) { + clearTimeout(this._registrationTimer); + this._registrationTimer = null; + } + + var extraHeaders = this._extraHeaders.slice(); + + if (options.all) { + extraHeaders.push("Contact: *".concat(this._extraContactParams)); + } else { + extraHeaders.push("Contact: ".concat(this._contact, ";expires=0").concat(this._extraContactParams)); + } + + extraHeaders.push('Expires: 0'); + var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, { + 'to_uri': this._to_uri, + 'call_id': this._call_id, + 'cseq': this._cseq += 1 + }, extraHeaders); + var request_sender = new RequestSender(this._ua, request, { + onRequestTimeout: function onRequestTimeout() { + _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT); + }, + onTransportError: function onTransportError() { + _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR); + }, + // Increase the CSeq on authentication. + onAuthenticated: function onAuthenticated() { + _this2._cseq += 1; + }, + onReceiveResponse: function onReceiveResponse(response) { + switch (true) { + case /^1[0-9]{2}$/.test(response.status_code): + // Ignore provisional responses. + break; + + case /^2[0-9]{2}$/.test(response.status_code): + _this2._unregistered(response); + + break; + + default: + { + var cause = Utils.sipErrorCause(response.status_code); + + _this2._unregistered(response, cause); + } + } + } + }); + request_sender.send(); + } + }, { + key: "close", + value: function close() { + if (this._registered) { + this.unregister(); + } + } + }, { + key: "onTransportClosed", + value: function onTransportClosed() { + this._registering = false; + + if (this._registrationTimer !== null) { + clearTimeout(this._registrationTimer); + this._registrationTimer = null; + } + + if (this._registered) { + this._registered = false; + + this._ua.unregistered({}); + } + } + }, { + key: "_registrationFailure", + value: function _registrationFailure(response, cause) { + this._registering = false; + + this._ua.registrationFailed({ + response: response || null, + cause: cause + }); + + if (this._registered) { + this._registered = false; + + this._ua.unregistered({ + response: response || null, + cause: cause + }); + } + } + }, { + key: "_unregistered", + value: function _unregistered(response, cause) { + this._registering = false; + this._registered = false; + + this._ua.unregistered({ + response: response || null, + cause: cause || null + }); + } + }]); + + return Registrator; +}(); +},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32}],19:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var JsSIP_C = require('./Constants'); + +var DigestAuthentication = require('./DigestAuthentication'); + +var Transactions = require('./Transactions'); + +var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers. + + +var EventHandlers = { + onRequestTimeout: function onRequestTimeout() {}, + onTransportError: function onTransportError() {}, + onReceiveResponse: function onReceiveResponse() {}, + onAuthenticated: function onAuthenticated() {} +}; + +module.exports = /*#__PURE__*/function () { + function RequestSender(ua, request, eventHandlers) { + var config2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + + _classCallCheck(this, RequestSender); + + this._ua = ua; + this._eventHandlers = eventHandlers; + this._method = request.method; + this._request = request; + this._auth = null; + this._challenged = false; + this._staled = false; + this._config2 = config2; // Define the undefined handlers. + + for (var handler in EventHandlers) { + if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { + if (!this._eventHandlers[handler]) { + this._eventHandlers[handler] = EventHandlers[handler]; + } + } + } // If ua is in closing process or even closed just allow sending Bye and ACK. + + + if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) { + this._eventHandlers.onTransportError(); + } + } + /** + * Create the client transaction and send the message. + */ + + + _createClass(RequestSender, [{ + key: "send", + value: function send() { + var _this = this; + + var eventHandlers = { + onRequestTimeout: function onRequestTimeout() { + _this._eventHandlers.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this._eventHandlers.onTransportError(); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this._receiveResponse(response); + } + }; + + switch (this._method) { + case 'INVITE': + this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); + break; + + case 'ACK': + this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); + break; + + default: + this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers); + } // If authorization JWT is present, use it. + + + if (this._ua._configuration.authorization_jwt) { + this._request.setHeader('Authorization', this._ua._configuration.authorization_jwt); + } + + this.clientTransaction.send(); + } + /** + * Called from client transaction when receiving a correct response to the request. + * Authenticate request if needed or pass the response back to the applicant. + */ + + }, { + key: "_receiveResponse", + value: function _receiveResponse(response) { + var challenge; + var authorization_header_name; + var status_code = response.status_code; + /* + * Authentication + * Authenticate once. _challenged_ flag used to avoid infinite authentications. + */ + + if ((status_code === 401 || status_code === 407) && (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { + // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. + if (response.status_code === 401) { + challenge = response.parseHeader('www-authenticate'); + authorization_header_name = 'authorization'; + } else { + challenge = response.parseHeader('proxy-authenticate'); + authorization_header_name = 'proxy-authorization'; + } // Verify it seems a valid challenge. + + + if (!challenge) { + debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); + + this._eventHandlers.onReceiveResponse(response); + + return; + } + + if (!this._challenged || !this._staled && challenge.stale === true) { + if (!this._auth) { + var cnf = this._config2 ? this._config2 : this._ua.configuration; + this._auth = new DigestAuthentication({ + username: cnf.authorization_user, + password: cnf.password, + realm: cnf.realm, + ha1: cnf.ha1 + }); + } // Verify that the challenge is really valid. + + + if (!this._auth.authenticate(this._request, challenge)) { + this._eventHandlers.onReceiveResponse(response); + + return; + } + + this._challenged = true; // Update ha1 and realm in the UA or in alternative config. + + if (!this._config2) { + this._ua.set('realm', this._auth.get('realm')); + + this._ua.set('ha1', this._auth.get('ha1')); + } else { + this._config2.realm = this._auth.get('realm'); + this._config2.ha1 = this._auth.get('ha1'); + } + + if (challenge.stale) { + this._staled = true; + } + + this._request = this._request.clone(); + this._request.cseq += 1; + + this._request.setHeader('cseq', "".concat(this._request.cseq, " ").concat(this._method)); + + this._request.setHeader(authorization_header_name, this._auth.toString()); + + this._eventHandlers.onAuthenticated(this._request); + + this.send(); + } else { + this._eventHandlers.onReceiveResponse(response); + } + } else { + this._eventHandlers.onReceiveResponse(response); + } + } + }]); + + return RequestSender; +}(); +},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,"debug":32}],20:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var sdp_transform = require('sdp-transform'); + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var NameAddrHeader = require('./NameAddrHeader'); + +var Grammar = require('./Grammar'); + +var debug = require('debug')('JsSIP:SIPMessage'); +/** + * -param {String} method request method + * -param {String} ruri request uri + * -param {UA} ua + * -param {Object} params parameters that will have priority over ua.configuration parameters: + *
+ * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set + * -param {Object} [headers] extra headers + * -param {String} [body] + */ + + +var OutgoingRequest = /*#__PURE__*/function () { + function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) { + _classCallCheck(this, OutgoingRequest); + + // Mandatory parameters check. + if (!method || !ruri || !ua) { + return null; + } + + params = params || {}; + this.ua = ua; + this.headers = {}; + this.method = method; + this.ruri = ruri; + this.body = body; + this.extraHeaders = Utils.cloneArray(extraHeaders); // Fill the Common SIP Request Headers. + // Route. + + if (params.route_set) { + this.setHeader('route', params.route_set); + } else if (ua.configuration.use_preloaded_route) { + this.setHeader('route', "<".concat(ua.transport.sip_uri, ";lr>")); + } // Via. + // Empty Via header. Will be filled by the client transaction. + + + this.setHeader('via', ''); // Max-Forwards. + + this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS); // To + + var to_uri = params.to_uri || ruri; + var to_params = params.to_tag ? { + tag: params.to_tag + } : null; + var to_display_name = typeof params.to_display_name !== 'undefined' ? params.to_display_name : null; + this.to = new NameAddrHeader(to_uri, to_display_name, to_params); + this.setHeader('to', this.to.toString()); // From. + + var from_uri = params.from_uri || ua.configuration.uri; + var from_params = { + tag: params.from_tag || Utils.newTag() + }; + var display_name; + + if (typeof params.from_display_name !== 'undefined') { + display_name = params.from_display_name; + } else if (ua.configuration.display_name) { + display_name = ua.configuration.display_name; + } else { + display_name = null; + } + + this.from = new NameAddrHeader(from_uri, display_name, from_params); + this.setHeader('from', this.from.toString()); // Call-ID. + + var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15); + this.call_id = call_id; + this.setHeader('call-id', call_id); // CSeq. + + var cseq = params.cseq || Math.floor(Math.random() * 10000); + this.cseq = cseq; + this.setHeader('cseq', "".concat(cseq, " ").concat(method)); + } + /** + * Replace the the given header by the given value. + * -param {String} name header name + * -param {String | Array} value header value + */ + + + _createClass(OutgoingRequest, [{ + key: "setHeader", + value: function setHeader(name, value) { + // Remove the header from extraHeaders if present. + var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); + + for (var idx = 0; idx < this.extraHeaders.length; idx++) { + if (regexp.test(this.extraHeaders[idx])) { + this.extraHeaders.splice(idx, 1); + } + } + + this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value]; + } + /** + * Get the value of the given header name at the given position. + * -param {String} name header name + * -returns {String|undefined} Returns the specified header, null if header doesn't exist. + */ + + }, { + key: "getHeader", + value: function getHeader(name) { + var headers = this.headers[Utils.headerize(name)]; + + if (headers) { + if (headers[0]) { + return headers[0]; + } + } else { + var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); + + var _iterator = _createForOfIteratorHelper(this.extraHeaders), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var header = _step.value; + + if (regexp.test(header)) { + return header.substring(header.indexOf(':') + 1).trim(); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + + return; + } + /** + * Get the header/s of the given name. + * -param {String} name header name + * -returns {Array} Array with all the headers of the specified name. + */ + + }, { + key: "getHeaders", + value: function getHeaders(name) { + var headers = this.headers[Utils.headerize(name)]; + var result = []; + + if (headers) { + var _iterator2 = _createForOfIteratorHelper(headers), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var header = _step2.value; + result.push(header); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + + return result; + } else { + var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); + + var _iterator3 = _createForOfIteratorHelper(this.extraHeaders), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _header = _step3.value; + + if (regexp.test(_header)) { + result.push(_header.substring(_header.indexOf(':') + 1).trim()); + } + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + + return result; + } + } + /** + * Verify the existence of the given header. + * -param {String} name header name + * -returns {boolean} true if header with given name exists, false otherwise + */ + + }, { + key: "hasHeader", + value: function hasHeader(name) { + if (this.headers[Utils.headerize(name)]) { + return true; + } else { + var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i'); + + var _iterator4 = _createForOfIteratorHelper(this.extraHeaders), + _step4; + + try { + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + var header = _step4.value; + + if (regexp.test(header)) { + return true; + } + } + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); + } + } + + return false; + } + /** + * Parse the current body as a SDP and store the resulting object + * into this.sdp. + * -param {Boolean} force: Parse even if this.sdp already exists. + * + * Returns this.sdp. + */ + + }, { + key: "parseSDP", + value: function parseSDP(force) { + if (!force && this.sdp) { + return this.sdp; + } else { + this.sdp = sdp_transform.parse(this.body || ''); + return this.sdp; + } + } + }, { + key: "toString", + value: function toString() { + var msg = "".concat(this.method, " ").concat(this.ruri, " SIP/2.0\r\n"); + + for (var headerName in this.headers) { + if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) { + var _iterator5 = _createForOfIteratorHelper(this.headers[headerName]), + _step5; + + try { + for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { + var headerValue = _step5.value; + msg += "".concat(headerName, ": ").concat(headerValue, "\r\n"); + } + } catch (err) { + _iterator5.e(err); + } finally { + _iterator5.f(); + } + } + } + + var _iterator6 = _createForOfIteratorHelper(this.extraHeaders), + _step6; + + try { + for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { + var header = _step6.value; + msg += "".concat(header.trim(), "\r\n"); + } // Supported. + + } catch (err) { + _iterator6.e(err); + } finally { + _iterator6.f(); + } + + var supported = []; + + switch (this.method) { + case JsSIP_C.REGISTER: + supported.push('path', 'gruu'); + break; + + case JsSIP_C.INVITE: + if (this.ua.configuration.session_timers) { + supported.push('timer'); + } + + if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) { + supported.push('gruu'); + } + + supported.push('ice', 'replaces'); + break; + + case JsSIP_C.UPDATE: + if (this.ua.configuration.session_timers) { + supported.push('timer'); + } + + supported.push('ice'); + break; + } + + supported.push('outbound'); + var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT; // Allow. + + msg += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); + msg += "Supported: ".concat(supported, "\r\n"); + msg += "User-Agent: ".concat(userAgent, "\r\n"); + + if (this.body) { + var length = Utils.str_utf8_length(this.body); + msg += "Content-Length: ".concat(length, "\r\n\r\n"); + msg += this.body; + } else { + msg += 'Content-Length: 0\r\n\r\n'; + } + + return msg; + } + }, { + key: "clone", + value: function clone() { + var request = new OutgoingRequest(this.method, this.ruri, this.ua); + Object.keys(this.headers).forEach(function (name) { + request.headers[name] = this.headers[name].slice(); + }, this); + request.body = this.body; + request.extraHeaders = Utils.cloneArray(this.extraHeaders); + request.to = this.to; + request.from = this.from; + request.call_id = this.call_id; + request.cseq = this.cseq; + return request; + } + }]); + + return OutgoingRequest; +}(); + +var InitialOutgoingInviteRequest = /*#__PURE__*/function (_OutgoingRequest) { + _inherits(InitialOutgoingInviteRequest, _OutgoingRequest); + + var _super = _createSuper(InitialOutgoingInviteRequest); + + function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) { + var _this; + + _classCallCheck(this, InitialOutgoingInviteRequest); + + _this = _super.call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body); + _this.transaction = null; + return _this; + } + + _createClass(InitialOutgoingInviteRequest, [{ + key: "cancel", + value: function cancel(reason) { + this.transaction.cancel(reason); + } + }, { + key: "clone", + value: function clone() { + var request = new InitialOutgoingInviteRequest(this.ruri, this.ua); + Object.keys(this.headers).forEach(function (name) { + request.headers[name] = this.headers[name].slice(); + }, this); + request.body = this.body; + request.extraHeaders = Utils.cloneArray(this.extraHeaders); + request.to = this.to; + request.from = this.from; + request.call_id = this.call_id; + request.cseq = this.cseq; + request.transaction = this.transaction; + return request; + } + }]); + + return InitialOutgoingInviteRequest; +}(OutgoingRequest); + +var IncomingMessage = /*#__PURE__*/function () { + function IncomingMessage() { + _classCallCheck(this, IncomingMessage); + + 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; + } + /** + * Insert a header of the given name and value into the last position of the + * header array. + */ + + + _createClass(IncomingMessage, [{ + key: "addHeader", + value: function addHeader(name, value) { + var header = { + raw: value + }; + name = Utils.headerize(name); + + if (this.headers[name]) { + this.headers[name].push(header); + } else { + this.headers[name] = [header]; + } + } + /** + * Get the value of the given header name at the given position. + */ + + }, { + key: "getHeader", + value: function getHeader(name) { + var header = this.headers[Utils.headerize(name)]; + + if (header) { + if (header[0]) { + return header[0].raw; + } + } else { + return; + } + } + /** + * Get the header/s of the given name. + */ + + }, { + key: "getHeaders", + value: function getHeaders(name) { + var headers = this.headers[Utils.headerize(name)]; + var result = []; + + if (!headers) { + return []; + } + + var _iterator7 = _createForOfIteratorHelper(headers), + _step7; + + try { + for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { + var header = _step7.value; + result.push(header.raw); + } + } catch (err) { + _iterator7.e(err); + } finally { + _iterator7.f(); + } + + return result; + } + /** + * Verify the existence of the given header. + */ + + }, { + key: "hasHeader", + value: function hasHeader(name) { + return this.headers[Utils.headerize(name)] ? true : false; + } + /** + * Parse the given header on the given index. + * -param {String} name header name + * -param {Number} [idx=0] header index + * -returns {Object|undefined} Parsed header object, undefined if the header + * is not present or in case of a parsing error. + */ + + }, { + key: "parseHeader", + value: function parseHeader(name) { + var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + name = Utils.headerize(name); + + if (!this.headers[name]) { + debug("header \"".concat(name, "\" not present")); + return; + } else if (idx >= this.headers[name].length) { + debug("not so many \"".concat(name, "\" headers present")); + return; + } + + var header = this.headers[name][idx]; + var value = header.raw; + + if (header.parsed) { + return header.parsed; + } // Substitute '-' by '_' for grammar rule matching. + + + var parsed = Grammar.parse(value, name.replace(/-/g, '_')); + + if (parsed === -1) { + this.headers[name].splice(idx, 1); // delete from headers + + debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); + return; + } else { + header.parsed = parsed; + return parsed; + } + } + /** + * Message Header attribute selector. Alias of parseHeader. + * -param {String} name header name + * -param {Number} [idx=0] header index + * -returns {Object|undefined} Parsed header object, undefined if the header + * is not present or in case of a parsing error. + * + * -example + * message.s('via',3).port + */ + + }, { + key: "s", + value: function s(name, idx) { + return this.parseHeader(name, idx); + } + /** + * Replace the value of the given header by the value. + * -param {String} name header name + * -param {String} value header value + */ + + }, { + key: "setHeader", + value: function setHeader(name, value) { + var header = { + raw: value + }; + this.headers[Utils.headerize(name)] = [header]; + } + /** + * Parse the current body as a SDP and store the resulting object + * into this.sdp. + * -param {Boolean} force: Parse even if this.sdp already exists. + * + * Returns this.sdp. + */ + + }, { + key: "parseSDP", + value: function parseSDP(force) { + if (!force && this.sdp) { + return this.sdp; + } else { + this.sdp = sdp_transform.parse(this.body || ''); + return this.sdp; + } + } + }, { + key: "toString", + value: function toString() { + return this.data; + } + }]); + + return IncomingMessage; +}(); + +var IncomingRequest = /*#__PURE__*/function (_IncomingMessage) { + _inherits(IncomingRequest, _IncomingMessage); + + var _super2 = _createSuper(IncomingRequest); + + function IncomingRequest(ua) { + var _this2; + + _classCallCheck(this, IncomingRequest); + + _this2 = _super2.call(this); + _this2.ua = ua; + _this2.headers = {}; + _this2.ruri = null; + _this2.transport = null; + _this2.server_transaction = null; + return _this2; + } + /** + * Stateful reply. + * -param {Number} code status code + * -param {String} reason reason phrase + * -param {Object} headers extra headers + * -param {String} body body + * -param {Function} [onSuccess] onSuccess callback + * -param {Function} [onFailure] onFailure callback + */ + + + _createClass(IncomingRequest, [{ + key: "reply", + value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) { + var supported = []; + var to = this.getHeader('To'); + code = code || null; + reason = reason || null; // Validate code and reason values. + + if (!code || code < 100 || code > 699) { + throw new TypeError("Invalid status_code: ".concat(code)); + } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { + throw new TypeError("Invalid reason_phrase: ".concat(reason)); + } + + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + extraHeaders = Utils.cloneArray(extraHeaders); + var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); + + if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) { + var headers = this.getHeaders('record-route'); + + var _iterator8 = _createForOfIteratorHelper(headers), + _step8; + + try { + for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { + var header = _step8.value; + response += "Record-Route: ".concat(header, "\r\n"); + } + } catch (err) { + _iterator8.e(err); + } finally { + _iterator8.f(); + } + } + + var vias = this.getHeaders('via'); + + var _iterator9 = _createForOfIteratorHelper(vias), + _step9; + + try { + for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { + var via = _step9.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator9.e(err); + } finally { + _iterator9.f(); + } + + if (!this.to_tag && code > 100) { + to += ";tag=".concat(Utils.newTag()); + } else if (this.to_tag && !this.s('to').hasParam('tag')) { + to += ";tag=".concat(this.to_tag); + } + + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(this.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(this.call_id, "\r\n"); + response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); + + var _iterator10 = _createForOfIteratorHelper(extraHeaders), + _step10; + + try { + for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { + var _header2 = _step10.value; + response += "".concat(_header2.trim(), "\r\n"); + } // Supported. + + } catch (err) { + _iterator10.e(err); + } finally { + _iterator10.f(); + } + + switch (this.method) { + case JsSIP_C.INVITE: + if (this.ua.configuration.session_timers) { + supported.push('timer'); + } + + if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) { + supported.push('gruu'); + } + + supported.push('ice', 'replaces'); + break; + + case JsSIP_C.UPDATE: + if (this.ua.configuration.session_timers) { + supported.push('timer'); + } + + if (body) { + supported.push('ice'); + } + + supported.push('replaces'); + } + + supported.push('outbound'); // Allow and Accept. + + if (this.method === JsSIP_C.OPTIONS) { + response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); + response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n"); + } else if (code === 405) { + response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n"); + } else if (code === 415) { + response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n"); + } + + response += "Supported: ".concat(supported, "\r\n"); + + if (body) { + var length = Utils.str_utf8_length(body); + response += 'Content-Type: application/sdp\r\n'; + response += "Content-Length: ".concat(length, "\r\n\r\n"); + response += body; + } else { + response += "Content-Length: ".concat(0, "\r\n\r\n"); + } + + this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); + } + /** + * Stateless reply. + * -param {Number} code status code + * -param {String} reason reason phrase + */ + + }, { + key: "reply_sl", + value: function reply_sl() { + var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var vias = this.getHeaders('via'); // Validate code and reason values. + + if (!code || code < 100 || code > 699) { + throw new TypeError("Invalid status_code: ".concat(code)); + } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { + throw new TypeError("Invalid reason_phrase: ".concat(reason)); + } + + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); + + var _iterator11 = _createForOfIteratorHelper(vias), + _step11; + + try { + for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { + var via = _step11.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator11.e(err); + } finally { + _iterator11.f(); + } + + var to = this.getHeader('To'); + + if (!this.to_tag && code > 100) { + to += ";tag=".concat(Utils.newTag()); + } else if (this.to_tag && !this.s('to').hasParam('tag')) { + to += ";tag=".concat(this.to_tag); + } + + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(this.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(this.call_id, "\r\n"); + response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); + response += "Content-Length: ".concat(0, "\r\n\r\n"); + this.transport.send(response); + } + }]); + + return IncomingRequest; +}(IncomingMessage); + +var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { + _inherits(IncomingResponse, _IncomingMessage2); + + var _super3 = _createSuper(IncomingResponse); + + function IncomingResponse() { + var _this3; + + _classCallCheck(this, IncomingResponse); + + _this3 = _super3.call(this); + _this3.headers = {}; + _this3.status_code = null; + _this3.reason_phrase = null; + return _this3; + } + + return IncomingResponse; +}(IncomingMessage); + +module.exports = { + OutgoingRequest: OutgoingRequest, + InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, + IncomingRequest: IncomingRequest, + IncomingResponse: IncomingResponse +}; +},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,"debug":32,"sdp-transform":37}],21:[function(require,module,exports){ +"use strict"; + +var Utils = require('./Utils'); + +var Grammar = require('./Grammar'); + +var debugerror = require('debug')('JsSIP:ERROR:Socket'); + +debugerror.log = console.warn.bind(console); +/** + * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ + * + * interface Socket { + * attribute String via_transport + * attribute String url + * attribute String sip_uri + * + * method connect(); + * method disconnect(); + * method send(data); + * + * attribute EventHandler onconnect + * attribute EventHandler ondisconnect + * attribute EventHandler ondata + * } + * + */ + +exports.isSocket = function (socket) { + // Ignore if an array is given. + if (Array.isArray(socket)) { + return false; + } + + if (typeof socket === 'undefined') { + debugerror('undefined JsSIP.Socket instance'); + return false; + } // Check Properties. + + + try { + if (!Utils.isString(socket.url)) { + debugerror('missing or invalid JsSIP.Socket url property'); + throw new Error(); + } + + if (!Utils.isString(socket.via_transport)) { + debugerror('missing or invalid JsSIP.Socket via_transport property'); + throw new Error(); + } + + if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { + debugerror('missing or invalid JsSIP.Socket sip_uri property'); + throw new Error(); + } + } catch (e) { + return false; + } // Check Methods. + + + try { + ['connect', 'disconnect', 'send'].forEach(function (method) { + if (!Utils.isFunction(socket[method])) { + debugerror("missing or invalid JsSIP.Socket method: ".concat(method)); + throw new Error(); + } + }); + } catch (e) { + return false; + } + + return true; +}; +},{"./Grammar":7,"./Utils":28,"debug":32}],22:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:Subscriber'); + +var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); + +debugerror.log = console.warn.bind(console); + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Subscriber, _EventEmitter); + + var _super = _createSuper(Subscriber); + + function Subscriber(ua, target, _ref) { + var _this; + + var event_name = _ref.event_name, + accept = _ref.accept, + expires = _ref.expires, + content_type = _ref.content_type, + allow_events = _ref.allow_events, + params = _ref.params, + headers = _ref.headers, + credential = _ref.credential; + + _classCallCheck(this, Subscriber); + + debug('new'); + _this = _super.call(this); + _this._ua = ua; + + if (!target) { + throw new TypeError('target is undefined'); + } + + _this.target = target; + + if (!event_name) { + throw new TypeError('event_name is undefined'); + } + + _this.event_name = event_name; + + if (!accept) { + throw new TypeError('accept is undefined'); + } + + _this.accept = accept; + + if (!expires) { + expires = 900; + } + + _this.expires = expires; + _this.allow_events = allow_events; // used to subscribe with body + + _this.content_type = content_type; + + if (!params) { + throw new TypeError('params is undefined'); + } + + if (!params.from_uri) { + throw new TypeError('params.from_uri is undefined'); + } + + if (!params.to_uri) { + throw new TypeError('params.to_uri is undefined'); + } + + _this.params = params; + params.from_tag = Utils.newTag(); + params.to_tag = null; + params.call_id = Utils.createRandomToken(20); + params.cseq = Math.floor(Math.random() * 10000 + 1); + _this.contact = ""); // this.contact = ``; + // Optional, used if credential is different from REGISTER/INVITE + + _this.credential = credential; // dialog state: init, notify_wait, pending, active, terminated + + _this._state = 'init'; // dialog id + + _this.id = null; // to refresh subscription + + _this.expires_timer = null; + _this.expires_timestamp = null; + + if (!headers) { + headers = []; + } + + _this.headers = headers.concat(["Event: ".concat(_this.event_name), "Accept: ".concat(_this.accept), "Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); + + if (_this.allowEvents) { + _this.headers.push("Allow-Events: ".concat(_this.allowEvents)); + } + + _this.is_terminated = false; + _this.route_set = null; // Custom session empty object for high level use. + + _this.data = {}; + return _this; + } + /** + * Callbacks + */ + + + _createClass(Subscriber, [{ + key: "onAuthenticated", + value: function onAuthenticated() { + this.params.cseq++; + } + }, { + key: "onRequestTimeout", + value: function onRequestTimeout() { + this._dialogTerminated('subscribe response timeout'); + } + }, { + key: "onTransportError", + value: function onTransportError() { + this._dialogTerminated('subscribe transport error'); + } + }, { + key: "onReceiveResponse", + value: function onReceiveResponse(response) { + if (response.status_code >= 200 && response.status_code < 300) { + if (this.params.to_tag === null) { + this.params.to_tag = response.to_tag; + this.id = "".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag); + debug('added dialog id=', this.id); + + this._ua.newDialog(this); + + this.route_set = response.getHeaders('record-route').reverse(); + + if (this.route_set.length > 0) { + this.params.route_set = this.route_set; + } + } + + var expires = this._getExpires(response); + + if (expires === -1) { + debugerror('response without Expires header'); + return; + } + + if (expires > 0) { + this.expires_timestamp = new Date().getTime() + expires * 1000; + + this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + } + } else if (response.status_code >= 300) { + this._dialogTerminated('receive subscribe non-OK response'); + } + } + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + if (request.method !== JsSIP_C.NOTIFY) { + request.reply(405); + return; + } + + var subs_state = request.parseHeader('subscription-state'); + + if (!subs_state) { + debugerror('missed header Subscription-State'); + request.reply(400); + return; + } + + request.reply(200); + var new_state = subs_state.state.toLowerCase(); + var prev_state = this._state; + + if (prev_state !== 'terminated' && new_state !== 'terminated') { + this._state = new_state; + + if (subs_state.expires !== undefined) { + var expires = subs_state.expires; + var expires_timestamp = new Date().getTime() + expires * 1000; + var max_time_deviation = 2000; // expiration time is shorter and the difference is not too small + + if (this.expires_timestamp - expires_timestamp > max_time_deviation) { + debug('update sending re-SUBSCRIBE time'); + clearTimeout(this.expires_timer); + this.expires_timestamp = expires_timestamp; + + this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + } + } + } + + if (prev_state !== 'active' && new_state === 'active') { + debug('emit "active"'); + this.emit('active'); + } + + var body = request.body; + var is_final = new_state === 'terminated'; // notify event fired for NOTIFY with body + + if (body) { + var content_type = request.getHeader('content-type'); + debug('emit "notify"'); + this.emit('notify', is_final, request, body, content_type); + } + + if (is_final) { + this._dialogTerminated('receive final notify'); + } + } + /** + * User API + */ + + }, { + key: "subscribe", + value: function subscribe() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + debug('subscribe()'); + + if (this._state === 'init') { + this._state = 'notify_wait'; + } + + var headers = this.headers.slice(); + + if (body) { + if (!this.content_type) { + throw new TypeError('content_type is undefined'); + } + + headers.push("Content-Type: ".concat(this.content_type)); + } + + this._send(body, headers); + } + }, { + key: "unsubscribe", + value: function unsubscribe() { + debug('unsubscribe()'); + + this._dialogTerminated('send un-subscribe'); + + var headers = ["Event: ".concat(this.event_name), 'Expires: 0']; + + this._send(null, headers); + } + }, { + key: "state", + get: function get() { + return this._state; + } + /** + * Private API. + */ + + }, { + key: "_dialogTerminated", + value: function _dialogTerminated(reason) { + var _this2 = this; + + // to prevent duplicate emit terminated + if (this.is_terminated) { + return; + } + + this.is_terminated = true; + this._state = 'terminated'; + clearTimeout(this.expires_timer); // remove dialog from dialogs table with some delay, to allow receiving final NOTIFY + + setTimeout(function () { + debug('removed dialog id=', _this2.id); + + _this2._ua.destroyDialog(_this2); + }, 32000); + debug("emit \"terminated\" ".concat(reason, "\"")); + this.emit('terminated', reason); + } + }, { + key: "_send", + value: function _send(body, headers) { + this.params.cseq++; + + this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this.target, this.params, headers, body, this, this.credential); + } + }, { + key: "_getExpires", + value: function _getExpires(r) { + var e = r.getHeader('expires'); + return e ? parseInt(e) : -1; + } + }, { + key: "_calculateTimeoutMs", + value: function _calculateTimeoutMs(expires) { + return expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; + } + }, { + key: "_scheduleSubscribe", + value: function _scheduleSubscribe(timeout) { + var _this3 = this; + + debug("next SUBSCRIBE will be sent in ".concat(Math.floor(timeout / 1000), " sec")); + this.expires_timer = setTimeout(function () { + _this3.expires_timer = undefined; + + _this3._send(null, _this3.headers); + }, timeout); + } + }]); + + return Subscriber; +}(EventEmitter); +},{"./Constants":2,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ +"use strict"; + +var T1 = 500, + T2 = 4000, + T4 = 5000; +module.exports = { + T1: T1, + T2: T2, + T4: T4, + TIMER_B: 64 * T1, + TIMER_D: 0 * T1, + TIMER_F: 64 * T1, + TIMER_H: 64 * T1, + TIMER_I: 0 * T1, + TIMER_J: 0 * T1, + TIMER_K: 0 * T4, + TIMER_L: 64 * T1, + TIMER_M: 64 * T1, + PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 + +}; +},{}],24:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var SIPMessage = require('./SIPMessage'); + +var Timers = require('./Timers'); + +var debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); + +var debugict = require('debug')('JsSIP:InviteClientTransaction'); + +var debugact = require('debug')('JsSIP:AckClientTransaction'); + +var debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); + +var debugist = require('debug')('JsSIP:InviteServerTransaction'); + +var C = { + // Transaction states. + STATUS_TRYING: 1, + STATUS_PROCEEDING: 2, + STATUS_CALLING: 3, + STATUS_ACCEPTED: 4, + STATUS_COMPLETED: 5, + STATUS_TERMINATED: 6, + STATUS_CONFIRMED: 7, + // Transaction types. + NON_INVITE_CLIENT: 'nict', + NON_INVITE_SERVER: 'nist', + INVITE_CLIENT: 'ict', + INVITE_SERVER: 'ist' +}; + +var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { + _inherits(NonInviteClientTransaction, _EventEmitter); + + var _super = _createSuper(NonInviteClientTransaction); + + function NonInviteClientTransaction(ua, transport, request, eventHandlers) { + var _this; + + _classCallCheck(this, NonInviteClientTransaction); + + _this = _super.call(this); + _this.type = C.NON_INVITE_CLIENT; + _this.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); + _this.ua = ua; + _this.transport = transport; + _this.request = request; + _this.eventHandlers = eventHandlers; + var via = "SIP/2.0/".concat(transport.via_transport); + via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this.id); + + _this.request.setHeader('via', via); + + _this.ua.newTransaction(_assertThisInitialized(_this)); + + return _this; + } + + _createClass(NonInviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "stateChanged", + value: function stateChanged(state) { + this.state = state; + this.emit('stateChanged'); + } + }, { + key: "send", + value: function send() { + var _this2 = this; + + this.stateChanged(C.STATUS_TRYING); + this.F = setTimeout(function () { + _this2.timer_F(); + }, Timers.TIMER_F); + + if (!this.transport.send(this.request)) { + this.onTransportError(); + } + } + }, { + key: "onTransportError", + value: function onTransportError() { + debugnict("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 timer_F() { + debugnict("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 timer_K() { + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + }, { + key: "receiveResponse", + value: function receiveResponse(response) { + var _this3 = this; + + var status_code = response.status_code; + + if (status_code < 200) { + switch (this.state) { + case C.STATUS_TRYING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_PROCEEDING); + this.eventHandlers.onReceiveResponse(response); + break; + } + } else { + switch (this.state) { + case C.STATUS_TRYING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_COMPLETED); + clearTimeout(this.F); + + if (status_code === 408) { + this.eventHandlers.onRequestTimeout(); + } else { + this.eventHandlers.onReceiveResponse(response); + } + + this.K = setTimeout(function () { + _this3.timer_K(); + }, Timers.TIMER_K); + break; + + case C.STATUS_COMPLETED: + break; + } + } + } + }]); + + return NonInviteClientTransaction; +}(EventEmitter); + +var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { + _inherits(InviteClientTransaction, _EventEmitter2); + + var _super2 = _createSuper(InviteClientTransaction); + + function InviteClientTransaction(ua, transport, request, eventHandlers) { + var _this4; + + _classCallCheck(this, InviteClientTransaction); + + _this4 = _super2.call(this); + _this4.type = C.INVITE_CLIENT; + _this4.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); + _this4.ua = ua; + _this4.transport = transport; + _this4.request = request; + _this4.eventHandlers = eventHandlers; + request.transaction = _assertThisInitialized(_this4); + var via = "SIP/2.0/".concat(transport.via_transport); + via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this4.id); + + _this4.request.setHeader('via', via); + + _this4.ua.newTransaction(_assertThisInitialized(_this4)); + + return _this4; + } + + _createClass(InviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "stateChanged", + value: function stateChanged(state) { + this.state = state; + this.emit('stateChanged'); + } + }, { + key: "send", + value: function send() { + var _this5 = this; + + this.stateChanged(C.STATUS_CALLING); + this.B = setTimeout(function () { + _this5.timer_B(); + }, Timers.TIMER_B); + + if (!this.transport.send(this.request)) { + this.onTransportError(); + } + } + }, { + key: "onTransportError", + value: function onTransportError() { + clearTimeout(this.B); + clearTimeout(this.D); + clearTimeout(this.M); + + if (this.state !== C.STATUS_ACCEPTED) { + debugict("transport error occurred, deleting transaction ".concat(this.id)); + this.eventHandlers.onTransportError(); + } + + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } // RFC 6026 7.2. + + }, { + key: "timer_M", + value: function timer_M() { + debugict("Timer M expired for transaction ".concat(this.id)); + + if (this.state === C.STATUS_ACCEPTED) { + clearTimeout(this.B); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + } // RFC 3261 17.1.1. + + }, { + key: "timer_B", + value: function timer_B() { + debugict("Timer B expired for transaction ".concat(this.id)); + + if (this.state === C.STATUS_CALLING) { + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + this.eventHandlers.onRequestTimeout(); + } + } + }, { + key: "timer_D", + value: function timer_D() { + debugict("Timer D expired for transaction ".concat(this.id)); + clearTimeout(this.B); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + }, { + key: "sendACK", + value: function sendACK(response) { + var _this6 = this; + + var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, { + 'route_set': this.request.getHeaders('route'), + 'call_id': this.request.getHeader('call-id'), + 'cseq': this.request.cseq + }); + ack.setHeader('from', this.request.getHeader('from')); + ack.setHeader('via', this.request.getHeader('via')); + ack.setHeader('to', response.getHeader('to')); + this.D = setTimeout(function () { + _this6.timer_D(); + }, Timers.TIMER_D); + this.transport.send(ack); + } + }, { + key: "cancel", + value: function cancel(reason) { + // Send only if a provisional response (>100) has been received. + if (this.state !== C.STATUS_PROCEEDING) { + return; + } + + var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, { + 'route_set': this.request.getHeaders('route'), + 'call_id': this.request.getHeader('call-id'), + 'cseq': this.request.cseq + }); + cancel.setHeader('from', this.request.getHeader('from')); + cancel.setHeader('via', this.request.getHeader('via')); + cancel.setHeader('to', this.request.getHeader('to')); + + if (reason) { + cancel.setHeader('reason', reason); + } + + this.transport.send(cancel); + } + }, { + key: "receiveResponse", + value: function receiveResponse(response) { + var _this7 = this; + + var status_code = response.status_code; + + if (status_code >= 100 && status_code <= 199) { + switch (this.state) { + case C.STATUS_CALLING: + this.stateChanged(C.STATUS_PROCEEDING); + this.eventHandlers.onReceiveResponse(response); + break; + + case C.STATUS_PROCEEDING: + this.eventHandlers.onReceiveResponse(response); + break; + } + } else if (status_code >= 200 && status_code <= 299) { + switch (this.state) { + case C.STATUS_CALLING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_ACCEPTED); + this.M = setTimeout(function () { + _this7.timer_M(); + }, Timers.TIMER_M); + this.eventHandlers.onReceiveResponse(response); + break; + + case C.STATUS_ACCEPTED: + this.eventHandlers.onReceiveResponse(response); + break; + } + } else if (status_code >= 300 && status_code <= 699) { + switch (this.state) { + case C.STATUS_CALLING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_COMPLETED); + this.sendACK(response); + this.eventHandlers.onReceiveResponse(response); + break; + + case C.STATUS_COMPLETED: + this.sendACK(response); + break; + } + } + } + }]); + + return InviteClientTransaction; +}(EventEmitter); + +var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { + _inherits(AckClientTransaction, _EventEmitter3); + + var _super3 = _createSuper(AckClientTransaction); + + function AckClientTransaction(ua, transport, request, eventHandlers) { + var _this8; + + _classCallCheck(this, AckClientTransaction); + + _this8 = _super3.call(this); + _this8.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000)); + _this8.transport = transport; + _this8.request = request; + _this8.eventHandlers = eventHandlers; + var via = "SIP/2.0/".concat(transport.via_transport); + via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this8.id); + + _this8.request.setHeader('via', via); + + return _this8; + } + + _createClass(AckClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "send", + value: function send() { + if (!this.transport.send(this.request)) { + this.onTransportError(); + } + } + }, { + key: "onTransportError", + value: function onTransportError() { + debugact("transport error occurred for transaction ".concat(this.id)); + this.eventHandlers.onTransportError(); + } + }]); + + return AckClientTransaction; +}(EventEmitter); + +var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { + _inherits(NonInviteServerTransaction, _EventEmitter4); + + var _super4 = _createSuper(NonInviteServerTransaction); + + function NonInviteServerTransaction(ua, transport, request) { + var _this9; + + _classCallCheck(this, NonInviteServerTransaction); + + _this9 = _super4.call(this); + _this9.type = C.NON_INVITE_SERVER; + _this9.id = request.via_branch; + _this9.ua = ua; + _this9.transport = transport; + _this9.request = request; + _this9.last_response = ''; + request.server_transaction = _assertThisInitialized(_this9); + _this9.state = C.STATUS_TRYING; + ua.newTransaction(_assertThisInitialized(_this9)); + return _this9; + } + + _createClass(NonInviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "stateChanged", + value: function stateChanged(state) { + this.state = state; + this.emit('stateChanged'); + } + }, { + key: "timer_J", + value: function timer_J() { + debugnist("Timer J expired for transaction ".concat(this.id)); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + }, { + key: "onTransportError", + value: function onTransportError() { + if (!this.transportError) { + this.transportError = true; + debugnist("transport error occurred, deleting transaction ".concat(this.id)); + clearTimeout(this.J); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + } + }, { + key: "receiveResponse", + value: function receiveResponse(status_code, response, onSuccess, onFailure) { + var _this10 = this; + + if (status_code === 100) { + /* RFC 4320 4.1 + * 'A SIP element MUST NOT + * send any provisional response with a + * Status-Code other than 100 to a non-INVITE request.' + */ + switch (this.state) { + case C.STATUS_TRYING: + this.stateChanged(C.STATUS_PROCEEDING); + + if (!this.transport.send(response)) { + this.onTransportError(); + } + + break; + + case C.STATUS_PROCEEDING: + this.last_response = response; + + if (!this.transport.send(response)) { + this.onTransportError(); + + if (onFailure) { + onFailure(); + } + } else if (onSuccess) { + onSuccess(); + } + + break; + } + } else if (status_code >= 200 && status_code <= 699) { + switch (this.state) { + case C.STATUS_TRYING: + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_COMPLETED); + this.last_response = response; + this.J = setTimeout(function () { + _this10.timer_J(); + }, Timers.TIMER_J); + + if (!this.transport.send(response)) { + this.onTransportError(); + + if (onFailure) { + onFailure(); + } + } else if (onSuccess) { + onSuccess(); + } + + break; + + case C.STATUS_COMPLETED: + break; + } + } + } + }]); + + return NonInviteServerTransaction; +}(EventEmitter); + +var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { + _inherits(InviteServerTransaction, _EventEmitter5); + + var _super5 = _createSuper(InviteServerTransaction); + + function InviteServerTransaction(ua, transport, request) { + var _this11; + + _classCallCheck(this, InviteServerTransaction); + + _this11 = _super5.call(this); + _this11.type = C.INVITE_SERVER; + _this11.id = request.via_branch; + _this11.ua = ua; + _this11.transport = transport; + _this11.request = request; + _this11.last_response = ''; + request.server_transaction = _assertThisInitialized(_this11); + _this11.state = C.STATUS_PROCEEDING; + ua.newTransaction(_assertThisInitialized(_this11)); + _this11.resendProvisionalTimer = null; + request.reply(100); + return _this11; + } + + _createClass(InviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "stateChanged", + value: function stateChanged(state) { + this.state = state; + this.emit('stateChanged'); + } + }, { + key: "timer_H", + value: function timer_H() { + debugist("Timer H expired for transaction ".concat(this.id)); + + if (this.state === C.STATUS_COMPLETED) { + debugist('ACK not received, dialog will be terminated'); + } + + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + }, { + key: "timer_I", + value: function timer_I() { + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } // RFC 6026 7.1. + + }, { + key: "timer_L", + value: function timer_L() { + debugist("Timer L expired for transaction ".concat(this.id)); + + if (this.state === C.STATUS_ACCEPTED) { + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + } + }, { + key: "onTransportError", + value: function onTransportError() { + if (!this.transportError) { + this.transportError = true; + debugist("transport error occurred, deleting transaction ".concat(this.id)); + + if (this.resendProvisionalTimer !== null) { + clearInterval(this.resendProvisionalTimer); + this.resendProvisionalTimer = null; + } + + clearTimeout(this.L); + clearTimeout(this.H); + clearTimeout(this.I); + this.stateChanged(C.STATUS_TERMINATED); + this.ua.destroyTransaction(this); + } + } + }, { + key: "resend_provisional", + value: function resend_provisional() { + if (!this.transport.send(this.last_response)) { + this.onTransportError(); + } + } // INVITE Server Transaction RFC 3261 17.2.1. + + }, { + key: "receiveResponse", + value: function receiveResponse(status_code, response, onSuccess, onFailure) { + var _this12 = this; + + if (status_code >= 100 && status_code <= 199) { + switch (this.state) { + case C.STATUS_PROCEEDING: + if (!this.transport.send(response)) { + this.onTransportError(); + } + + this.last_response = response; + break; + } + } + + if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) { + // Trigger the resendProvisionalTimer only for the first non 100 provisional response. + if (this.resendProvisionalTimer === null) { + this.resendProvisionalTimer = setInterval(function () { + _this12.resend_provisional(); + }, Timers.PROVISIONAL_RESPONSE_INTERVAL); + } + } else if (status_code >= 200 && status_code <= 299) { + switch (this.state) { + case C.STATUS_PROCEEDING: + this.stateChanged(C.STATUS_ACCEPTED); + this.last_response = response; + this.L = setTimeout(function () { + _this12.timer_L(); + }, Timers.TIMER_L); + + if (this.resendProvisionalTimer !== null) { + clearInterval(this.resendProvisionalTimer); + this.resendProvisionalTimer = null; + } + + /* falls through */ + + case C.STATUS_ACCEPTED: + // Note that this point will be reached for proceeding this.state also. + if (!this.transport.send(response)) { + this.onTransportError(); + + if (onFailure) { + onFailure(); + } + } else if (onSuccess) { + onSuccess(); + } + + break; + } + } else if (status_code >= 300 && status_code <= 699) { + switch (this.state) { + case C.STATUS_PROCEEDING: + if (this.resendProvisionalTimer !== null) { + clearInterval(this.resendProvisionalTimer); + this.resendProvisionalTimer = null; + } + + if (!this.transport.send(response)) { + this.onTransportError(); + + if (onFailure) { + onFailure(); + } + } else { + this.stateChanged(C.STATUS_COMPLETED); + this.H = setTimeout(function () { + _this12.timer_H(); + }, Timers.TIMER_H); + + if (onSuccess) { + onSuccess(); + } + } + + break; + } + } + } + }]); + + return InviteServerTransaction; +}(EventEmitter); +/** + * INVITE: + * _true_ if retransmission + * _false_ new request + * + * ACK: + * _true_ ACK to non2xx response + * _false_ ACK must be passed to TU (accepted state) + * ACK to 2xx response + * + * CANCEL: + * _true_ no matching invite transaction + * _false_ matching invite transaction and no final response sent + * + * OTHER: + * _true_ retransmission + * _false_ new request + */ + + +function checkTransaction(_ref, request) { + var _transactions = _ref._transactions; + var tr; + + switch (request.method) { + case JsSIP_C.INVITE: + tr = _transactions.ist[request.via_branch]; + + if (tr) { + switch (tr.state) { + case C.STATUS_PROCEEDING: + tr.transport.send(tr.last_response); + break; + // RFC 6026 7.1 Invite retransmission. + // Received while in C.STATUS_ACCEPTED state. Absorb it. + + case C.STATUS_ACCEPTED: + break; + } + + return true; + } + + break; + + case JsSIP_C.ACK: + tr = _transactions.ist[request.via_branch]; // RFC 6026 7.1. + + if (tr) { + if (tr.state === C.STATUS_ACCEPTED) { + return false; + } else if (tr.state === C.STATUS_COMPLETED) { + tr.state = C.STATUS_CONFIRMED; + tr.I = setTimeout(function () { + tr.timer_I(); + }, Timers.TIMER_I); + return true; + } + } // ACK to 2XX Response. + else { + return false; + } + + break; + + case JsSIP_C.CANCEL: + tr = _transactions.ist[request.via_branch]; + + if (tr) { + request.reply_sl(200); + + if (tr.state === C.STATUS_PROCEEDING) { + return false; + } else { + return true; + } + } else { + request.reply_sl(481); + return true; + } + + default: + // Non-INVITE Server Transaction RFC 3261 17.2.2. + tr = _transactions.nist[request.via_branch]; + + if (tr) { + switch (tr.state) { + case C.STATUS_TRYING: + break; + + case C.STATUS_PROCEEDING: + case C.STATUS_COMPLETED: + tr.transport.send(tr.last_response); + break; + } + + return true; + } + + break; + } +} + +module.exports = { + C: C, + NonInviteClientTransaction: NonInviteClientTransaction, + InviteClientTransaction: InviteClientTransaction, + AckClientTransaction: AckClientTransaction, + NonInviteServerTransaction: NonInviteServerTransaction, + InviteServerTransaction: InviteServerTransaction, + checkTransaction: checkTransaction +}; +},{"./Constants":2,"./SIPMessage":20,"./Timers":23,"debug":32,"events":31}],25:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var Socket = require('./Socket'); + +var debug = require('debug')('JsSIP:Transport'); + +var debugerror = require('debug')('JsSIP:ERROR:Transport'); + +var JsSIP_C = require('./Constants'); + +debugerror.log = console.warn.bind(console); +/** + * Constants + */ + +var C = { + // Transport status. + STATUS_CONNECTED: 0, + STATUS_CONNECTING: 1, + STATUS_DISCONNECTED: 2, + // Socket status. + SOCKET_STATUS_READY: 0, + SOCKET_STATUS_ERROR: 1, + // Recovery options. + recovery_options: { + // minimum interval in seconds between recover attempts. + min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL, + // maximum interval in seconds between recover attempts. + max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL + } +}; +/* + * Manages one or multiple JsSIP.Socket instances. + * Is reponsible for transport recovery logic among all socket instances. + * + * @socket JsSIP::Socket instance + */ + +module.exports = /*#__PURE__*/function () { + function Transport(sockets) { + var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options; + + _classCallCheck(this, Transport); + + debug('new()'); + this.status = C.STATUS_DISCONNECTED; // Current socket. + + this.socket = null; // Socket collection. + + this.sockets = []; + this.recovery_options = recovery_options; + this.recover_attempts = 0; + this.recovery_timer = null; + this.close_requested = false; // It seems that TextDecoder is not available in some versions of React-Native. + // See https://github.com/versatica/JsSIP/issues/695 + + try { + this.textDecoder = new TextDecoder('utf8'); + } catch (error) { + debugerror("cannot use TextDecoder: ".concat(error)); + } + + if (typeof sockets === 'undefined') { + throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument'); + } + + if (!(sockets instanceof Array)) { + sockets = [sockets]; + } + + sockets.forEach(function (socket) { + if (!Socket.isSocket(socket.socket)) { + throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance'); + } + + if (socket.weight && !Number(socket.weight)) { + throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number'); + } + + this.sockets.push({ + socket: socket.socket, + weight: socket.weight || 0, + status: C.SOCKET_STATUS_READY + }); + }, this); // Get the socket with higher weight. + + this._getSocket(); + } + /** + * Instance Methods + */ + + + _createClass(Transport, [{ + key: "via_transport", + get: function get() { + return this.socket.via_transport; + } + }, { + key: "url", + get: function get() { + return this.socket.url; + } + }, { + key: "sip_uri", + get: function get() { + return this.socket.sip_uri; + } + }, { + key: "connect", + value: function connect() { + debug('connect()'); + + if (this.isConnected()) { + debug('Transport is already connected'); + return; + } else if (this.isConnecting()) { + debug('Transport is connecting'); + return; + } + + this.close_requested = false; + this.status = C.STATUS_CONNECTING; + this.onconnecting({ + socket: this.socket, + attempts: this.recover_attempts + }); + + if (!this.close_requested) { + // Bind socket event callbacks. + this.socket.onconnect = this._onConnect.bind(this); + this.socket.ondisconnect = this._onDisconnect.bind(this); + this.socket.ondata = this._onData.bind(this); + this.socket.connect(); + } + + return; + } + }, { + key: "disconnect", + value: function disconnect() { + debug('close()'); + this.close_requested = true; + this.recover_attempts = 0; + this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer. + + if (this.recovery_timer !== null) { + clearTimeout(this.recovery_timer); + this.recovery_timer = null; + } // Unbind socket event callbacks. + + + this.socket.onconnect = function () {}; + + this.socket.ondisconnect = function () {}; + + this.socket.ondata = function () {}; + + this.socket.disconnect(); + this.ondisconnect({ + socket: this.socket, + error: false + }); + } + }, { + key: "send", + value: function send(data) { + debug('send()'); + + if (!this.isConnected()) { + debugerror('unable to send message, transport is not connected'); + return false; + } + + var message = data.toString(); + debug("sending message:\n\n".concat(message, "\n")); + return this.socket.send(message); + } + }, { + key: "isConnected", + value: function isConnected() { + return this.status === C.STATUS_CONNECTED; + } + }, { + key: "isConnecting", + value: function isConnecting() { + return this.status === C.STATUS_CONNECTING; + } + /** + * Private API. + */ + + }, { + key: "_reconnect", + value: function _reconnect() { + var _this = this; + + this.recover_attempts += 1; + var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1); + + if (k < this.recovery_options.min_interval) { + k = this.recovery_options.min_interval; + } else if (k > this.recovery_options.max_interval) { + k = this.recovery_options.max_interval; + } + + debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); + this.recovery_timer = setTimeout(function () { + if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) { + // Get the next available socket with higher weight. + _this._getSocket(); // Connect the socket. + + + _this.connect(); + } + }, k * 1000); + } + /** + * get the next available socket with higher weight + */ + + }, { + key: "_getSocket", + value: function _getSocket() { + var candidates = []; + this.sockets.forEach(function (socket) { + if (socket.status === C.SOCKET_STATUS_ERROR) { + return; // continue the array iteration + } else if (candidates.length === 0) { + candidates.push(socket); + } else if (socket.weight > candidates[0].weight) { + candidates = [socket]; + } else if (socket.weight === candidates[0].weight) { + candidates.push(socket); + } + }); + + if (candidates.length === 0) { + // All sockets have failed. reset sockets status. + this.sockets.forEach(function (socket) { + socket.status = C.SOCKET_STATUS_READY; + }); // Get next available socket. + + this._getSocket(); + + return; + } + + var idx = Math.floor(Math.random() * candidates.length); + this.socket = candidates[idx].socket; + } + /** + * Socket Event Handlers + */ + + }, { + key: "_onConnect", + value: function _onConnect() { + this.recover_attempts = 0; + this.status = C.STATUS_CONNECTED; // Clear recovery_timer. + + if (this.recovery_timer !== null) { + clearTimeout(this.recovery_timer); + this.recovery_timer = null; + } + + this.onconnect({ + socket: this + }); + } + }, { + key: "_onDisconnect", + value: function _onDisconnect(error, code, reason) { + this.status = C.STATUS_DISCONNECTED; + this.ondisconnect({ + socket: this.socket, + error: error, + code: code, + reason: reason + }); + + if (this.close_requested) { + return; + } // Update socket status. + else { + this.sockets.forEach(function (socket) { + if (this.socket === socket.socket) { + socket.status = C.SOCKET_STATUS_ERROR; + } + }, this); + } + + this._reconnect(error); + } + }, { + key: "_onData", + value: function _onData(data) { + // CRLF Keep Alive response from server. Ignore it. + if (data === '\r\n') { + debug('received message with CRLF Keep Alive response'); + return; + } // Binary message. + else if (typeof data !== 'string') { + try { + if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data)); + } catch (evt) { + debug('received binary message failed to be converted into string,' + ' message discarded'); + return; + } + + debug("received binary message:\n\n".concat(data, "\n")); + } // Text message. + else { + debug("received text message:\n\n".concat(data, "\n")); + } + + this.ondata({ + transport: this, + message: data + }); + } + }]); + + return Transport; +}(); +},{"./Constants":2,"./Socket":21,"debug":32}],26:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var Registrator = require('./Registrator'); + +var RTCSession = require('./RTCSession'); + +var Subscriber = require('./Subscriber'); + +var Notifier = require('./Notifier'); + +var Message = require('./Message'); + +var Transactions = require('./Transactions'); + +var Transport = require('./Transport'); + +var Utils = require('./Utils'); + +var Exceptions = require('./Exceptions'); + +var URI = require('./URI'); + +var Parser = require('./Parser'); + +var SIPMessage = require('./SIPMessage'); + +var RequestSender = require('./RequestSender'); + +var sanityCheck = require('./sanityCheck'); + +var config = require('./Config'); + +var debug = require('debug')('JsSIP:UA'); + +var debugerror = require('debug')('JsSIP:ERROR:UA'); + +debugerror.log = console.warn.bind(console); +var C = { + // UA status codes. + STATUS_INIT: 0, + STATUS_READY: 1, + STATUS_USER_CLOSED: 2, + STATUS_NOT_READY: 3, + // UA error codes. + CONFIGURATION_ERROR: 1, + NETWORK_ERROR: 2 +}; +/** + * The User-Agent class. + * @class JsSIP.UA + * @param {Object} configuration Configuration parameters. + * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid. + * @throws {TypeError} If no configuration is given. + */ + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(UA, _EventEmitter); + + var _super = _createSuper(UA); + + function UA(configuration) { + var _this; + + _classCallCheck(this, UA); + + debug('new() [configuration:%o]', configuration); + _this = _super.call(this); + _this._cache = { + credentials: {} + }; + _this._configuration = Object.assign({}, config.settings); + _this._dynConfiguration = {}; + _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE). + + _this._applicants = {}; + _this._sessions = {}; + _this._transport = null; + _this._contact = null; + _this._status = C.STATUS_INIT; + _this._error = null; + _this._transactions = { + nist: {}, + nict: {}, + ist: {}, + ict: {} + }; // Custom UA empty object for high level use. + + _this._data = {}; + _this._closeTimer = null; // Check configuration argument. + + if (configuration === undefined) { + throw new TypeError('Not enough arguments'); + } // Load configuration. + + + try { + _this._loadConfig(configuration); + } catch (e) { + _this._status = C.STATUS_NOT_READY; + _this._error = C.CONFIGURATION_ERROR; + throw e; + } // Initialize registrator. + + + _this._registrator = new Registrator(_assertThisInitialized(_this)); + return _this; + } + + _createClass(UA, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "configuration", + get: function get() { + return this._configuration; + } + }, { + key: "transport", + get: function get() { + return this._transport; + } // ================= + // High Level API + // ================= + + /** + * Connect to the server if status = STATUS_INIT. + * Resume UA after being closed. + */ + + }, { + key: "start", + value: function start() { + debug('start()'); + + if (this._status === C.STATUS_INIT) { + this._transport.connect(); + } else if (this._status === C.STATUS_USER_CLOSED) { + debug('restarting UA'); // Disconnect. + + if (this._closeTimer !== null) { + clearTimeout(this._closeTimer); + this._closeTimer = null; + + this._transport.disconnect(); + } // Reconnect. + + + this._status = C.STATUS_INIT; + + this._transport.connect(); + } else if (this._status === C.STATUS_READY) { + debug('UA is in READY status, not restarted'); + } else { + debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); + } // Set dynamic configuration. + + + this._dynConfiguration.register = this._configuration.register; + } + /** + * Register. + */ + + }, { + key: "register", + value: function register() { + debug('register()'); + this._dynConfiguration.register = true; + + this._registrator.register(); + } + /** + * Unregister. + */ + + }, { + key: "unregister", + value: function unregister(options) { + debug('unregister()'); + this._dynConfiguration.register = false; + + this._registrator.unregister(options); + } + /** + * Get the Registrator instance. + */ + + }, { + key: "registrator", + value: function registrator() { + return this._registrator; + } + /** + * Registration state. + */ + + }, { + key: "isRegistered", + value: function isRegistered() { + return this._registrator.registered; + } + /** + * Connection state. + */ + + }, { + key: "isConnected", + value: function isConnected() { + return this._transport.isConnected(); + } + /** + * Make an outgoing call. + * + * -param {String} target + * -param {Object} [options] + * + * -throws {TypeError} + * + */ + + }, { + key: "call", + value: function call(target, options) { + debug('call()'); + var session = new RTCSession(this); + session.connect(target, options); + return session; + } + /** + * Send a message. + * + * -param {String} target + * -param {String} body + * -param {Object} [options] + * + * -throws {TypeError} + * + */ + + }, { + key: "sendMessage", + value: function sendMessage(target, body, options) { + debug('sendMessage()'); + var message = new Message(this); + message.send(target, body, options); + return message; + } + /** + * Arbitrary client transaction + */ + + }, { + key: "sendRequest", + value: function sendRequest(method, target, params, headers, body, handlers, credential) { + debug('sendRequest()'); + var request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); + var requestSender = new RequestSender(this, request, handlers, credential); + requestSender.send(); + } + /** + * Create subscriber + */ + + }, { + key: "subscriber", + value: function subscriber(target, options) { + debug('subscriber()'); + return new Subscriber(this, target, options); + } + /** + * Create notifier + */ + + }, { + key: "notifier", + value: function notifier(options) { + debug('notifier()'); + return new Notifier(this, options); + } + /** + * Terminate ongoing sessions. + */ + + }, { + key: "terminateSessions", + value: function terminateSessions(options) { + debug('terminateSessions()'); + + for (var idx in this._sessions) { + if (!this._sessions[idx].isEnded()) { + this._sessions[idx].terminate(options); + } + } + } + /** + * Gracefully close. + * + */ + + }, { + key: "stop", + value: function stop() { + var _this2 = this; + + debug('stop()'); // Remove dynamic settings. + + this._dynConfiguration = {}; + + if (this._status === C.STATUS_USER_CLOSED) { + debug('UA already closed'); + return; + } // Close registrator. + + + this._registrator.close(); // If there are session wait a bit so CANCEL/BYE can be sent and their responses received. + + + var num_sessions = Object.keys(this._sessions).length; // Run _terminate_ on every Session. + + for (var session in this._sessions) { + if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { + debug("closing session ".concat(session)); + + try { + this._sessions[session].terminate(); + } catch (error) {} + } + } // Run _close_ on every applicant. + + + for (var applicant in this._applicants) { + if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try { + this._applicants[applicant].close(); + } catch (error) {} + } + + this._status = C.STATUS_USER_CLOSED; + var num_transactions = Object.keys(this._transactions.nict).length + Object.keys(this._transactions.nist).length + Object.keys(this._transactions.ict).length + Object.keys(this._transactions.ist).length; + + if (num_transactions === 0 && num_sessions === 0) { + this._transport.disconnect(); + } else { + this._closeTimer = setTimeout(function () { + _this2._closeTimer = null; + + _this2._transport.disconnect(); + }, 2000); + } + } + /** + * Normalice a string into a valid SIP request URI + * -param {String} target + * -returns {JsSIP.URI|undefined} + */ + + }, { + key: "normalizeTarget", + value: function normalizeTarget(target) { + return Utils.normalizeTarget(target, this._configuration.hostport_params); + } + /** + * Allow retrieving configuration and autogenerated fields in runtime. + */ + + }, { + key: "get", + value: function get(parameter) { + switch (parameter) { + case 'authorization_user': + return this._configuration.authorization_user; + + case 'realm': + return this._configuration.realm; + + case 'ha1': + return this._configuration.ha1; + + case 'authorization_jwt': + return this._configuration.authorization_jwt; + + default: + debugerror('get() | cannot get "%s" parameter in runtime', parameter); + return undefined; + } + } + /** + * Allow configuration changes in runtime. + * Returns true if the parameter could be set. + */ + + }, { + key: "set", + value: function set(parameter, value) { + switch (parameter) { + case 'authorization_user': + { + this._configuration.authorization_user = String(value); + break; + } + + case 'password': + { + this._configuration.password = String(value); + break; + } + + case 'realm': + { + this._configuration.realm = String(value); + break; + } + + case 'ha1': + { + this._configuration.ha1 = String(value); // Delete the plain SIP password. + + this._configuration.password = null; + break; + } + + case 'authorization_jwt': + { + this._configuration.authorization_jwt = String(value); + break; + } + + case 'display_name': + { + this._configuration.display_name = value; + break; + } + + default: + debugerror('set() | cannot set "%s" parameter in runtime', parameter); + return false; + } + + return true; + } // ========================== + // Event Handlers. + // ========================== + + /** + * new Transaction + */ + + }, { + key: "newTransaction", + value: function newTransaction(transaction) { + this._transactions[transaction.type][transaction.id] = transaction; + this.emit('newTransaction', { + transaction: transaction + }); + } + /** + * Transaction destroyed. + */ + + }, { + key: "destroyTransaction", + value: function destroyTransaction(transaction) { + delete this._transactions[transaction.type][transaction.id]; + this.emit('transactionDestroyed', { + transaction: transaction + }); + } + /** + * new Dialog + */ + + }, { + key: "newDialog", + value: function newDialog(dialog) { + this._dialogs[dialog.id] = dialog; + } + /** + * Dialog destroyed. + */ + + }, { + key: "destroyDialog", + value: function destroyDialog(dialog) { + delete this._dialogs[dialog.id]; + } + /** + * new Message + */ + + }, { + key: "newMessage", + value: function newMessage(message, data) { + this._applicants[message] = message; + this.emit('newMessage', data); + } + /** + * Message destroyed. + */ + + }, { + key: "destroyMessage", + value: function destroyMessage(message) { + delete this._applicants[message]; + } + /** + * new RTCSession + */ + + }, { + key: "newRTCSession", + value: function newRTCSession(session, data) { + this._sessions[session.id] = session; + this.emit('newRTCSession', data); + } + /** + * RTCSession destroyed. + */ + + }, { + key: "destroyRTCSession", + value: function destroyRTCSession(session) { + delete this._sessions[session.id]; + } + /** + * Registered + */ + + }, { + key: "registered", + value: function registered(data) { + this.emit('registered', data); + } + /** + * Unregistered + */ + + }, { + key: "unregistered", + value: function unregistered(data) { + this.emit('unregistered', data); + } + /** + * Registration Failed + */ + + }, { + key: "registrationFailed", + value: function registrationFailed(data) { + this.emit('registrationFailed', data); + } // ========================= + // ReceiveRequest. + // ========================= + + /** + * Request reception + */ + + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + var method = request.method; // Check that request URI points to us. + + if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { + debug('Request-URI does not point to us'); + + if (request.method !== JsSIP_C.ACK) { + request.reply_sl(404); + } + + return; + } // Check request URI scheme. + + + if (request.ruri.scheme === JsSIP_C.SIPS) { + request.reply_sl(416); + return; + } // Check transaction. + + + if (Transactions.checkTransaction(this, request)) { + return; + } // Create the server transaction. + + + if (method === JsSIP_C.INVITE) { + /* eslint-disable no-new */ + new Transactions.InviteServerTransaction(this, this._transport, request); + /* eslint-enable no-new */ + } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) { + /* eslint-disable no-new */ + new Transactions.NonInviteServerTransaction(this, this._transport, request); + /* eslint-enable no-new */ + } + /* RFC3261 12.2.2 + * Requests that do not change in any way the state of a dialog may be + * received within a dialog (for example, an OPTIONS request). + * They are processed as if they had been received outside the dialog. + */ + + + if (method === JsSIP_C.OPTIONS) { + request.reply(200); + } else if (method === JsSIP_C.MESSAGE) { + if (this.listeners('newMessage').length === 0) { + request.reply(405); + return; + } + + var message = new Message(this); + message.init_incoming(request); + } else if (method === JsSIP_C.SUBSCRIBE) { + if (this.listeners('newSubscribe').length === 0) { + request.reply(405); + return; + } + } else if (method === JsSIP_C.INVITE) { + // Initial INVITE. + if (!request.to_tag && this.listeners('newRTCSession').length === 0) { + request.reply(405); + return; + } + } + + var dialog; + var session; // Initial Request. + + if (!request.to_tag) { + switch (method) { + case JsSIP_C.INVITE: + if (window.RTCPeerConnection) { + // TODO + if (request.hasHeader('replaces')) { + var replaces = request.replaces; + dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag); + + if (dialog) { + session = dialog.owner; + + if (!session.isEnded()) { + session.receiveRequest(request); + } else { + request.reply(603); + } + } else { + request.reply(481); + } + } else { + session = new RTCSession(this); + session.init_incoming(request); + } + } else { + debugerror('INVITE received but WebRTC is not supported'); + request.reply(488); + } + + break; + + case JsSIP_C.BYE: + // Out of dialog BYE received. + request.reply(481); + break; + + case JsSIP_C.CANCEL: + session = this._findSession(request); + + if (session) { + session.receiveRequest(request); + } else { + debug('received CANCEL request for a non existent session'); + } + + break; + + case JsSIP_C.ACK: + /* Absorb it. + * ACK request without a corresponding Invite Transaction + * and without To tag. + */ + break; + + case JsSIP_C.NOTIFY: + // Receive new sip event. + this.emit('sipEvent', { + event: request.event, + request: request + }); + request.reply(200); + break; + + case JsSIP_C.SUBSCRIBE: + this.emit('newSubscribe', { + event: request.event, + request: request + }); + break; + + default: + request.reply(405); + break; + } + } // In-dialog request. + else { + dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag); + + if (dialog) { + dialog.receiveRequest(request); + } else if (method === JsSIP_C.NOTIFY) { + session = this._findSession(request); + + if (session) { + session.receiveRequest(request); + } else { + debug('received NOTIFY request for a non existent subscription'); + request.reply(481, 'Subscription does not exist'); + } + } + /* RFC3261 12.2.2 + * Request with to tag, but no matching dialog found. + * Exception: ACK for an Invite request for which a dialog has not + * been created. + */ + else if (method !== JsSIP_C.ACK) { + request.reply(481); + } + } + } // ================= + // Utils. + // ================= + + /** + * Get the session to which the request belongs to, if any. + */ + + }, { + key: "_findSession", + value: function _findSession(_ref) { + var call_id = _ref.call_id, + from_tag = _ref.from_tag, + to_tag = _ref.to_tag; + var sessionIDa = call_id + from_tag; + var sessionA = this._sessions[sessionIDa]; + var sessionIDb = call_id + to_tag; + var sessionB = this._sessions[sessionIDb]; + + if (sessionA) { + return sessionA; + } else if (sessionB) { + return sessionB; + } else { + return null; + } + } + /** + * Get the dialog to which the request belongs to, if any. + */ + + }, { + key: "_findDialog", + value: function _findDialog(call_id, from_tag, to_tag) { + var id = call_id + from_tag + to_tag; + var dialog = this._dialogs[id]; + + if (dialog) { + return dialog; + } else { + id = call_id + to_tag + from_tag; + dialog = this._dialogs[id]; + + if (dialog) { + return dialog; + } else { + return null; + } + } + } + }, { + key: "_loadConfig", + value: function _loadConfig(configuration) { + // Check and load the given configuration. + try { + config.load(this._configuration, configuration); + } catch (e) { + throw e; + } // Post Configuration Process. + // Allow passing 0 number as display_name. + + + if (this._configuration.display_name === 0) { + this._configuration.display_name = '0'; + } // Instance-id for GRUU. + + + if (!this._configuration.instance_id) { + this._configuration.instance_id = Utils.newUUID(); + } // Jssip_id instance parameter. Static random tag of length 5. + + + this._configuration.jssip_id = Utils.createRandomToken(5); // String containing this._configuration.uri without scheme and user. + + var hostport_params = this._configuration.uri.clone(); + + hostport_params.user = null; + this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, ''); // Transport. + + try { + this._transport = new Transport(this._configuration.sockets, { + // Recovery options. + max_interval: this._configuration.connection_recovery_max_interval, + min_interval: this._configuration.connection_recovery_min_interval + }); // Transport event callbacks. + + this._transport.onconnecting = onTransportConnecting.bind(this); + this._transport.onconnect = onTransportConnect.bind(this); + this._transport.ondisconnect = onTransportDisconnect.bind(this); + this._transport.ondata = onTransportData.bind(this); + } catch (e) { + debugerror(e); + throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); + } // Remove sockets instance from configuration object. + + + delete this._configuration.sockets; // Check whether authorization_user is explicitly defined. + // Take 'this._configuration.uri.user' value if not. + + if (!this._configuration.authorization_user) { + this._configuration.authorization_user = this._configuration.uri.user; + } // If no 'registrar_server' is set use the 'uri' value without user portion and + // without URI params/headers. + + + if (!this._configuration.registrar_server) { + var registrar_server = this._configuration.uri.clone(); + + registrar_server.user = null; + registrar_server.clearParams(); + registrar_server.clearHeaders(); + this._configuration.registrar_server = registrar_server; + } // User no_answer_timeout. + + + this._configuration.no_answer_timeout *= 1000; // Via Host. + + if (this._configuration.contact_uri) { + this._configuration.via_host = this._configuration.contact_uri.host; + } // Contact URI. + else { + this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, { + transport: 'ws' + }); + } + + this._contact = { + pub_gruu: null, + temp_gruu: null, + uri: this._configuration.contact_uri, + toString: function toString() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var anonymous = options.anonymous || null; + var outbound = options.outbound || null; + var contact = '<'; + + if (anonymous) { + contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws'; + } else { + contact += this.pub_gruu || this.uri.toString(); + } + + if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) { + contact += ';ob'; + } + + contact += '>'; + return contact; + } + }; // Seal the configuration. + + var writable_parameters = ['authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register']; + + for (var parameter in this._configuration) { + if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) { + if (writable_parameters.indexOf(parameter) !== -1) { + Object.defineProperty(this._configuration, parameter, { + writable: true, + configurable: false + }); + } else { + Object.defineProperty(this._configuration, parameter, { + writable: false, + configurable: false + }); + } + } + } + + debug('configuration parameters after validation:'); + + for (var _parameter in this._configuration) { + // Only show the user user configurable parameters. + if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) { + switch (_parameter) { + case 'uri': + case 'registrar_server': + debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); + break; + + case 'password': + case 'ha1': + case 'authorization_jwt': + debug("- ".concat(_parameter, ": NOT SHOWN")); + break; + + default: + debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); + } + } + } + + return; + } + }], [{ + key: "C", + get: // Expose C object. + function get() { + return C; + } + }]); + + return UA; +}(EventEmitter); +/** + * Transport event handlers + */ +// Transport connecting event. + + +function onTransportConnecting(data) { + this.emit('connecting', data); +} // Transport connected event. + + +function onTransportConnect(data) { + if (this._status === C.STATUS_USER_CLOSED) { + return; + } + + this._status = C.STATUS_READY; + this._error = null; + this.emit('connected', data); + + if (this._dynConfiguration.register) { + this._registrator.register(); + } +} // Transport disconnected event. + + +function onTransportDisconnect(data) { + // Run _onTransportError_ callback on every client transaction using _transport_. + var client_transactions = ['nict', 'ict', 'nist', 'ist']; + + for (var _i = 0, _client_transactions = client_transactions; _i < _client_transactions.length; _i++) { + var type = _client_transactions[_i]; + + for (var id in this._transactions[type]) { + if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) { + this._transactions[type][id].onTransportError(); + } + } + } + + this.emit('disconnected', data); // Call registrator _onTransportClosed_. + + this._registrator.onTransportClosed(); + + if (this._status !== C.STATUS_USER_CLOSED) { + this._status = C.STATUS_NOT_READY; + this._error = C.NETWORK_ERROR; + } +} // Transport data event. + + +function onTransportData(data) { + var transport = data.transport; + var message = data.message; + message = Parser.parseMessage(message, this); + + if (!message) { + return; + } + + if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) { + return; + } // Do some sanity check. + + + if (!sanityCheck(message, this, transport)) { + return; + } + + if (message instanceof SIPMessage.IncomingRequest) { + message.transport = transport; + this.receiveRequest(message); + } else if (message instanceof SIPMessage.IncomingResponse) { + /* Unike stated in 18.1.2, if a response does not match + * any transaction, it is discarded here and no passed to the core + * in order to be discarded there. + */ + var transaction; + + switch (message.method) { + case JsSIP_C.INVITE: + transaction = this._transactions.ict[message.via_branch]; + + if (transaction) { + transaction.receiveResponse(message); + } + + break; + + case JsSIP_C.ACK: + // Just in case ;-). + break; + + default: + transaction = this._transactions.nict[message.via_branch]; + + if (transaction) { + transaction.receiveResponse(message); + } + + break; + } + } +} +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"debug":32,"events":31}],27:[function(require,module,exports){ +"use strict"; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var Grammar = require('./Grammar'); +/** + * -param {String} [scheme] + * -param {String} [user] + * -param {String} host + * -param {String} [port] + * -param {Object} [parameters] + * -param {Object} [headers] + * + */ + + +module.exports = /*#__PURE__*/function () { + function URI(scheme, user, host, port) { + var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; + var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; + + _classCallCheck(this, URI); + + // Checks. + if (!host) { + throw new TypeError('missing or invalid "host" parameter'); + } // Initialize parameters. + + + this._parameters = {}; + this._headers = {}; + this._scheme = scheme || JsSIP_C.SIP; + this._user = user; + this._host = host; + this._port = port; + + for (var param in parameters) { + if (Object.prototype.hasOwnProperty.call(parameters, param)) { + this.setParam(param, parameters[param]); + } + } + + for (var header in headers) { + if (Object.prototype.hasOwnProperty.call(headers, header)) { + this.setHeader(header, headers[header]); + } + } + } + + _createClass(URI, [{ + key: "scheme", + get: function get() { + return this._scheme; + }, + set: function set(value) { + this._scheme = value.toLowerCase(); + } + }, { + key: "user", + get: function get() { + return this._user; + }, + set: function set(value) { + this._user = value; + } + }, { + key: "host", + get: function get() { + return this._host; + }, + set: function set(value) { + this._host = value.toLowerCase(); + } + }, { + key: "port", + get: function get() { + return this._port; + }, + set: function set(value) { + this._port = value === 0 ? value : parseInt(value, 10) || null; + } + }, { + key: "setParam", + value: function setParam(key, value) { + if (key) { + this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString(); + } + } + }, { + key: "getParam", + value: function getParam(key) { + if (key) { + return this._parameters[key.toLowerCase()]; + } + } + }, { + key: "hasParam", + value: function hasParam(key) { + if (key) { + return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false; + } + } + }, { + key: "deleteParam", + value: function deleteParam(parameter) { + parameter = parameter.toLowerCase(); + + if (this._parameters.hasOwnProperty(parameter)) { + var value = this._parameters[parameter]; + delete this._parameters[parameter]; + return value; + } + } + }, { + key: "clearParams", + value: function clearParams() { + this._parameters = {}; + } + }, { + key: "setHeader", + value: function setHeader(name, value) { + this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value]; + } + }, { + key: "getHeader", + value: function getHeader(name) { + if (name) { + return this._headers[Utils.headerize(name)]; + } + } + }, { + key: "hasHeader", + value: function hasHeader(name) { + if (name) { + return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false; + } + } + }, { + key: "deleteHeader", + value: function deleteHeader(header) { + header = Utils.headerize(header); + + if (this._headers.hasOwnProperty(header)) { + var value = this._headers[header]; + delete this._headers[header]; + return value; + } + } + }, { + key: "clearHeaders", + value: function clearHeaders() { + this._headers = {}; + } + }, { + key: "clone", + value: function clone() { + return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers))); + } + }, { + key: "toString", + value: function toString() { + var headers = []; + var uri = "".concat(this._scheme, ":"); + + if (this._user) { + uri += "".concat(Utils.escapeUser(this._user), "@"); + } + + uri += this._host; + + if (this._port || this._port === 0) { + uri += ":".concat(this._port); + } + + for (var parameter in this._parameters) { + if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) { + uri += ";".concat(parameter); + + if (this._parameters[parameter] !== null) { + uri += "=".concat(this._parameters[parameter]); + } + } + } + + for (var header in this._headers) { + if (Object.prototype.hasOwnProperty.call(this._headers, header)) { + var _iterator = _createForOfIteratorHelper(this._headers[header]), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var item = _step.value; + headers.push("".concat(header, "=").concat(item)); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + } + + if (headers.length > 0) { + uri += "?".concat(headers.join('&')); + } + + return uri; + } + }, { + key: "toAor", + value: function toAor(show_port) { + var aor = "".concat(this._scheme, ":"); + + if (this._user) { + aor += "".concat(Utils.escapeUser(this._user), "@"); + } + + aor += this._host; + + if (show_port && (this._port || this._port === 0)) { + aor += ":".concat(this._port); + } + + return aor; + } + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a JsSIP.URI instance or undefined if + * it is an invalid URI. + */ + function parse(uri) { + uri = Grammar.parse(uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } else { + return undefined; + } + } + }]); + + return URI; +}(); +},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var JsSIP_C = require('./Constants'); + +var URI = require('./URI'); + +var Grammar = require('./Grammar'); + +exports.str_utf8_length = function (string) { + return unescape(encodeURIComponent(string)).length; +}; // Used by 'hasMethods'. + + +var isFunction = exports.isFunction = function (fn) { + if (fn !== undefined) { + return Object.prototype.toString.call(fn) === '[object Function]' ? true : false; + } else { + return false; + } +}; + +exports.isString = function (str) { + if (str !== undefined) { + return Object.prototype.toString.call(str) === '[object String]' ? true : false; + } else { + return false; + } +}; + +exports.isDecimal = function (num) { + return !isNaN(num) && parseFloat(num) === parseInt(num, 10); +}; + +exports.isEmpty = function (value) { + return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value); +}; + +exports.hasMethods = function (obj) { + for (var _len = arguments.length, methodNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + methodNames[_key - 1] = arguments[_key]; + } + + for (var _i = 0, _methodNames = methodNames; _i < _methodNames.length; _i++) { + var methodName = _methodNames[_i]; + + if (isFunction(obj[methodName])) { + return false; + } + } + + return true; +}; // Used by 'newTag'. + + +var createRandomToken = exports.createRandomToken = function (size) { + var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32; + var i, + r, + token = ''; + + for (i = 0; i < size; i++) { + r = Math.random() * base | 0; + token += r.toString(base); + } + + return token; +}; + +exports.newTag = function () { + return createRandomToken(10); +}; // https://stackoverflow.com/users/109538/broofa. + + +exports.newUUID = function () { + var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0, + v = c === 'x' ? r : r & 0x3 | 0x8; + return v.toString(16); + }); + return UUID; +}; + +exports.hostType = function (host) { + if (!host) { + return; + } else { + host = Grammar.parse(host, 'host'); + + if (host !== -1) { + return host.host_type; + } + } +}; +/** +* Hex-escape a SIP URI user. +* Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F). +* +* Used by 'normalizeTarget'. +*/ + + +var escapeUser = exports.escapeUser = function (user) { + return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/'); +}; +/** +* Normalize SIP URI. +* NOTE: It does not allow a SIP URI without username. +* Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'. +* Detects the domain part (if given) and properly hex-escapes the user portion. +* If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators. +*/ + + +exports.normalizeTarget = function (target, domain) { + // If no target is given then raise an error. + if (!target) { + return; // If a URI instance is given then return it. + } else if (target instanceof URI) { + return target; // If a string is given split it by '@': + // - Last fragment is the desired domain. + // - Otherwise append the given domain argument. + } else if (typeof target === 'string') { + var target_array = target.split('@'); + var target_user; + var target_domain; + + switch (target_array.length) { + case 1: + if (!domain) { + return; + } + + target_user = target; + target_domain = domain; + break; + + case 2: + target_user = target_array[0]; + target_domain = target_array[1]; + break; + + default: + target_user = target_array.slice(0, target_array.length - 1).join('@'); + target_domain = target_array[target_array.length - 1]; + } // Remove the URI scheme (if present). + + + target_user = target_user.replace(/^(sips?|tel):/i, ''); // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols. + + if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) { + target_user = target_user.replace(/[-.()]/g, ''); + } // Build the complete SIP URI. + + + target = "".concat(JsSIP_C.SIP, ":").concat(escapeUser(target_user), "@").concat(target_domain); // Finally parse the resulting URI. + + var uri; + + if (uri = URI.parse(target)) { + return uri; + } else { + return; + } + } else { + return; + } +}; + +exports.headerize = function (string) { + var exceptions = { + 'Call-Id': 'Call-ID', + 'Cseq': 'CSeq', + 'Www-Authenticate': 'WWW-Authenticate' + }; + var name = string.toLowerCase().replace(/_/g, '-').split('-'); + var hname = ''; + var parts = name.length; + var part; + + for (part = 0; part < parts; part++) { + if (part !== 0) { + hname += '-'; + } + + hname += name[part].charAt(0).toUpperCase() + name[part].substring(1); + } + + if (exceptions[hname]) { + hname = exceptions[hname]; + } + + return hname; +}; + +exports.sipErrorCause = function (status_code) { + for (var cause in JsSIP_C.SIP_ERROR_CAUSES) { + if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) { + return JsSIP_C.causes[cause]; + } + } + + return JsSIP_C.causes.SIP_FAILURE_CODE; +}; +/** +* Generate a random Test-Net IP (https://tools.ietf.org/html/rfc5735) +*/ + + +exports.getRandomTestNetIP = function () { + function getOctet(from, to) { + return Math.floor(Math.random() * (to - from + 1) + from); + } + + return "192.0.2.".concat(getOctet(1, 254)); +}; // MD5 (Message-Digest Algorithm) https://www.webtoolkit.info. + + +exports.calculateMD5 = function (string) { + function rotateLeft(lValue, iShiftBits) { + return lValue << iShiftBits | lValue >>> 32 - iShiftBits; + } + + function addUnsigned(lX, lY) { + var lX8 = lX & 0x80000000; + var lY8 = lY & 0x80000000; + var lX4 = lX & 0x40000000; + var lY4 = lY & 0x40000000; + var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); + + if (lX4 & lY4) { + return lResult ^ 0x80000000 ^ lX8 ^ lY8; + } + + if (lX4 | lY4) { + if (lResult & 0x40000000) { + return lResult ^ 0xC0000000 ^ lX8 ^ lY8; + } else { + return lResult ^ 0x40000000 ^ lX8 ^ lY8; + } + } else { + return lResult ^ lX8 ^ lY8; + } + } + + function doF(x, y, z) { + return x & y | ~x & z; + } + + function doG(x, y, z) { + return x & z | y & ~z; + } + + function doH(x, y, z) { + return x ^ y ^ z; + } + + function doI(x, y, z) { + return y ^ (x | ~z); + } + + function doFF(a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + } + + function doGG(a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + } + + function doHH(a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + } + + function doII(a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + } + + function convertToWordArray(str) { + var lWordCount; + var lMessageLength = str.length; + var lNumberOfWords_temp1 = lMessageLength + 8; + var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64; + var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; + var lWordArray = new Array(lNumberOfWords - 1); + var lBytePosition = 0; + var lByteCount = 0; + + while (lByteCount < lMessageLength) { + lWordCount = (lByteCount - lByteCount % 4) / 4; + lBytePosition = lByteCount % 4 * 8; + lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition; + lByteCount++; + } + + lWordCount = (lByteCount - lByteCount % 4) / 4; + lBytePosition = lByteCount % 4 * 8; + lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition; + lWordArray[lNumberOfWords - 2] = lMessageLength << 3; + lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; + return lWordArray; + } + + function wordToHex(lValue) { + var wordToHexValue = '', + wordToHexValue_temp = '', + lByte, + lCount; + + for (lCount = 0; lCount <= 3; lCount++) { + lByte = lValue >>> lCount * 8 & 255; + wordToHexValue_temp = "0".concat(lByte.toString(16)); + wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2); + } + + return wordToHexValue; + } + + function utf8Encode(str) { + str = str.replace(/\r\n/g, '\n'); + var utftext = ''; + + for (var n = 0; n < str.length; n++) { + var _c = str.charCodeAt(n); + + if (_c < 128) { + utftext += String.fromCharCode(_c); + } else if (_c > 127 && _c < 2048) { + utftext += String.fromCharCode(_c >> 6 | 192); + utftext += String.fromCharCode(_c & 63 | 128); + } else { + utftext += String.fromCharCode(_c >> 12 | 224); + utftext += String.fromCharCode(_c >> 6 & 63 | 128); + utftext += String.fromCharCode(_c & 63 | 128); + } + } + + return utftext; + } + + var x = []; + var k, AA, BB, CC, DD, a, b, c, d; + var S11 = 7, + S12 = 12, + S13 = 17, + S14 = 22; + var S21 = 5, + S22 = 9, + S23 = 14, + S24 = 20; + var S31 = 4, + S32 = 11, + S33 = 16, + S34 = 23; + var S41 = 6, + S42 = 10, + S43 = 15, + S44 = 21; + string = utf8Encode(string); + x = convertToWordArray(string); + a = 0x67452301; + b = 0xEFCDAB89; + c = 0x98BADCFE; + d = 0x10325476; + + for (k = 0; k < x.length; k += 16) { + AA = a; + BB = b; + CC = c; + DD = d; + a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478); + d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); + c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB); + b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); + a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); + d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A); + c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613); + b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501); + a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8); + d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); + c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); + b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); + a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122); + d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193); + c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E); + b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821); + a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562); + d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340); + c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51); + b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); + a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D); + d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453); + c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); + b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); + a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); + d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6); + c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); + b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED); + a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); + d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); + c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9); + b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); + a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); + d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681); + c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); + b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); + a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); + d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); + c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); + b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); + a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); + d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); + c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); + b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05); + a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); + d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); + c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); + b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); + a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244); + d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97); + c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7); + b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039); + a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3); + d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); + c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); + b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1); + a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); + d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); + c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314); + b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1); + a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82); + d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235); + c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); + b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391); + a = addUnsigned(a, AA); + b = addUnsigned(b, BB); + c = addUnsigned(c, CC); + d = addUnsigned(d, DD); + } + + var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); + return temp.toLowerCase(); +}; + +exports.closeMediaStream = function (stream) { + if (!stream) { + return; + } // Latest spec states that MediaStream has no stop() method and instead must + // call stop() on every MediaStreamTrack. + + + try { + var tracks; + + if (stream.getTracks) { + tracks = stream.getTracks(); + + var _iterator = _createForOfIteratorHelper(tracks), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var track = _step.value; + track.stop(); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } else { + tracks = stream.getAudioTracks(); + + var _iterator2 = _createForOfIteratorHelper(tracks), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var _track = _step2.value; + + _track.stop(); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + + tracks = stream.getVideoTracks(); + + var _iterator3 = _createForOfIteratorHelper(tracks), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _track2 = _step3.value; + + _track2.stop(); + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } + } catch (error) { + // Deprecated by the spec, but still in use. + // NOTE: In Temasys IE plugin stream.stop is a callable 'object'. + if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') { + stream.stop(); + } + } +}; + +exports.cloneArray = function (array) { + return array && array.slice() || []; +}; + +exports.cloneObject = function (obj) { + var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return obj && Object.assign({}, obj) || fallback; +}; +},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var Grammar = require('./Grammar'); + +var debug = require('debug')('JsSIP:WebSocketInterface'); + +var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); + +debugerror.log = console.warn.bind(console); + +module.exports = /*#__PURE__*/function () { + function WebSocketInterface(url) { + _classCallCheck(this, WebSocketInterface); + + debug('new() [url:"%s"]', url); + this._url = url; + this._sip_uri = null; + this._via_transport = null; + this._ws = null; + var parsed_url = Grammar.parse(url, 'absoluteURI'); + + if (parsed_url === -1) { + debugerror("invalid WebSocket URI: ".concat(url)); + throw new TypeError("Invalid argument: ".concat(url)); + } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { + debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); + throw new TypeError("Invalid argument: ".concat(url)); + } else { + this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws"); + this._via_transport = parsed_url.scheme.toUpperCase(); + } + } + + _createClass(WebSocketInterface, [{ + key: "via_transport", + get: function get() { + return this._via_transport; + }, + set: function set(value) { + this._via_transport = value.toUpperCase(); + } + }, { + key: "sip_uri", + get: function get() { + return this._sip_uri; + } + }, { + key: "url", + get: function get() { + return this._url; + } + }, { + key: "connect", + value: function connect() { + debug('connect()'); + + if (this.isConnected()) { + debug("WebSocket ".concat(this._url, " is already connected")); + return; + } else if (this.isConnecting()) { + debug("WebSocket ".concat(this._url, " is connecting")); + return; + } + + if (this._ws) { + this.disconnect(); + } + + debug("connecting to WebSocket ".concat(this._url)); + + try { + this._ws = new WebSocket(this._url, 'sip'); + this._ws.binaryType = 'arraybuffer'; + this._ws.onopen = this._onOpen.bind(this); + this._ws.onclose = this._onClose.bind(this); + this._ws.onmessage = this._onMessage.bind(this); + this._ws.onerror = this._onError.bind(this); + } catch (e) { + this._onError(e); + } + } + }, { + key: "disconnect", + value: function disconnect() { + debug('disconnect()'); + + if (this._ws) { + // Unbind websocket event callbacks. + 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 send(message) { + debug('send()'); + + if (this.isConnected()) { + this._ws.send(message); + + return true; + } else { + debugerror('unable to send message, WebSocket is not open'); + return false; + } + } + }, { + key: "isConnected", + value: function isConnected() { + return this._ws && this._ws.readyState === this._ws.OPEN; + } + }, { + key: "isConnecting", + value: function isConnecting() { + return this._ws && this._ws.readyState === this._ws.CONNECTING; + } + /** + * WebSocket Event Handlers + */ + + }, { + key: "_onOpen", + value: function _onOpen() { + debug("WebSocket ".concat(this._url, " connected")); + this.onconnect(); + } + }, { + key: "_onClose", + value: function _onClose(_ref) { + var wasClean = _ref.wasClean, + code = _ref.code, + reason = _ref.reason; + debug("WebSocket ".concat(this._url, " closed")); + + if (wasClean === false) { + debug('WebSocket abrupt disconnection'); + } + + this.ondisconnect(!wasClean, code, reason); + } + }, { + key: "_onMessage", + value: function _onMessage(_ref2) { + var data = _ref2.data; + debug('received WebSocket message'); + this.ondata(data); + } + }, { + key: "_onError", + value: function _onError(e) { + debugerror("WebSocket ".concat(this._url, " error: "), e); + } + }]); + + return WebSocketInterface; +}(); +},{"./Grammar":7,"debug":32}],30:[function(require,module,exports){ +"use strict"; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var JsSIP_C = require('./Constants'); + +var SIPMessage = require('./SIPMessage'); + +var Utils = require('./Utils'); + +var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses. + + +var all = [minimumHeaders]; // Checks for requests. + +var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2]; // Checks for responses. + +var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response]; // local variables. + +var message; +var ua; +var transport; + +module.exports = function (m, u, t) { + message = m; + ua = u; + transport = t; + + var _iterator = _createForOfIteratorHelper(all), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var _check2 = _step.value; + + if (_check2() === false) { + return false; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + if (message instanceof SIPMessage.IncomingRequest) { + var _iterator2 = _createForOfIteratorHelper(requests), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var check = _step2.value; + + if (check() === false) { + return false; + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } else if (message instanceof SIPMessage.IncomingResponse) { + var _iterator3 = _createForOfIteratorHelper(responses), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _check = _step3.value; + + if (_check() === false) { + return false; + } + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } // Everything is OK. + + + return true; +}; +/* + * Sanity Check for incoming Messages + * + * Requests: + * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme + * - _rfc3261_16_3_4_ Receive a Request already sent by us + * Does not look at via sent-by but at jssip_id, which is inserted as + * a prefix in all initial requests generated by the ua + * - _rfc3261_18_3_request_ Body Content-Length + * - _rfc3261_8_2_2_2_ Merged Requests + * + * Responses: + * - _rfc3261_8_1_3_3_ Multiple Via headers + * - _rfc3261_18_3_response_ Body Content-Length + * + * All: + * - Minimum headers in a SIP message + */ +// Sanity Check functions for requests. + + +function rfc3261_8_2_2_1() { + if (message.s('to').uri.scheme !== 'sip') { + reply(416); + return false; + } +} + +function rfc3261_16_3_4() { + if (!message.to_tag) { + if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) { + reply(482); + return false; + } + } +} + +function rfc3261_18_3_request() { + var len = Utils.str_utf8_length(message.body); + var contentLength = message.getHeader('content-length'); + + if (len < contentLength) { + reply(400); + return false; + } +} + +function rfc3261_8_2_2_2() { + var fromTag = message.from_tag; + var call_id = message.call_id; + var cseq = message.cseq; + var tr; // Accept any in-dialog request. + + if (message.to_tag) { + return; + } // INVITE request. + + + if (message.method === JsSIP_C.INVITE) { + // If the branch matches the key of any IST then assume it is a retransmission + // and ignore the INVITE. + // TODO: we should reply the last response. + if (ua._transactions.ist[message.via_branch]) { + return false; + } // Otherwise check whether it is a merged request. + else { + for (var transaction in ua._transactions.ist) { + if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) { + tr = ua._transactions.ist[transaction]; + + if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) { + reply(482); + return false; + } + } + } + } + } // Non INVITE request. + // If the branch matches the key of any NIST then assume it is a retransmission + // and ignore the request. + // TODO: we should reply the last response. + else if (ua._transactions.nist[message.via_branch]) { + return false; + } // Otherwise check whether it is a merged request. + else { + for (var _transaction in ua._transactions.nist) { + if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) { + tr = ua._transactions.nist[_transaction]; + + if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) { + reply(482); + return false; + } + } + } + } +} // Sanity Check functions for responses. + + +function rfc3261_8_1_3_3() { + if (message.getHeaders('via').length > 1) { + debug('more than one Via header field present in the response, dropping the response'); + return false; + } +} + +function rfc3261_18_3_response() { + var len = Utils.str_utf8_length(message.body), + contentLength = message.getHeader('content-length'); + + if (len < contentLength) { + debug('message body length is lower than the value in Content-Length header field, dropping the response'); + return false; + } +} // Sanity Check functions for requests and responses. + + +function minimumHeaders() { + var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via']; + + for (var _i = 0, _mandatoryHeaders = mandatoryHeaders; _i < _mandatoryHeaders.length; _i++) { + var header = _mandatoryHeaders[_i]; + + if (!message.hasHeader(header)) { + debug("missing mandatory header field : ".concat(header, ", dropping the response")); + return false; + } + } +} // Reply. + + +function reply(status_code) { + var vias = message.getHeaders('via'); + var to; + var response = "SIP/2.0 ".concat(status_code, " ").concat(JsSIP_C.REASON_PHRASE[status_code], "\r\n"); + + var _iterator4 = _createForOfIteratorHelper(vias), + _step4; + + try { + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + var via = _step4.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); + } + + to = message.getHeader('To'); + + if (!message.to_tag) { + to += ";tag=".concat(Utils.newTag()); + } + + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(message.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(message.call_id, "\r\n"); + response += "CSeq: ".concat(message.cseq, " ").concat(message.method, "\r\n"); + response += '\r\n'; + transport.send(response); +} +},{"./Constants":2,"./SIPMessage":20,"./Utils":28,"debug":32}],31:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var objectCreate = Object.create || objectCreatePolyfill +var objectKeys = Object.keys || objectKeysPolyfill +var bind = Function.prototype.bind || functionBindPolyfill + +function EventEmitter() { + if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) { + this._events = objectCreate(null); + this._eventsCount = 0; + } + + this._maxListeners = this._maxListeners || undefined; +} +module.exports = EventEmitter; + +// Backwards-compat with node 0.10.x +EventEmitter.EventEmitter = EventEmitter; + +EventEmitter.prototype._events = undefined; +EventEmitter.prototype._maxListeners = undefined; + +// By default EventEmitters will print a warning if more than 10 listeners are +// added to it. This is a useful default which helps finding memory leaks. +var defaultMaxListeners = 10; + +var hasDefineProperty; +try { + var o = {}; + if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 }); + hasDefineProperty = o.x === 0; +} catch (err) { hasDefineProperty = false } +if (hasDefineProperty) { + Object.defineProperty(EventEmitter, 'defaultMaxListeners', { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + // check whether the input is a positive number (whose value is zero or + // greater and not a NaN). + if (typeof arg !== 'number' || arg < 0 || arg !== arg) + throw new TypeError('"defaultMaxListeners" must be a positive number'); + defaultMaxListeners = arg; + } + }); +} else { + EventEmitter.defaultMaxListeners = defaultMaxListeners; +} + +// Obviously not all Emitters should be limited to 10. This function allows +// that to be increased. Set to zero for unlimited. +EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== 'number' || n < 0 || isNaN(n)) + throw new TypeError('"n" argument must be a positive number'); + this._maxListeners = n; + return this; +}; + +function $getMaxListeners(that) { + if (that._maxListeners === undefined) + return EventEmitter.defaultMaxListeners; + return that._maxListeners; +} + +EventEmitter.prototype.getMaxListeners = function getMaxListeners() { + return $getMaxListeners(this); +}; + +// These standalone emit* functions are used to optimize calling of event +// handlers for fast cases because emit() itself often has a variable number of +// arguments and can be deoptimized because of that. These functions always have +// the same number of arguments and thus do not get deoptimized, so the code +// inside them can execute faster. +function emitNone(handler, isFn, self) { + if (isFn) + handler.call(self); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self); + } +} +function emitOne(handler, isFn, self, arg1) { + if (isFn) + handler.call(self, arg1); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1); + } +} +function emitTwo(handler, isFn, self, arg1, arg2) { + if (isFn) + handler.call(self, arg1, arg2); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1, arg2); + } +} +function emitThree(handler, isFn, self, arg1, arg2, arg3) { + if (isFn) + handler.call(self, arg1, arg2, arg3); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].call(self, arg1, arg2, arg3); + } +} + +function emitMany(handler, isFn, self, args) { + if (isFn) + handler.apply(self, args); + else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + listeners[i].apply(self, args); + } +} + +EventEmitter.prototype.emit = function emit(type) { + var er, handler, len, args, i, events; + var doError = (type === 'error'); + + events = this._events; + if (events) + doError = (doError && events.error == null); + else if (!doError) + return false; + + // If there is no 'error' event listener then throw. + if (doError) { + if (arguments.length > 1) + er = arguments[1]; + if (er instanceof Error) { + throw er; // Unhandled 'error' event + } else { + // At least give some kind of context to the user + var err = new Error('Unhandled "error" event. (' + er + ')'); + err.context = er; + throw err; + } + return false; + } + + handler = events[type]; + + if (!handler) + return false; + + var isFn = typeof handler === 'function'; + len = arguments.length; + switch (len) { + // fast cases + case 1: + emitNone(handler, isFn, this); + break; + case 2: + emitOne(handler, isFn, this, arguments[1]); + break; + case 3: + emitTwo(handler, isFn, this, arguments[1], arguments[2]); + break; + case 4: + emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]); + break; + // slower + default: + args = new Array(len - 1); + for (i = 1; i < len; i++) + args[i - 1] = arguments[i]; + emitMany(handler, isFn, this, args); + } + + return true; +}; + +function _addListener(target, type, listener, prepend) { + var m; + var events; + var existing; + + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + + events = target._events; + if (!events) { + events = target._events = objectCreate(null); + target._eventsCount = 0; + } else { + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (events.newListener) { + target.emit('newListener', type, + listener.listener ? listener.listener : listener); + + // Re-assign `events` because a newListener handler could have caused the + // this._events to be assigned to a new object + events = target._events; + } + existing = events[type]; + } + + if (!existing) { + // Optimize the case of one listener. Don't need the extra array object. + existing = events[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === 'function') { + // Adding the second element, need to change to array. + existing = events[type] = + prepend ? [listener, existing] : [existing, listener]; + } else { + // If we've already got an array, just append. + if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + } + + // Check for listener leak + if (!existing.warned) { + m = $getMaxListeners(target); + if (m && m > 0 && existing.length > m) { + existing.warned = true; + var w = new Error('Possible EventEmitter memory leak detected. ' + + existing.length + ' "' + String(type) + '" listeners ' + + 'added. Use emitter.setMaxListeners() to ' + + 'increase limit.'); + w.name = 'MaxListenersExceededWarning'; + w.emitter = target; + w.type = type; + w.count = existing.length; + if (typeof console === 'object' && console.warn) { + console.warn('%s: %s', w.name, w.message); + } + } + } + } + + return target; +} + +EventEmitter.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); +}; + +EventEmitter.prototype.on = EventEmitter.prototype.addListener; + +EventEmitter.prototype.prependListener = + function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + +function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + switch (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: + var args = new Array(arguments.length); + for (var i = 0; i < args.length; ++i) + args[i] = arguments[i]; + this.listener.apply(this.target, args); + } + } +} + +function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener }; + var wrapped = bind.call(onceWrapper, state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; +} + +EventEmitter.prototype.once = function once(type, listener) { + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + this.on(type, _onceWrap(this, type, listener)); + return this; +}; + +EventEmitter.prototype.prependOnceListener = + function prependOnceListener(type, listener) { + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + +// Emits a 'removeListener' event if and only if the listener was removed. +EventEmitter.prototype.removeListener = + function removeListener(type, listener) { + var list, events, position, i, originalListener; + + if (typeof listener !== 'function') + throw new TypeError('"listener" argument must be a function'); + + events = this._events; + if (!events) + return this; + + list = events[type]; + if (!list) + return this; + + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = objectCreate(null); + else { + delete events[type]; + if (events.removeListener) + this.emit('removeListener', type, list.listener || listener); + } + } else if (typeof list !== 'function') { + position = -1; + + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + + if (position < 0) + return this; + + if (position === 0) + list.shift(); + else + spliceOne(list, position); + + if (list.length === 1) + events[type] = list[0]; + + if (events.removeListener) + this.emit('removeListener', type, originalListener || listener); + } + + return this; + }; + +EventEmitter.prototype.removeAllListeners = + function removeAllListeners(type) { + var listeners, events, i; + + events = this._events; + if (!events) + return this; + + // not listening for removeListener, no need to emit + if (!events.removeListener) { + if (arguments.length === 0) { + this._events = objectCreate(null); + this._eventsCount = 0; + } else if (events[type]) { + if (--this._eventsCount === 0) + this._events = objectCreate(null); + else + delete events[type]; + } + return this; + } + + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + var keys = objectKeys(events); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === 'removeListener') continue; + this.removeAllListeners(key); + } + this.removeAllListeners('removeListener'); + this._events = objectCreate(null); + this._eventsCount = 0; + return this; + } + + listeners = events[type]; + + if (typeof listeners === 'function') { + this.removeListener(type, listeners); + } else if (listeners) { + // LIFO order + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + + return this; + }; + +function _listeners(target, type, unwrap) { + var events = target._events; + + if (!events) + return []; + + var evlistener = events[type]; + if (!evlistener) + return []; + + if (typeof evlistener === 'function') + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); +} + +EventEmitter.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); +}; + +EventEmitter.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); +}; + +EventEmitter.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === 'function') { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } +}; + +EventEmitter.prototype.listenerCount = listenerCount; +function listenerCount(type) { + var events = this._events; + + if (events) { + var evlistener = events[type]; + + if (typeof evlistener === 'function') { + return 1; + } else if (evlistener) { + return evlistener.length; + } + } + + return 0; +} + +EventEmitter.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : []; +}; + +// About 1.5x faster than the two-arg version of Array#splice(). +function spliceOne(list, index) { + for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) + list[i] = list[k]; + list.pop(); +} + +function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; +} + +function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; +} + +function objectCreatePolyfill(proto) { + var F = function() {}; + F.prototype = proto; + return new F; +} +function objectKeysPolyfill(obj) { + var keys = []; + for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) { + keys.push(k); + } + return k; +} +function functionBindPolyfill(context) { + var fn = this; + return function () { + return fn.apply(context, arguments); + }; +} + +},{}],32:[function(require,module,exports){ +(function (process){(function (){ +/* eslint-env browser */ + +/** + * This is the web browser implementation of `debug()`. + */ + +exports.formatArgs = formatArgs; +exports.save = save; +exports.load = load; +exports.useColors = useColors; +exports.storage = localstorage(); +exports.destroy = (() => { + let warned = false; + + return () => { + if (!warned) { + warned = true; + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + }; +})(); + +/** + * Colors. + */ + +exports.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' +]; + +/** + * Currently only WebKit-based Web Inspectors, Firefox >= v31, + * and the Firebug extension (any Firefox version) are known + * to support "%c" CSS customizations. + * + * TODO: add a `localStorage` variable to explicitly enable/disable colors + */ + +// eslint-disable-next-line complexity +function useColors() { + // NB: In an Electron preload script, document will be defined but not fully + // initialized. Since we know we're in Chrome, we'll just detect this case + // explicitly + if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { + return true; + } + + // Internet Explorer and Edge do not support colors. + if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { + return false; + } + + // Is webkit? http://stackoverflow.com/a/16459606/376773 + // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 + return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || + // Is firebug? http://stackoverflow.com/a/398120/376773 + (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || + // Is firefox >= v31? + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || + // Double check webkit in userAgent just in case we are in a worker + (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); +} + +/** + * Colorize log arguments if enabled. + * + * @api public + */ + +function formatArgs(args) { + args[0] = (this.useColors ? '%c' : '') + + this.namespace + + (this.useColors ? ' %c' : ' ') + + args[0] + + (this.useColors ? '%c ' : ' ') + + '+' + module.exports.humanize(this.diff); + + if (!this.useColors) { + return; + } + + const c = 'color: ' + this.color; + args.splice(1, 0, c, 'color: inherit'); + + // The final "%c" is somewhat tricky, because there could be other + // arguments passed either before or after the %c, so we need to + // figure out the correct index to insert the CSS into + let index = 0; + let lastC = 0; + args[0].replace(/%[a-zA-Z%]/g, match => { + if (match === '%%') { + return; + } + index++; + if (match === '%c') { + // We only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; + } + }); + + args.splice(lastC, 0, c); +} + +/** + * Invokes `console.debug()` when available. + * No-op when `console.debug` is not a "function". + * If `console.debug` is not available, falls back + * to `console.log`. + * + * @api public + */ +exports.log = console.debug || console.log || (() => {}); + +/** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ +function save(namespaces) { + try { + if (namespaces) { + exports.storage.setItem('debug', namespaces); + } else { + exports.storage.removeItem('debug'); + } + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } +} + +/** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ +function load() { + let r; + try { + r = exports.storage.getItem('debug'); + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } + + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + if (!r && typeof process !== 'undefined' && 'env' in process) { + r = process.env.DEBUG; + } + + return r; +} + +/** + * Localstorage attempts to return the localstorage. + * + * This is necessary because safari throws + * when a user disables cookies/localstorage + * and you attempt to access it. + * + * @return {LocalStorage} + * @api private + */ + +function localstorage() { + try { + // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context + // The Browser also has localStorage in the global context. + return localStorage; + } catch (error) { + // Swallow + // XXX (@Qix-) should we be logging these? + } +} + +module.exports = require('./common')(exports); + +const {formatters} = module.exports; + +/** + * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. + */ + +formatters.j = function (v) { + try { + return JSON.stringify(v); + } catch (error) { + return '[UnexpectedJSONParseError]: ' + error.message; + } +}; + +}).call(this)}).call(this,require('_process')) +},{"./common":33,"_process":35}],33:[function(require,module,exports){ + +/** + * This is the common logic for both the Node.js and web browser + * implementations of `debug()`. + */ + +function setup(env) { + createDebug.debug = createDebug; + createDebug.default = createDebug; + createDebug.coerce = coerce; + createDebug.disable = disable; + createDebug.enable = enable; + createDebug.enabled = enabled; + createDebug.humanize = require('ms'); + createDebug.destroy = destroy; + + Object.keys(env).forEach(key => { + createDebug[key] = env[key]; + }); + + /** + * The currently active debug mode names, and names to skip. + */ + + createDebug.names = []; + createDebug.skips = []; + + /** + * Map of special "%n" handling functions, for the debug "format" argument. + * + * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". + */ + createDebug.formatters = {}; + + /** + * Selects a color for a debug namespace + * @param {String} namespace The namespace string for the for the debug instance to be colored + * @return {Number|String} An ANSI color code for the given namespace + * @api private + */ + function selectColor(namespace) { + let hash = 0; + + for (let i = 0; i < namespace.length; i++) { + hash = ((hash << 5) - hash) + namespace.charCodeAt(i); + hash |= 0; // Convert to 32bit integer + } + + return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; + } + createDebug.selectColor = selectColor; + + /** + * Create a debugger with the given `namespace`. + * + * @param {String} namespace + * @return {Function} + * @api public + */ + function createDebug(namespace) { + let prevTime; + let enableOverride = null; + + function debug(...args) { + // Disabled? + if (!debug.enabled) { + return; + } + + const self = debug; + + // Set `diff` timestamp + const curr = Number(new Date()); + const ms = curr - (prevTime || curr); + self.diff = ms; + self.prev = prevTime; + self.curr = curr; + prevTime = curr; + + args[0] = createDebug.coerce(args[0]); + + if (typeof args[0] !== 'string') { + // Anything else let's inspect with %O + args.unshift('%O'); + } + + // Apply any `formatters` transformations + let index = 0; + args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { + // If we encounter an escaped % then don't increase the array index + if (match === '%%') { + return '%'; + } + index++; + const formatter = createDebug.formatters[format]; + if (typeof formatter === 'function') { + const val = args[index]; + match = formatter.call(self, val); + + // Now we need to remove `args[index]` since it's inlined in the `format` + args.splice(index, 1); + index--; + } + return match; + }); + + // Apply env-specific formatting (colors, etc.) + createDebug.formatArgs.call(self, args); + + const logFn = self.log || createDebug.log; + logFn.apply(self, args); + } + + debug.namespace = namespace; + debug.useColors = createDebug.useColors(); + debug.color = createDebug.selectColor(namespace); + debug.extend = extend; + debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. + + Object.defineProperty(debug, 'enabled', { + enumerable: true, + configurable: false, + get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, + set: v => { + enableOverride = v; + } + }); + + // Env-specific initialization logic for debug instances + if (typeof createDebug.init === 'function') { + createDebug.init(debug); + } + + return debug; + } + + function extend(namespace, delimiter) { + const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); + newDebug.log = this.log; + return newDebug; + } + + /** + * Enables a debug mode by namespaces. This can include modes + * separated by a colon and wildcards. + * + * @param {String} namespaces + * @api public + */ + function enable(namespaces) { + createDebug.save(namespaces); + + createDebug.names = []; + createDebug.skips = []; + + let i; + const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); + const len = split.length; + + for (i = 0; i < len; i++) { + if (!split[i]) { + // ignore empty strings + continue; + } + + namespaces = split[i].replace(/\*/g, '.*?'); + + if (namespaces[0] === '-') { + createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); + } else { + createDebug.names.push(new RegExp('^' + namespaces + '$')); + } + } + } + + /** + * Disable debug output. + * + * @return {String} namespaces + * @api public + */ + function disable() { + const namespaces = [ + ...createDebug.names.map(toNamespace), + ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace) + ].join(','); + createDebug.enable(''); + return namespaces; + } + + /** + * Returns true if the given mode name is enabled, false otherwise. + * + * @param {String} name + * @return {Boolean} + * @api public + */ + function enabled(name) { + if (name[name.length - 1] === '*') { + return true; + } + + let i; + let len; + + for (i = 0, len = createDebug.skips.length; i < len; i++) { + if (createDebug.skips[i].test(name)) { + return false; + } + } + + for (i = 0, len = createDebug.names.length; i < len; i++) { + if (createDebug.names[i].test(name)) { + return true; + } + } + + return false; + } + + /** + * Convert regexp to namespace + * + * @param {RegExp} regxep + * @return {String} namespace + * @api private + */ + function toNamespace(regexp) { + return regexp.toString() + .substring(2, regexp.toString().length - 2) + .replace(/\.\*\?$/, '*'); + } + + /** + * Coerce `val`. + * + * @param {Mixed} val + * @return {Mixed} + * @api private + */ + function coerce(val) { + if (val instanceof Error) { + return val.stack || val.message; + } + return val; + } + + /** + * XXX DO NOT USE. This is a temporary stub function. + * XXX It WILL be removed in the next major release. + */ + function destroy() { + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + + createDebug.enable(createDebug.load()); + + return createDebug; +} + +module.exports = setup; + +},{"ms":34}],34:[function(require,module,exports){ +/** + * Helpers. + */ + +var s = 1000; +var m = s * 60; +var h = m * 60; +var d = h * 24; +var w = d * 7; +var y = d * 365.25; + +/** + * Parse or format the given `val`. + * + * Options: + * + * - `long` verbose formatting [false] + * + * @param {String|Number} val + * @param {Object} [options] + * @throws {Error} throw an error if val is not a non-empty string or a number + * @return {String|Number} + * @api public + */ + +module.exports = function(val, options) { + options = options || {}; + var type = typeof val; + if (type === 'string' && val.length > 0) { + return parse(val); + } else if (type === 'number' && isFinite(val)) { + return options.long ? fmtLong(val) : fmtShort(val); + } + throw new Error( + 'val is not a non-empty string or a valid number. val=' + + JSON.stringify(val) + ); +}; + +/** + * Parse the given `str` and return milliseconds. + * + * @param {String} str + * @return {Number} + * @api private + */ + +function parse(str) { + str = String(str); + if (str.length > 100) { + return; + } + var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( + str + ); + if (!match) { + return; + } + var n = parseFloat(match[1]); + var type = (match[2] || 'ms').toLowerCase(); + switch (type) { + case 'years': + case 'year': + case 'yrs': + case 'yr': + case 'y': + return n * y; + case 'weeks': + case 'week': + case 'w': + return n * w; + case 'days': + case 'day': + case 'd': + return n * d; + case 'hours': + case 'hour': + case 'hrs': + case 'hr': + case 'h': + return n * h; + case 'minutes': + case 'minute': + case 'mins': + case 'min': + case 'm': + return n * m; + case 'seconds': + case 'second': + case 'secs': + case 'sec': + case 's': + return n * s; + case 'milliseconds': + case 'millisecond': + case 'msecs': + case 'msec': + case 'ms': + return n; + default: + return undefined; + } +} + +/** + * Short format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtShort(ms) { + var msAbs = Math.abs(ms); + if (msAbs >= d) { + return Math.round(ms / d) + 'd'; + } + if (msAbs >= h) { + return Math.round(ms / h) + 'h'; + } + if (msAbs >= m) { + return Math.round(ms / m) + 'm'; + } + if (msAbs >= s) { + return Math.round(ms / s) + 's'; + } + return ms + 'ms'; +} + +/** + * Long format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtLong(ms) { + var msAbs = Math.abs(ms); + if (msAbs >= d) { + return plural(ms, msAbs, d, 'day'); + } + if (msAbs >= h) { + return plural(ms, msAbs, h, 'hour'); + } + if (msAbs >= m) { + return plural(ms, msAbs, m, 'minute'); + } + if (msAbs >= s) { + return plural(ms, msAbs, s, 'second'); + } + return ms + ' ms'; +} + +/** + * Pluralization helper. + */ + +function plural(ms, msAbs, n, name) { + var isPlural = msAbs >= n * 1.5; + return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); +} + +},{}],35:[function(require,module,exports){ +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + +},{}],36:[function(require,module,exports){ +var grammar = module.exports = { + v: [{ + name: 'version', + reg: /^(\d*)$/ + }], + o: [{ + // o=- 20518 0 IN IP4 203.0.113.1 + // NB: sessionId will be a String in most cases because it is huge + 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' + }], + // default parsing of these only (though some of these feel outdated) + s: [{ name: 'name' }], + i: [{ name: 'description' }], + u: [{ name: 'uri' }], + e: [{ name: 'email' }], + p: [{ name: 'phone' }], + z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly... + r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly + // k: [{}], // outdated thing ignored + t: [{ + // t=0 0 + name: 'timing', + reg: /^(\d*) (\d*)/, + names: ['start', 'stop'], + format: '%d %d' + }], + c: [{ + // c=IN IP4 10.47.197.26 + name: 'connection', + reg: /^IN IP(\d) (\S*)/, + names: ['version', 'ip'], + format: 'IN IP%d %s' + }], + b: [{ + // b=AS:4000 + push: 'bandwidth', + reg: /^(TIAS|AS|CT|RR|RS):(\d*)/, + names: ['type', 'limit'], + format: '%s:%s' + }], + m: [{ + // m=video 51744 RTP/AVP 126 97 98 34 31 + // NB: special - pushes to session + // TODO: rtp/fmtp should be filtered by the payloads found here? + reg: /^(\w*) (\d*) ([\w/]*)(?: (.*))?/, + names: ['type', 'port', 'protocol', 'payloads'], + format: '%s %d %s %s' + }], + a: [ + { + // a=rtpmap:110 opus/48000/2 + push: 'rtp', + reg: /^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/, + names: ['payload', 'codec', 'rate', 'encoding'], + format: function (o) { + return (o.encoding) + ? 'rtpmap:%d %s/%s/%s' + : o.rate + ? 'rtpmap:%d %s/%s' + : 'rtpmap:%d %s'; + } + }, + { + // a=fmtp:108 profile-level-id=24;object=23;bitrate=64000 + // a=fmtp:111 minptime=10; useinbandfec=1 + push: 'fmtp', + reg: /^fmtp:(\d*) ([\S| ]*)/, + names: ['payload', 'config'], + format: 'fmtp:%d %s' + }, + { + // a=control:streamid=0 + name: 'control', + reg: /^control:(.*)/, + format: 'control:%s' + }, + { + // a=rtcp:65179 IN IP4 193.84.77.194 + name: 'rtcp', + reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/, + names: ['port', 'netType', 'ipVer', 'address'], + format: function (o) { + return (o.address != null) + ? 'rtcp:%d %s IP%d %s' + : 'rtcp:%d'; + } + }, + { + // a=rtcp-fb:98 trr-int 100 + push: 'rtcpFbTrrInt', + reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, + names: ['payload', 'value'], + format: 'rtcp-fb:%s trr-int %d' + }, + { + // a=rtcp-fb:98 nack rpsi + push: 'rtcpFb', + reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/, + names: ['payload', 'type', 'subtype'], + format: function (o) { + return (o.subtype != null) + ? 'rtcp-fb:%s %s %s' + : 'rtcp-fb:%s %s'; + } + }, + { + // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset + // a=extmap:1/recvonly URI-gps-string + // a=extmap:3 urn:ietf:params:rtp-hdrext:encrypt urn:ietf:params:rtp-hdrext:smpte-tc 25@600/24 + push: 'ext', + reg: /^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/, + names: ['value', 'direction', 'encrypt-uri', 'uri', 'config'], + format: function (o) { + return ( + 'extmap:%d' + + (o.direction ? '/%s' : '%v') + + (o['encrypt-uri'] ? ' %s' : '%v') + + ' %s' + + (o.config ? ' %s' : '') + ); + } + }, + { + // a=extmap-allow-mixed + name: 'extmapAllowMixed', + reg: /^(extmap-allow-mixed)/ + }, + { + // a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32 + push: 'crypto', + reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/, + names: ['id', 'suite', 'config', 'sessionConfig'], + format: function (o) { + return (o.sessionConfig != null) + ? 'crypto:%d %s %s %s' + : 'crypto:%d %s %s'; + } + }, + { + // a=setup:actpass + name: 'setup', + reg: /^setup:(\w*)/, + format: 'setup:%s' + }, + { + // a=connection:new + name: 'connectionType', + reg: /^connection:(new|existing)/, + format: 'connection:%s' + }, + { + // a=mid:1 + name: 'mid', + reg: /^mid:([^\s]*)/, + format: 'mid:%s' + }, + { + // a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a + name: 'msid', + reg: /^msid:(.*)/, + format: 'msid:%s' + }, + { + // a=ptime:20 + name: 'ptime', + reg: /^ptime:(\d*(?:\.\d*)*)/, + format: 'ptime:%d' + }, + { + // a=maxptime:60 + name: 'maxptime', + reg: /^maxptime:(\d*(?:\.\d*)*)/, + format: 'maxptime:%d' + }, + { + // a=sendrecv + name: 'direction', + reg: /^(sendrecv|recvonly|sendonly|inactive)/ + }, + { + // a=ice-lite + name: 'icelite', + reg: /^(ice-lite)/ + }, + { + // a=ice-ufrag:F7gI + name: 'iceUfrag', + reg: /^ice-ufrag:(\S*)/, + format: 'ice-ufrag:%s' + }, + { + // a=ice-pwd:x9cml/YzichV2+XlhiMu8g + name: 'icePwd', + reg: /^ice-pwd:(\S*)/, + format: 'ice-pwd:%s' + }, + { + // a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33 + name: 'fingerprint', + reg: /^fingerprint:(\S*) (\S*)/, + names: ['type', 'hash'], + format: 'fingerprint:%s %s' + }, + { + // a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host + // a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10 + // a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0 network-id 3 network-cost 10 + // a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10 + // a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0 network-id 3 network-cost 10 + 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 (o) { + var str = 'candidate:%s %d %s %d %s %d typ %s'; + + str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v'; + + // NB: candidate has three optional chunks, so %void middles one if it's missing + str += (o.tcptype != null) ? ' tcptype %s' : '%v'; + + if (o.generation != null) { + str += ' generation %d'; + } + + str += (o['network-id'] != null) ? ' network-id %d' : '%v'; + str += (o['network-cost'] != null) ? ' network-cost %d' : '%v'; + return str; + } + }, + { + // a=end-of-candidates (keep after the candidates line for readability) + name: 'endOfCandidates', + reg: /^(end-of-candidates)/ + }, + { + // a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ... + name: 'remoteCandidates', + reg: /^remote-candidates:(.*)/, + format: 'remote-candidates:%s' + }, + { + // a=ice-options:google-ice + name: 'iceOptions', + reg: /^ice-options:(\S*)/, + format: 'ice-options:%s' + }, + { + // a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1 + push: 'ssrcs', + reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/, + names: ['id', 'attribute', 'value'], + format: function (o) { + var str = 'ssrc:%d'; + if (o.attribute != null) { + str += ' %s'; + if (o.value != null) { + str += ':%s'; + } + } + return str; + } + }, + { + // a=ssrc-group:FEC 1 2 + // a=ssrc-group:FEC-FR 3004364195 1080772241 + push: 'ssrcGroups', + // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E + reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/, + names: ['semantics', 'ssrcs'], + format: 'ssrc-group:%s %s' + }, + { + // a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV + name: 'msidSemantic', + reg: /^msid-semantic:\s?(\w*) (\S*)/, + names: ['semantic', 'token'], + format: 'msid-semantic: %s %s' // space after ':' is not accidental + }, + { + // a=group:BUNDLE audio video + push: 'groups', + reg: /^group:(\w*) (.*)/, + names: ['type', 'mids'], + format: 'group:%s %s' + }, + { + // a=rtcp-mux + name: 'rtcpMux', + reg: /^(rtcp-mux)/ + }, + { + // a=rtcp-rsize + name: 'rtcpRsize', + reg: /^(rtcp-rsize)/ + }, + { + // a=sctpmap:5000 webrtc-datachannel 1024 + name: 'sctpmap', + reg: /^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/, + names: ['sctpmapNumber', 'app', 'maxMessageSize'], + format: function (o) { + return (o.maxMessageSize != null) + ? 'sctpmap:%s %s %s' + : 'sctpmap:%s %s'; + } + }, + { + // a=x-google-flag:conference + name: 'xGoogleFlag', + reg: /^x-google-flag:([^\s]*)/, + format: 'x-google-flag:%s' + }, + { + // a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0 + push: 'rids', + reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/, + names: ['id', 'direction', 'params'], + format: function (o) { + return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s'; + } + }, + { + // a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250] + // a=imageattr:* send [x=800,y=640] recv * + // a=imageattr:100 recv [x=320,y=240] + push: 'imageattrs', + reg: new RegExp( + // a=imageattr:97 + '^imageattr:(\\d+|\\*)' + + // send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] + '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' + + // recv [x=330,y=250] + '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?' + ), + names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'], + format: function (o) { + return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : ''); + } + }, + { + // a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8 + // a=simulcast:recv 1;4,5 send 6;7 + name: 'simulcast', + reg: new RegExp( + // a=simulcast: + '^simulcast:' + + // send 1,2,3;~4,~5 + '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' + + // space + recv 6;~7,~8 + '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' + + // end + '$' + ), + names: ['dir1', 'list1', 'dir2', 'list2'], + format: function (o) { + return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : ''); + } + }, + { + // old simulcast draft 03 (implemented by Firefox) + // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03 + // a=simulcast: recv pt=97;98 send pt=97 + // a=simulcast: send rid=5;6;7 paused=6,7 + name: 'simulcast_03', + reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/, + names: ['value'], + format: 'simulcast: %s' + }, + { + // a=framerate:25 + // a=framerate:29.97 + name: 'framerate', + reg: /^framerate:(\d+(?:$|\.\d+))/, + format: 'framerate:%s' + }, + { + // RFC4570 + // a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5 + 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' + }, + { + // a=bundle-only + name: 'bundleOnly', + reg: /^(bundle-only)/ + }, + { + // a=label:1 + name: 'label', + reg: /^label:(.+)/, + format: 'label:%s' + }, + { + // RFC version 26 for SCTP over DTLS + // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5 + name: 'sctpPort', + reg: /^sctp-port:(\d+)$/, + format: 'sctp-port:%s' + }, + { + // RFC version 26 for SCTP over DTLS + // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6 + name: 'maxMessageSize', + reg: /^max-message-size:(\d+)$/, + format: 'max-message-size:%s' + }, + { + // RFC7273 + // a=ts-refclk:ptp=IEEE1588-2008:39-A7-94-FF-FE-07-CB-D0:37 + push:'tsRefClocks', + reg: /^ts-refclk:([^\s=]*)(?:=(\S*))?/, + names: ['clksrc', 'clksrcExt'], + format: function (o) { + return 'ts-refclk:%s' + (o.clksrcExt != null ? '=%s' : ''); + } + }, + { + // RFC7273 + // a=mediaclk:direct=963214424 + name:'mediaClk', + reg: /^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/, + names: ['id', 'mediaClockName', 'mediaClockValue', 'rateNumerator', 'rateDenominator'], + format: function (o) { + var str = 'mediaclk:'; + str += (o.id != null ? 'id=%s %s' : '%v%s'); + str += (o.mediaClockValue != null ? '=%s' : ''); + str += (o.rateNumerator != null ? ' rate=%s' : ''); + str += (o.rateDenominator != null ? '/%s' : ''); + return str; + } + }, + { + // a=keywds:keywords + name: 'keywords', + reg: /^keywds:(.+)$/, + format: 'keywds:%s' + }, + { + // a=content:main + name: 'content', + reg: /^content:(.+)/, + format: 'content:%s' + }, + // BFCP https://tools.ietf.org/html/rfc4583 + { + // a=floorctrl:c-s + name: 'bfcpFloorCtrl', + reg: /^floorctrl:(c-only|s-only|c-s)/, + format: 'floorctrl:%s' + }, + { + // a=confid:1 + name: 'bfcpConfId', + reg: /^confid:(\d+)/, + format: 'confid:%s' + }, + { + // a=userid:1 + name: 'bfcpUserId', + reg: /^userid:(\d+)/, + format: 'userid:%s' + }, + { + // a=floorid:1 + name: 'bfcpFloorId', + reg: /^floorid:(.+) (?:m-stream|mstrm):(.+)/, + names: ['id', 'mStream'], + format: 'floorid:%s mstrm:%s' + }, + { + // any a= that we don't understand is kept verbatim on media.invalid + push: 'invalid', + names: ['value'] + } + ] +}; + +// set sensible defaults to avoid polluting the grammar with boring details +Object.keys(grammar).forEach(function (key) { + var objs = grammar[key]; + objs.forEach(function (obj) { + if (!obj.reg) { + obj.reg = /(.*)/; + } + if (!obj.format) { + obj.format = '%s'; + } + }); +}); + +},{}],37:[function(require,module,exports){ +var parser = require('./parser'); +var writer = require('./writer'); + +exports.write = writer; +exports.parse = parser.parse; +exports.parseParams = parser.parseParams; +exports.parseFmtpConfig = parser.parseFmtpConfig; // Alias of parseParams(). +exports.parsePayloads = parser.parsePayloads; +exports.parseRemoteCandidates = parser.parseRemoteCandidates; +exports.parseImageAttributes = parser.parseImageAttributes; +exports.parseSimulcastStreamList = parser.parseSimulcastStreamList; + +},{"./parser":38,"./writer":39}],38:[function(require,module,exports){ +var toIntIfInt = function (v) { + return String(Number(v)) === v ? Number(v) : v; +}; + +var attachProperties = function (match, location, names, rawName) { + if (rawName && !names) { + location[rawName] = toIntIfInt(match[1]); + } + else { + for (var i = 0; i < names.length; i += 1) { + if (match[i+1] != null) { + location[names[i]] = toIntIfInt(match[i+1]); + } + } + } +}; + +var parseReg = function (obj, location, content) { + var needsBlank = obj.name && obj.names; + if (obj.push && !location[obj.push]) { + location[obj.push] = []; + } + else if (needsBlank && !location[obj.name]) { + location[obj.name] = {}; + } + var keyLocation = obj.push ? + {} : // blank object that will be pushed + needsBlank ? location[obj.name] : location; // otherwise, named location or root + + attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name); + + if (obj.push) { + location[obj.push].push(keyLocation); + } +}; + +var grammar = require('./grammar'); +var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/); + +exports.parse = function (sdp) { + var session = {} + , media = [] + , location = session; // points at where properties go under (one of the above) + + // parse lines we understand + sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) { + var type = l[0]; + var content = l.slice(2); + if (type === 'm') { + media.push({rtp: [], fmtp: []}); + location = media[media.length-1]; // point at latest media line + } + + for (var j = 0; j < (grammar[type] || []).length; j += 1) { + var obj = grammar[type][j]; + if (obj.reg.test(content)) { + return parseReg(obj, location, content); + } + } + }); + + session.media = media; // link it up + return session; +}; + +var paramReducer = function (acc, expr) { + var s = expr.split(/=(.+)/, 2); + if (s.length === 2) { + acc[s[0]] = toIntIfInt(s[1]); + } else if (s.length === 1 && expr.length > 1) { + acc[s[0]] = undefined; + } + return acc; +}; + +exports.parseParams = function (str) { + return str.split(/;\s?/).reduce(paramReducer, {}); +}; + +// For backward compatibility - alias will be removed in 3.0.0 +exports.parseFmtpConfig = exports.parseParams; + +exports.parsePayloads = function (str) { + return str.toString().split(' ').map(Number); +}; + +exports.parseRemoteCandidates = function (str) { + var candidates = []; + var parts = str.split(' ').map(toIntIfInt); + for (var i = 0; i < parts.length; i += 3) { + candidates.push({ + component: parts[i], + ip: parts[i + 1], + port: parts[i + 2] + }); + } + return candidates; +}; + +exports.parseImageAttributes = function (str) { + return str.split(' ').map(function (item) { + return item.substring(1, item.length-1).split(',').reduce(paramReducer, {}); + }); +}; + +exports.parseSimulcastStreamList = function (str) { + return str.split(';').map(function (stream) { + return stream.split(',').map(function (format) { + var scid, paused = false; + + if (format[0] !== '~') { + scid = toIntIfInt(format); + } else { + scid = toIntIfInt(format.substring(1, format.length)); + paused = true; + } + + return { + scid: scid, + paused: paused + }; + }); + }); +}; + +},{"./grammar":36}],39:[function(require,module,exports){ +var grammar = require('./grammar'); + +// customized util.format - discards excess arguments and can void middle ones +var formatRegExp = /%[sdv%]/g; +var format = function (formatStr) { + var i = 1; + var args = arguments; + var len = args.length; + return formatStr.replace(formatRegExp, function (x) { + if (i >= len) { + return x; // missing argument + } + var arg = args[i]; + i += 1; + switch (x) { + case '%%': + return '%'; + case '%s': + return String(arg); + case '%d': + return Number(arg); + case '%v': + return ''; + } + }); + // NB: we discard excess arguments - they are typically undefined from makeLine +}; + +var makeLine = function (type, obj, location) { + var str = obj.format instanceof Function ? + (obj.format(obj.push ? location : location[obj.name])) : + obj.format; + + var args = [type + '=' + str]; + if (obj.names) { + for (var i = 0; i < obj.names.length; i += 1) { + var n = obj.names[i]; + if (obj.name) { + args.push(location[obj.name][n]); + } + else { // for mLine and push attributes + args.push(location[obj.names[i]]); + } + } + } + else { + args.push(location[obj.name]); + } + return format.apply(null, args); +}; + +// RFC specified order +// TODO: extend this with all the rest +var defaultOuterOrder = [ + 'v', 'o', 's', 'i', + 'u', 'e', 'p', 'c', + 'b', 't', 'r', 'z', 'a' +]; +var defaultInnerOrder = ['i', 'c', 'b', 'a']; + + +module.exports = function (session, opts) { + opts = opts || {}; + // ensure certain properties exist + if (session.version == null) { + session.version = 0; // 'v=0' must be there (only defined version atm) + } + if (session.name == null) { + session.name = ' '; // 's= ' must be there if no meaningful name set + } + session.media.forEach(function (mLine) { + if (mLine.payloads == null) { + mLine.payloads = ''; + } + }); + + var outerOrder = opts.outerOrder || defaultOuterOrder; + var innerOrder = opts.innerOrder || defaultInnerOrder; + var sdp = []; + + // loop through outerOrder for matching properties on session + outerOrder.forEach(function (type) { + grammar[type].forEach(function (obj) { + if (obj.name in session && session[obj.name] != null) { + sdp.push(makeLine(type, obj, session)); + } + else if (obj.push in session && session[obj.push] != null) { + session[obj.push].forEach(function (el) { + sdp.push(makeLine(type, obj, el)); + }); + } + }); + }); + + // then for each media line, follow the innerOrder + session.media.forEach(function (mLine) { + sdp.push(makeLine('m', grammar.m[0], mLine)); + + innerOrder.forEach(function (type) { + grammar[type].forEach(function (obj) { + if (obj.name in mLine && mLine[obj.name] != null) { + sdp.push(makeLine(type, obj, mLine)); + } + else if (obj.push in mLine && mLine[obj.push] != null) { + mLine[obj.push].forEach(function (el) { + sdp.push(makeLine(type, obj, el)); + }); + } + }); + }); + }); + + return sdp.join('\r\n') + '\r\n'; +}; + +},{"./grammar":36}],40:[function(require,module,exports){ +module.exports={ + "name": "jssip", + "title": "JsSIP", + "description": "the Javascript SIP library", + "version": "3.7.5", + "homepage": "https://jssip.net", + "author": "José Luis Millán (https://github.com/jmillan)", + "contributors": [ + "Iñaki Baz Castillo (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.14.34", + "debug": "^4.3.1", + "events": "^3.3.0", + "sdp-transform": "^2.14.1" + }, + "devDependencies": { + "@babel/core": "^7.13.10", + "@babel/preset-env": "^7.13.10", + "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) +}); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 6d3fe9ca2..a71b08059 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.data={},n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n.is_terminated=!1,n.terminated_reason=void 0,n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){"pending"===this._state&&(f('set "active" state'),this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=_,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,f||(f=[]),r.headers=f.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){this._dialogTerminated("send un-subscribe");var e=["Event: ".concat(this.event_name),"Expires: 0"];this._send(null,e)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var e=["Event: ".concat(this.event_name),"Expires: 0"];this._send(null,e)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.d.ts b/lib/Notifier.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/lib/Notifier.js b/lib/Notifier.js index 5b6490dd5..30232bb3b 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -10,7 +10,10 @@ module.exports = class Notifier extends EventEmitter { constructor(ua, { subscribe, content_type, headers, credential, pending }) { + debug('new'); + super(); + this._ua = ua; this.expires_timestamp = null; this.expires_timer = null; @@ -19,20 +22,25 @@ module.exports = class Notifier extends EventEmitter this.is_first_notify_response = true; this.id = null; this.event_name = subscribe.getHeader('event'); - this.content_type = content_type; + if (!content_type) + { throw new TypeError('content_type is undefined'); + } + + this.content_type = content_type; this.expires = parseInt(subscribe.getHeader('expires')); this.credential = credential; + const user = subscribe.to.uri.user; const domain = subscribe.to.uri.host; this.contact = ``; this.rcseq = subscribe.cseq; - this.data = {}; // Custom session empty object for high level use. this.headers = headers ? headers : []; this.target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); + this.params = { from : subscribe.to, from_tag : subscribe.to_tag, @@ -41,14 +49,21 @@ module.exports = class Notifier extends EventEmitter call_id : subscribe.call_id, cseq : Math.floor((Math.random() * 10000) + 1) }; + this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + debug('add dialog id=', this.id); this._ua.newDialog(this); + this._setExpiresTimestamp(); this._setExpiresTimer(); - subscribe.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); this.is_terminated = false; this.terminated_reason = undefined; + + // Custom session empty object for high level use. + this.data = {}; + + subscribe.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); } /** @@ -77,8 +92,11 @@ module.exports = class Notifier extends EventEmitter { this.is_first_notify_response = false; this.route_set = response.getHeaders('record-route').reverse(); + if (this.route_set.length > 0) + { this.params.route_set = this.route_set; + } } } else if (response.status_code >= 300) @@ -91,17 +109,20 @@ module.exports = class Notifier extends EventEmitter { if (request.method !== JsSIP_C.SUBSCRIBE) { - request.reply(405); // Method Not Allowed + request.reply(405); return; } + let h = request.getHeader('expires'); if (h === undefined || h === null) { - h = '900'; // Missed header Expires. RFC 6665 3.1.1. Set default expires value + // Missed header Expires. RFC 6665 3.1.1. Set default expires value + h = '900'; debug(`Missed expires header. Set by default ${h}`); } + this.expires = parseInt(h); request.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); @@ -128,15 +149,18 @@ module.exports = class Notifier extends EventEmitter */ setActiveState() { + debug('setActiveState()'); + if (this._state === 'pending') { - debug('set "active" state'); this._state = 'active'; } } sendNotify(body = null) { + debug('sendNotify()'); + let subs_state = this._state; if (this._state !== 'terminated') @@ -152,10 +176,12 @@ module.exports = class Notifier extends EventEmitter headers.push(`Subscription-State: ${subs_state}`); headers.push(`Event: ${this.event_name}`); + if (body) { headers.push(`Content-Type: ${this.content_type}`); } + this.params.cseq++; this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); @@ -163,8 +189,13 @@ module.exports = class Notifier extends EventEmitter sendFinalNotify(body = null, reason = null) { + debug('sendFinalNotify()'); + if (this.is_final_notify_sent) + { return; + } + this.is_final_notify_sent = true; this._dialogTerminated('send final notify'); this.terminated_reason = reason; @@ -180,18 +211,23 @@ module.exports = class Notifier extends EventEmitter * Private API. */ _dialogTerminated(reason) - { + { if (this.is_terminated) + { return; + } + this.is_terminated = true; this._state = 'terminated'; clearTimeout(this.expires_timer); + // If delay needed ? setTimeout(() => { debug('remove dialog id=', this.id); this._ua.destroyDialog(this); }, 32000); + debug(`emit "terminated" ${reason}"`); this.emit('terminated', reason); } @@ -214,7 +250,10 @@ module.exports = class Notifier extends EventEmitter setTimeout(() => { if (this.is_final_notify_sent) + { return; + } + this.terminated_reason = 'timeout'; this.is_final_notify_sent = true; this.sendNotify(); diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/lib/Subscriber.js b/lib/Subscriber.js index c8bb0779a..a80c2a60b 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -11,28 +11,59 @@ module.exports = class Subscriber extends EventEmitter constructor(ua, target, { event_name, accept, expires, content_type, allow_events, params, headers, credential }) { + debug('new'); + super(); + this._ua = ua; + if (!target) + { throw new TypeError('target is undefined'); + } + this.target = target; + if (!event_name) + { throw new TypeError('event_name is undefined'); + } + this.event_name = event_name; + if (!accept) + { throw new TypeError('accept is undefined'); + } + this.accept = accept; + if (!expires) + { expires = 900; + } + this.expires = expires; - this.allow_events = allow_events; // optional - this.content_type = content_type; // used to subscribe with body + this.allow_events = allow_events; + + // used to subscribe with body + this.content_type = content_type; + if (!params) + { throw new TypeError('params is undefined'); + } + if (!params.from_uri) + { throw new TypeError('params.from_uri is undefined'); + } + if (!params.to_uri) + { throw new TypeError('params.to_uri is undefined'); + } + this.params = params; params.from_tag = Utils.newTag(); params.to_tag = null; @@ -40,24 +71,42 @@ module.exports = class Subscriber extends EventEmitter params.cseq = Math.floor((Math.random() * 10000) + 1); this.contact = ``; // this.contact = ``; - this.credential = credential; // optional - this._state = 'init'; // init, notify_wait, pending, active, terminated - this.id = null; // dialog id - this.expires_timer = null; // to update subscription + + // Optional, used if credential is different from REGISTER/INVITE + this.credential = credential; + + // dialog state: init, notify_wait, pending, active, terminated + this._state = 'init'; + + // dialog id + this.id = null; + + // to refresh subscription + this.expires_timer = null; this.expires_timestamp = null; + if (!headers) + { headers = []; + } + this.headers = headers.concat([ `Event: ${this.event_name}`, `Accept: ${this.accept}`, `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); + if (this.allowEvents) + { this.headers.push(`Allow-Events: ${this.allowEvents}`); + } + this.is_terminated = false; this.route_set = null; - this.data = {}; // Custom session empty object for high level use. + + // Custom session empty object for high level use. + this.data = {}; } /** @@ -86,11 +135,16 @@ module.exports = class Subscriber extends EventEmitter { this.params.to_tag = response.to_tag; this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + debug('added dialog id=', this.id); this._ua.newDialog(this); + this.route_set = response.getHeaders('record-route').reverse(); + if (this.route_set.length > 0) + { this.params.route_set = this.route_set; + } } const expires = this._getExpires(response); @@ -100,6 +154,7 @@ module.exports = class Subscriber extends EventEmitter return; } + if (expires > 0) { this.expires_timestamp = new Date().getTime() + (expires * 1000); @@ -116,19 +171,21 @@ module.exports = class Subscriber extends EventEmitter { if (request.method !== JsSIP_C.NOTIFY) { - request.reply(405); // Method Not Allowed + request.reply(405); return; } + const subs_state = request.parseHeader('subscription-state'); if (!subs_state) { debugerror('missed header Subscription-State'); - request.reply(400); // Bad request + request.reply(400); return; } + request.reply(200); const new_state = subs_state.state.toLowerCase(); @@ -137,22 +194,25 @@ module.exports = class Subscriber extends EventEmitter if (prev_state !== 'terminated' && new_state !== 'terminated') { this._state = new_state; + if (subs_state.expires !== undefined) { const expires = subs_state.expires; const expires_timestamp = new Date().getTime() + (expires * 1000); const max_time_deviation = 2000; - // expiration shorter and the difference is not too small + // expiration time is shorter and the difference is not too small if (this.expires_timestamp - expires_timestamp > max_time_deviation) { debug('update sending re-SUBSCRIBE time'); + clearTimeout(this.expires_timer); this.expires_timestamp = expires_timestamp; this._scheduleSubscribe(this._calculateTimeoutMs(expires)); } } } + if (prev_state !== 'active' && new_state === 'active') { debug('emit "active"'); @@ -170,8 +230,11 @@ module.exports = class Subscriber extends EventEmitter debug('emit "notify"'); this.emit('notify', is_final, request, body, content_type); } + if (is_final) + { this._dialogTerminated('receive final notify'); + } } /** @@ -179,21 +242,30 @@ module.exports = class Subscriber extends EventEmitter */ subscribe(body = null) { + debug('subscribe()'); + if (this._state === 'init') + { this._state = 'notify_wait'; + } const headers = this.headers.slice(); if (body) { - if (!this.content_type) + if (!this.content_type) + { throw new TypeError('content_type is undefined'); + } headers.push(`Content-Type: ${this.content_type}`); } + this._send(body, headers); } unsubscribe() { + debug('unsubscribe()'); + this._dialogTerminated('send un-subscribe'); const headers = [ `Event: ${this.event_name}`, @@ -213,17 +285,24 @@ module.exports = class Subscriber extends EventEmitter */ _dialogTerminated(reason) { - if (this.is_terminated) // to prevent duplicate call + // to prevent duplicate emit terminated + if (this.is_terminated) + { return; + } + this.is_terminated = true; this._state = 'terminated'; clearTimeout(this.expires_timer); - // remove dialog from dialogs table with some delay, to allow receive end NOTIFY + + // remove dialog from dialogs table with some delay, to allow receiving final NOTIFY setTimeout(() => { debug('removed dialog id=', this.id); + this._ua.destroyDialog(this); }, 32000); + debug(`emit "terminated" ${reason}"`); this.emit('terminated', reason); } @@ -251,6 +330,7 @@ module.exports = class Subscriber extends EventEmitter _scheduleSubscribe(timeout) { debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); + this.expires_timer = setTimeout(() => { this.expires_timer = undefined; From fe32ca36aa75d69138732bbd99a3e8df81af94f9 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 21 May 2021 15:43:25 +0300 Subject: [PATCH 07/70] added *.ts definitions --- lib/Notifier.d.ts | 10 ++++++++++ lib/Subscriber.d.ts | 9 +++++++++ lib/Subscriber.js | 4 ++-- lib/UA.d.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/lib/Notifier.d.ts b/lib/Notifier.d.ts index e69de29bb..a1922e2b8 100644 --- a/lib/Notifier.d.ts +++ b/lib/Notifier.d.ts @@ -0,0 +1,10 @@ +import {EventEmitter} from 'events' +import {SUBSCRIBE, NOTIFY} from './Constants' +import * as Utils from './Utils' + +export class Notifier extends EventEmitter { + setActiveState(): void; + sendNotify(body?: string): void; + sendFinalNotify(body?: string, reason?: string): void; + get state(): string; +} \ No newline at end of file diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts index e69de29bb..ef94efc90 100644 --- a/lib/Subscriber.d.ts +++ b/lib/Subscriber.d.ts @@ -0,0 +1,9 @@ +import {EventEmitter} from 'events' +import {SUBSCRIBE, NOTIFY} from './Constants' +import * as Utils from './Utils' + +export class Subscriber extends EventEmitter { + subscribe(body?: string): void; + unsubscribe(body?: string): void; + get state(): string; +} \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index a80c2a60b..40b7422f0 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -262,7 +262,7 @@ module.exports = class Subscriber extends EventEmitter this._send(body, headers); } - unsubscribe() + unsubscribe(body = null) { debug('unsubscribe()'); @@ -272,7 +272,7 @@ module.exports = class Subscriber extends EventEmitter 'Expires: 0' ]; - this._send(null, headers); + this._send(body, headers); } get state() diff --git a/lib/UA.d.ts b/lib/UA.d.ts index e4f9f7a40..96b492073 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -6,6 +6,8 @@ import {AnswerOptions, AnyListener, Originator, RTCSession, RTCSessionEventMap, import {IncomingRequest, IncomingResponse, OutgoingRequest} from './SIPMessage' import {Message, SendMessageOptions} from './Message' import {Registrator} from './Registrator' +import {Notifier} from './Notifier' +import {Subscriber} from './Subscriber' import {URI} from './URI' import {causes} from './Constants' @@ -103,6 +105,7 @@ export type IncomingMessageListener = (event: IncomingMessageEvent) => void; export type OutgoingMessageListener = (event: OutgoingMessageEvent) => void; export type MessageListener = IncomingMessageListener | OutgoingMessageListener; export type SipEventListener = (event: { event: T; request: IncomingRequest; }) => void +export type SipSubscribeListener = (event: { event: T; request: IncomingRequest; }) => void export interface UAEventMap { connecting: UAConnectingListener; @@ -115,6 +118,7 @@ export interface UAEventMap { newRTCSession: RTCSessionListener; newMessage: MessageListener; sipEvent: SipEventListener; + newSubscribe: SipSubscribeListener; } export interface UAContactOptions { @@ -130,6 +134,44 @@ export interface UAContact { toString(options?: UAContactOptions): string } +export interface Credential { + authorization_user: string; + password: string; +} + +export interface RequestParams { + from_uri: URI; + from_display_name?: string; + from_tag: string; + to_uri: URI; + to_display_name?: string; + to_tag?: string; + call_id: string; + cseq: number; +} + +export interface SubscriberParams { + from_uri: URI; + from_display_name?: string; + to_uri: URI; + to_display_name?: string; +} + +export interface SubscriberOptions { + event_name: string; + accept: string; + expires: number; + content_type: string; + params: SubscriberParams; + credential: Credential; +} + +export interface NotifierOptions { + subscribe: IncomingRequest; + content_type: string; + pending?: boolean; +} + declare enum UAStatus { // UA status codes. STATUS_INIT = 0, @@ -166,6 +208,12 @@ export class UA extends EventEmitter { sendMessage(target: string | URI, body: string, options?: SendMessageOptions): Message; + sendRequest(method: string, target: string, params: RequestParams, headers?: string[], body?: string, handlers: any, credential: Credential): void; + + subscriber(target: string, options: SubscriberOptions): Subscriber; + + notifier(options: NotifierOptions): Notifier; + terminateSessions(options?: TerminateOptions): void; isRegistered(): boolean; From 1ceeb78e4adf6739096eac54c2df9a1ab1daf7a9 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 21 May 2021 15:43:25 +0300 Subject: [PATCH 08/70] added *.ts definitions --- dist/jssip.js | 7 ++++--- dist/jssip.min.js | 2 +- lib/Notifier.d.ts | 10 ++++++++++ lib/Subscriber.d.ts | 9 +++++++++ lib/Subscriber.js | 4 ++-- lib/UA.d.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 6 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index a741e02ef..133f5bac7 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16732,8 +16732,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var h = request.getHeader('expires'); if (h === undefined || h === null) { - h = '900'; // Missed header Expires. RFC 6665 3.1.1. Set default expires value - + // Missed header Expires. RFC 6665 3.1.1. Set default expires value + h = '900'; debug("Missed expires header. Set by default ".concat(h)); } @@ -22821,13 +22821,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "unsubscribe", value: function unsubscribe() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; debug('unsubscribe()'); this._dialogTerminated('send un-subscribe'); var headers = ["Event: ".concat(this.event_name), 'Expires: 0']; - this._send(null, headers); + this._send(body, headers); } }, { key: "state", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index a71b08059..1d3f64a9a 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var e=["Event: ".concat(this.event_name),"Expires: 0"];this._send(null,e)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.d.ts b/lib/Notifier.d.ts index e69de29bb..a1922e2b8 100644 --- a/lib/Notifier.d.ts +++ b/lib/Notifier.d.ts @@ -0,0 +1,10 @@ +import {EventEmitter} from 'events' +import {SUBSCRIBE, NOTIFY} from './Constants' +import * as Utils from './Utils' + +export class Notifier extends EventEmitter { + setActiveState(): void; + sendNotify(body?: string): void; + sendFinalNotify(body?: string, reason?: string): void; + get state(): string; +} \ No newline at end of file diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts index e69de29bb..ef94efc90 100644 --- a/lib/Subscriber.d.ts +++ b/lib/Subscriber.d.ts @@ -0,0 +1,9 @@ +import {EventEmitter} from 'events' +import {SUBSCRIBE, NOTIFY} from './Constants' +import * as Utils from './Utils' + +export class Subscriber extends EventEmitter { + subscribe(body?: string): void; + unsubscribe(body?: string): void; + get state(): string; +} \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index a80c2a60b..40b7422f0 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -262,7 +262,7 @@ module.exports = class Subscriber extends EventEmitter this._send(body, headers); } - unsubscribe() + unsubscribe(body = null) { debug('unsubscribe()'); @@ -272,7 +272,7 @@ module.exports = class Subscriber extends EventEmitter 'Expires: 0' ]; - this._send(null, headers); + this._send(body, headers); } get state() diff --git a/lib/UA.d.ts b/lib/UA.d.ts index e4f9f7a40..c3fea25b4 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -6,6 +6,8 @@ import {AnswerOptions, AnyListener, Originator, RTCSession, RTCSessionEventMap, import {IncomingRequest, IncomingResponse, OutgoingRequest} from './SIPMessage' import {Message, SendMessageOptions} from './Message' import {Registrator} from './Registrator' +import {Notifier} from './Notifier' +import {Subscriber} from './Subscriber' import {URI} from './URI' import {causes} from './Constants' @@ -103,6 +105,7 @@ export type IncomingMessageListener = (event: IncomingMessageEvent) => void; export type OutgoingMessageListener = (event: OutgoingMessageEvent) => void; export type MessageListener = IncomingMessageListener | OutgoingMessageListener; export type SipEventListener = (event: { event: T; request: IncomingRequest; }) => void +export type SipSubscribeListener = (event: { event: T; request: IncomingRequest; }) => void export interface UAEventMap { connecting: UAConnectingListener; @@ -115,6 +118,7 @@ export interface UAEventMap { newRTCSession: RTCSessionListener; newMessage: MessageListener; sipEvent: SipEventListener; + newSubscribe: SipSubscribeListener; } export interface UAContactOptions { @@ -130,6 +134,44 @@ export interface UAContact { toString(options?: UAContactOptions): string } +export interface Credential { + authorization_user: string; + password: string; +} + +export interface RequestParams { + from_uri: URI; + from_display_name?: string; + from_tag: string; + to_uri: URI; + to_display_name?: string; + to_tag?: string; + call_id: string; + cseq: number; +} + +export interface SubscriberParams { + from_uri: URI; + from_display_name?: string; + to_uri: URI; + to_display_name?: string; +} + +export interface SubscriberOptions { + event_name: string; + accept: string; + expires: number; + content_type: string; + params: SubscriberParams; + credential: Credential; +} + +export interface NotifierOptions { + subscribe: IncomingRequest; + content_type: string; + pending?: boolean; +} + declare enum UAStatus { // UA status codes. STATUS_INIT = 0, @@ -166,6 +208,12 @@ export class UA extends EventEmitter { sendMessage(target: string | URI, body: string, options?: SendMessageOptions): Message; + sendRequest(method: string, target: string, params: RequestParams, headers?: string[], body?: string, handlers?: any, credential?: Credential): void; + + subscriber(target: string, options: SubscriberOptions): Subscriber; + + notifier(options: NotifierOptions): Notifier; + terminateSessions(options?: TerminateOptions): void; isRegistered(): boolean; From 825d6ade8e8f062d677aee087549f38c11de7933 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 21 May 2021 18:25:33 +0300 Subject: [PATCH 09/70] subscriber/notifer contact changed --- dist/jssip.js | 8 +++----- dist/jssip.min.js | 2 +- lib/Notifier.js | 4 +--- lib/Subscriber.js | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 133f5bac7..57dd76b54 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16654,9 +16654,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.content_type = content_type; _this.expires = parseInt(subscribe.getHeader('expires')); _this.credential = credential; - var user = subscribe.to.uri.user; - var domain = subscribe.to.uri.host; - _this.contact = ""); + _this.contact = ""); _this.rcseq = subscribe.cseq; _this.headers = headers ? headers : []; _this.target = subscribe.from.uri.user; @@ -22654,8 +22652,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { params.to_tag = null; params.call_id = Utils.createRandomToken(20); params.cseq = Math.floor(Math.random() * 10000 + 1); - _this.contact = ""); // this.contact = ``; - // Optional, used if credential is different from REGISTER/INVITE + _this.contact = ""); + _this.contact += ";+sip.instance=\"\""); // Optional, used if credential is different from REGISTER/INVITE _this.credential = credential; // dialog state: init, notify_wait, pending, active, terminated diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 1d3f64a9a..ce2d5ccda 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 30232bb3b..21ee84545 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -32,10 +32,8 @@ module.exports = class Notifier extends EventEmitter this.expires = parseInt(subscribe.getHeader('expires')); this.credential = credential; - const user = subscribe.to.uri.user; - const domain = subscribe.to.uri.host; + this.contact = ``; - this.contact = ``; this.rcseq = subscribe.cseq; this.headers = headers ? headers : []; this.target = subscribe.from.uri.user; diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 40b7422f0..07fadf78c 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -70,7 +70,7 @@ module.exports = class Subscriber extends EventEmitter params.call_id = Utils.createRandomToken(20); params.cseq = Math.floor((Math.random() * 10000) + 1); this.contact = ``; - // this.contact = ``; + this.contact += `;+sip.instance=""`; // Optional, used if credential is different from REGISTER/INVITE this.credential = credential; From b8ab24c49c7b57302333f301eba1d816c02e1453 Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 22 May 2021 21:05:45 +0300 Subject: [PATCH 10/70] modified Allow-Events --- dist/jssip.js | 11 +++++++++-- dist/jssip.min.js | 2 +- lib/Notifier.js | 10 +++++++++- lib/Subscriber.js | 4 ++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 57dd76b54..ecf3b4939 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16631,6 +16631,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var subscribe = _ref.subscribe, content_type = _ref.content_type, headers = _ref.headers, + allow_events = _ref.allow_events, credential = _ref.credential, pending = _ref.pending; @@ -16645,6 +16646,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.is_final_notify_sent = false; _this.is_first_notify_response = true; _this.id = null; + _this.allow_events = allow_events; _this.event_name = subscribe.getHeader('event'); if (!content_type) { @@ -16657,6 +16659,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.contact = ""); _this.rcseq = subscribe.cseq; _this.headers = headers ? headers : []; + + if (_this.allow_events) { + _this.headers.push("Allow-Events: ".concat(_this.allow_events)); + } + _this.target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); _this.params = { @@ -22670,8 +22677,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.headers = headers.concat(["Event: ".concat(_this.event_name), "Accept: ".concat(_this.accept), "Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); - if (_this.allowEvents) { - _this.headers.push("Allow-Events: ".concat(_this.allowEvents)); + if (_this.allow_events) { + _this.headers.push("Allow-Events: ".concat(_this.allow_events)); } _this.is_terminated = false; diff --git a/dist/jssip.min.js b/dist/jssip.min.js index ce2d5ccda..560f63dd0 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allowEvents&&r.headers.push("Allow-Events: ".concat(r.allowEvents)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 21ee84545..9649fe77f 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -8,7 +8,8 @@ debugerror.log = console.warn.bind(console); module.exports = class Notifier extends EventEmitter { - constructor(ua, { subscribe, content_type, headers, credential, pending }) + constructor(ua, { subscribe, content_type, headers, allow_events, + credential, pending }) { debug('new'); @@ -21,6 +22,7 @@ module.exports = class Notifier extends EventEmitter this.is_final_notify_sent = false; this.is_first_notify_response = true; this.id = null; + this.allow_events = allow_events; this.event_name = subscribe.getHeader('event'); if (!content_type) @@ -36,6 +38,12 @@ module.exports = class Notifier extends EventEmitter this.rcseq = subscribe.cseq; this.headers = headers ? headers : []; + + if (this.allow_events) + { + this.headers.push(`Allow-Events: ${this.allow_events}`); + } + this.target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 07fadf78c..28589e6a0 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -97,9 +97,9 @@ module.exports = class Subscriber extends EventEmitter `Contact: ${this.contact}` ]); - if (this.allowEvents) + if (this.allow_events) { - this.headers.push(`Allow-Events: ${this.allowEvents}`); + this.headers.push(`Allow-Events: ${this.allow_events}`); } this.is_terminated = false; From 1e28648b902fb8a2f8a7e5bc184237d97d92184e Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 22 May 2021 21:55:50 +0300 Subject: [PATCH 11/70] added check if is_first_notify_request --- lib/Notifier.js | 3 +++ lib/Subscriber.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index 9649fe77f..447291ed7 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -6,6 +6,9 @@ const debugerror = require('debug')('JsSIP:ERROR:Notifier'); debugerror.log = console.warn.bind(console); +/** + * It's implementation of RFC 6665 Notifier + */ module.exports = class Notifier extends EventEmitter { constructor(ua, { subscribe, content_type, headers, allow_events, diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 28589e6a0..8c20dfe90 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -6,6 +6,9 @@ const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); debugerror.log = console.warn.bind(console); +/** + * It's implementation of RFC 6665 Subscriber + */ module.exports = class Subscriber extends EventEmitter { constructor(ua, target, { event_name, accept, expires, content_type, @@ -48,6 +51,7 @@ module.exports = class Subscriber extends EventEmitter // used to subscribe with body this.content_type = content_type; + this.is_first_notify_request = true; if (!params) { @@ -188,9 +192,15 @@ module.exports = class Subscriber extends EventEmitter request.reply(200); + if( this.is_first_notify_request ) + { + this.is_first_notify_request = false; + // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? + } + const new_state = subs_state.state.toLowerCase(); const prev_state = this._state; - + if (prev_state !== 'terminated' && new_state !== 'terminated') { this._state = new_state; From 55ea3ce05a65d87bbf6d9326848a368faa9621eb Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 23 May 2021 19:04:37 +0300 Subject: [PATCH 12/70] undefined params is supported --- dist/jssip.js | 41 ++++++++++++++++++++++++++--------------- dist/jssip.min.js | 2 +- lib/Subscriber.js | 39 ++++++++++++++++++--------------------- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index ecf3b4939..b602c5a25 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16619,6 +16619,9 @@ var debug = require('debug')('JsSIP:Notifier'); var debugerror = require('debug')('JsSIP:ERROR:Notifier'); debugerror.log = console.warn.bind(console); +/** + * It's implementation of RFC 6665 Notifier + */ module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(Notifier, _EventEmitter); @@ -22591,6 +22594,9 @@ var debug = require('debug')('JsSIP:Subscriber'); var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); debugerror.log = console.warn.bind(console); +/** + * It's implementation of RFC 6665 Subscriber + */ module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(Subscriber, _EventEmitter); @@ -22641,25 +22647,25 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.allow_events = allow_events; // used to subscribe with body _this.content_type = content_type; + _this.is_first_notify_request = true; + /** + * params is optional. + * It is used if the user or domain differ from those set in JsSIP.UA config. + * If used please define properties: + * to_uri, to_display_name, from_uri, from_display_name + */ - if (!params) { - throw new TypeError('params is undefined'); - } - - if (!params.from_uri) { - throw new TypeError('params.from_uri is undefined'); - } + _this.params = params ? Utils.cloneObject(params) : {}; - if (!params.to_uri) { - throw new TypeError('params.to_uri is undefined'); + if (!_this.params.from_uri) { + _this.params.from_uri = _this._ua.configuration.uri; } - _this.params = params; - params.from_tag = Utils.newTag(); - params.to_tag = null; - params.call_id = Utils.createRandomToken(20); - params.cseq = Math.floor(Math.random() * 10000 + 1); - _this.contact = ""); + _this.params.from_tag = Utils.newTag(); + _this.params.to_tag = null; + _this.params.call_id = Utils.createRandomToken(20); + _this.params.cseq = Math.floor(Math.random() * 10000 + 1); + _this.contact = ""); _this.contact += ";+sip.instance=\"\""); // Optional, used if credential is different from REGISTER/INVITE _this.credential = credential; // dialog state: init, notify_wait, pending, active, terminated @@ -22758,6 +22764,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } request.reply(200); + + if (this.is_first_notify_request) { + this.is_first_notify_request = false; // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? + } + var new_state = subs_state.state.toLowerCase(); var prev_state = this._state; diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 560f63dd0..2a2330473 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),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&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function We(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),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&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=b())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"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,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=b());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!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 b=S.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,LWS:E,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,maddr_param:Ee,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function b(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 E(){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 A(){var e;return e=null!==(e=E())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=E();null!==s;)r.push(s),s=E();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=E();null!==s;)r.push(s),s=E();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=E()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=E())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=b())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=b())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=C())&&null===(t=b())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=b())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ee())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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 be(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 Ee(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=b()),e}function ke(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=b()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=b());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=b());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=b());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=b()),e}function We(){var e;return null===(e=C())&&null===(e=b())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=b())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=b())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=b())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=b())&&null===(t=O())&&null===(t=k())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=b())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=E())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=E())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=bt()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function bt(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function Et(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=N())))),e}function Rt(){var e;return null===(e=wt())&&(e=bt()),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=bt()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=E()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=E()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=bt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=bt())?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=bt()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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=bt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=bt())?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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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=bt()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=N()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=bt()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=bt()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=bn())?(s=i,null!==(t=B())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function bn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function En(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=bt()),e}function In(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=E());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=E());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=bt()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new E("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new E("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!0,C.direction&&"sendrecv"!==C.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var S,b=s(o.getAudioTracks());try{for(b.s();!(S=b.n()).done;){var E=S.value;o.removeTrack(E)}}catch(e){b.e(e)}finally{b.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new b(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),b=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:b}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),E=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:b,AckClientTransaction:E,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 8c20dfe90..69c53b8cb 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -53,27 +53,24 @@ module.exports = class Subscriber extends EventEmitter this.content_type = content_type; this.is_first_notify_request = true; - if (!params) + /** + * params is optional. + * It is used if the user or domain differ from those set in JsSIP.UA config. + * If used please define properties: + * to_uri, to_display_name, from_uri, from_display_name + */ + this.params = params ? Utils.cloneObject(params) : {}; + + if (!this.params.from_uri) { - throw new TypeError('params is undefined'); + this.params.from_uri = this._ua.configuration.uri; } - if (!params.from_uri) - { - throw new TypeError('params.from_uri is undefined'); - } - - if (!params.to_uri) - { - throw new TypeError('params.to_uri is undefined'); - } - - this.params = params; - params.from_tag = Utils.newTag(); - params.to_tag = null; - params.call_id = Utils.createRandomToken(20); - params.cseq = Math.floor((Math.random() * 10000) + 1); - this.contact = ``; + this.params.from_tag = Utils.newTag(); + this.params.to_tag = null; + this.params.call_id = Utils.createRandomToken(20); + this.params.cseq = Math.floor((Math.random() * 10000) + 1); + this.contact = ``; this.contact += `;+sip.instance=""`; // Optional, used if credential is different from REGISTER/INVITE @@ -192,10 +189,10 @@ module.exports = class Subscriber extends EventEmitter request.reply(200); - if( this.is_first_notify_request ) + if (this.is_first_notify_request) { - this.is_first_notify_request = false; - // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? + this.is_first_notify_request = false; + // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? } const new_state = subs_state.state.toLowerCase(); From 0d5dcdc08a301175530ff3c0efe8c950b6534a64 Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 23 May 2021 20:33:26 +0300 Subject: [PATCH 13/70] Added comments for public methods --- dist/jssip.js | 97 ++++++++++++++++++++++++++++++++++++++--------- lib/Notifier.js | 39 +++++++++++++++++-- lib/Subscriber.js | 46 +++++++++++++++++----- lib/UA.d.ts | 11 ++++-- 4 files changed, 159 insertions(+), 34 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index b602c5a25..58f4cb711 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16628,6 +16628,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(Notifier); + /** + * -param {Object} ua JsSIP UA + * -param {Object} options + * -param {IncomingRequest} subscribe + * -param {String} content_type Content-Type header value + * -param {Array} headers Optional. Additional SIP headers. + * -param {String} allow_events Allow-Events header value. Optional. + * -param {Object} credential. Will have priority over ua.configuration. Optional. + * -param {Boolean} pending Set initial dialog state as "pending". Optional. + */ function Notifier(ua, _ref) { var _this; @@ -16668,7 +16678,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _this.target = subscribe.from.uri.user; - subscribe.to_tag = Utils.newTag(); + subscribe.to_tag = Utils.newTag(); // NOTIFY request params set according received SUBSCRIBE + _this.params = { from: subscribe.to, from_tag: subscribe.to_tag, @@ -16676,11 +16687,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { to_tag: subscribe.from_tag, call_id: subscribe.call_id, cseq: Math.floor(Math.random() * 10000 + 1) - }; + }; // Dialog id + _this.id = "".concat(_this.params.call_id).concat(_this.params.from_tag).concat(_this.params.to_tag); debug('add dialog id=', _this.id); - _this._ua.newDialog(_assertThisInitialized(_this)); + _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timerstamp and timer + _this._setExpiresTimestamp(); @@ -16694,7 +16707,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this; } /** - * Callbacks + * NOTIFY transactions callbacks */ @@ -16729,6 +16742,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._dialogTerminated('receive notify non-OK response'); } } + /** + * Dialog callback + */ + }, { key: "receiveRequest", value: function receiveRequest(request) { @@ -16765,6 +16782,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * User API */ + /** + * Switch pending dialog state to active + */ + }, { key: "setActiveState", value: function setActiveState() { @@ -16774,6 +16795,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._state = 'active'; } } + /** + * Send the initial and subsequent NOTIFY request + * -param {String} body. Optional. + */ + }, { key: "sendNotify", value: function sendNotify() { @@ -16799,6 +16825,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); } + /** + * Send the final NOTIFY request + * -param {String} body Optional. + * -param {String} reason To construct Subscription-State. Optional. + */ + }, { key: "sendFinalNotify", value: function sendFinalNotify() { @@ -16817,6 +16849,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.terminated_reason = reason; this.sendNotify(body); } + /** + * Get dialog state + */ + }, { key: "state", get: function get() { @@ -22603,6 +22639,20 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(Subscriber); + /** + * -param {Object} ua JsSIP UA + * -param {String} + * -param {Object} options + * -param {String} event_name Event header value + * -param {String} accept Accept header value + * -param {Number} expires Expires header value. Optional. Default is 900 + * -param {String} content_type Content-Type header value + * -param {String} allow_events Allow-Events header value. Optional. + * -param {Object} params Will have priority over ua.configuration. Optional. + * If set please define: to_uri, to_display_name, from_uri, from_display_name + * -param {Array} headers Optional. Additional SIP headers. + * -param {Object} credential. Will have priority over ua.configuration. Optional. + */ function Subscriber(ua, target, _ref) { var _this; @@ -22648,31 +22698,26 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.content_type = content_type; _this.is_first_notify_request = true; - /** - * params is optional. - * It is used if the user or domain differ from those set in JsSIP.UA config. - * If used please define properties: - * to_uri, to_display_name, from_uri, from_display_name - */ - _this.params = params ? Utils.cloneObject(params) : {}; if (!_this.params.from_uri) { _this.params.from_uri = _this._ua.configuration.uri; - } + } // set SUBSCRIBE dialog parameters + _this.params.from_tag = Utils.newTag(); _this.params.to_tag = null; _this.params.call_id = Utils.createRandomToken(20); - _this.params.cseq = Math.floor(Math.random() * 10000 + 1); + _this.params.cseq = Math.floor(Math.random() * 10000 + 1); // Create contact + _this.contact = ""); _this.contact += ";+sip.instance=\"\""); // Optional, used if credential is different from REGISTER/INVITE - _this.credential = credential; // dialog state: init, notify_wait, pending, active, terminated + _this.credential = credential; // Dialog state: init, notify_wait, pending, active, terminated - _this._state = 'init'; // dialog id + _this._state = 'init'; // Dialog id - _this.id = null; // to refresh subscription + _this.id = null; // To refresh subscription _this.expires_timer = null; _this.expires_timestamp = null; @@ -22694,7 +22739,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this; } /** - * Callbacks + * SUBSCRIBE transactions callbacks */ @@ -22747,6 +22792,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._dialogTerminated('receive subscribe non-OK response'); } } + /** + * Dialog callback + */ + }, { key: "receiveRequest", value: function receiveRequest(request) { @@ -22812,6 +22861,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * User API */ + /** + * Send the initial and subsequent SUBSCRIBE request + * -param {String} body. Optional. + */ + }, { key: "subscribe", value: function subscribe() { @@ -22834,6 +22888,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._send(body, headers); } + /** + * Send un-SUBSCRIBE + * -param {String} body. Optional. + */ + }, { key: "unsubscribe", value: function unsubscribe() { @@ -22846,6 +22905,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._send(body, headers); } + /** + * Get dialog state + */ + }, { key: "state", get: function get() { diff --git a/lib/Notifier.js b/lib/Notifier.js index 447291ed7..dd54bc84e 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -11,6 +11,16 @@ debugerror.log = console.warn.bind(console); */ module.exports = class Notifier extends EventEmitter { + /** + * -param {Object} ua JsSIP UA + * -param {Object} options + * -param {IncomingRequest} subscribe + * -param {String} content_type Content-Type header value + * -param {Array} headers Optional. Additional SIP headers. + * -param {String} allow_events Allow-Events header value. Optional. + * -param {Object} credential. Will have priority over ua.configuration. Optional. + * -param {Boolean} pending Set initial dialog state as "pending". Optional. + */ constructor(ua, { subscribe, content_type, headers, allow_events, credential, pending }) { @@ -50,6 +60,7 @@ module.exports = class Notifier extends EventEmitter this.target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); + // NOTIFY request params set according received SUBSCRIBE this.params = { from : subscribe.to, from_tag : subscribe.to_tag, @@ -59,13 +70,16 @@ module.exports = class Notifier extends EventEmitter cseq : Math.floor((Math.random() * 10000) + 1) }; + // Dialog id this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; debug('add dialog id=', this.id); this._ua.newDialog(this); + // Set expires timerstamp and timer this._setExpiresTimestamp(); this._setExpiresTimer(); + this.is_terminated = false; this.terminated_reason = undefined; @@ -76,7 +90,7 @@ module.exports = class Notifier extends EventEmitter } /** - * Callbacks + * NOTIFY transactions callbacks */ onAuthenticated() { @@ -114,6 +128,9 @@ module.exports = class Notifier extends EventEmitter } } + /** + * Dialog callback + */ receiveRequest(request) { if (request.method !== JsSIP_C.SUBSCRIBE) @@ -156,6 +173,10 @@ module.exports = class Notifier extends EventEmitter /** * User API */ + + /** + * Switch pending dialog state to active + */ setActiveState() { debug('setActiveState()'); @@ -166,6 +187,10 @@ module.exports = class Notifier extends EventEmitter } } + /** + * Send the initial and subsequent NOTIFY request + * -param {String} body. Optional. + */ sendNotify(body = null) { debug('sendNotify()'); @@ -195,7 +220,12 @@ module.exports = class Notifier extends EventEmitter this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); } - + + /** + * Send the final NOTIFY request + * -param {String} body Optional. + * -param {String} reason To construct Subscription-State. Optional. + */ sendFinalNotify(body = null, reason = null) { debug('sendFinalNotify()'); @@ -210,7 +240,10 @@ module.exports = class Notifier extends EventEmitter this.terminated_reason = reason; this.sendNotify(body); } - + + /** + * Get dialog state + */ get state() { return this._state; diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 69c53b8cb..b9bb90163 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -11,6 +11,20 @@ debugerror.log = console.warn.bind(console); */ module.exports = class Subscriber extends EventEmitter { + /** + * -param {Object} ua JsSIP UA + * -param {String} + * -param {Object} options + * -param {String} event_name Event header value + * -param {String} accept Accept header value + * -param {Number} expires Expires header value. Optional. Default is 900 + * -param {String} content_type Content-Type header value + * -param {String} allow_events Allow-Events header value. Optional. + * -param {Object} params Will have priority over ua.configuration. Optional. + * If set please define: to_uri, to_display_name, from_uri, from_display_name + * -param {Array} headers Optional. Additional SIP headers. + * -param {Object} credential. Will have priority over ua.configuration. Optional. + */ constructor(ua, target, { event_name, accept, expires, content_type, allow_events, params, headers, credential }) { @@ -53,12 +67,6 @@ module.exports = class Subscriber extends EventEmitter this.content_type = content_type; this.is_first_notify_request = true; - /** - * params is optional. - * It is used if the user or domain differ from those set in JsSIP.UA config. - * If used please define properties: - * to_uri, to_display_name, from_uri, from_display_name - */ this.params = params ? Utils.cloneObject(params) : {}; if (!this.params.from_uri) @@ -66,23 +74,26 @@ module.exports = class Subscriber extends EventEmitter this.params.from_uri = this._ua.configuration.uri; } + // set SUBSCRIBE dialog parameters this.params.from_tag = Utils.newTag(); this.params.to_tag = null; this.params.call_id = Utils.createRandomToken(20); this.params.cseq = Math.floor((Math.random() * 10000) + 1); + + // Create contact this.contact = ``; this.contact += `;+sip.instance=""`; // Optional, used if credential is different from REGISTER/INVITE this.credential = credential; - // dialog state: init, notify_wait, pending, active, terminated + // Dialog state: init, notify_wait, pending, active, terminated this._state = 'init'; - // dialog id + // Dialog id this.id = null; - // to refresh subscription + // To refresh subscription this.expires_timer = null; this.expires_timestamp = null; @@ -111,7 +122,7 @@ module.exports = class Subscriber extends EventEmitter } /** - * Callbacks + * SUBSCRIBE transactions callbacks */ onAuthenticated() { @@ -168,6 +179,9 @@ module.exports = class Subscriber extends EventEmitter } } + /** + * Dialog callback + */ receiveRequest(request) { if (request.method !== JsSIP_C.NOTIFY) @@ -247,6 +261,11 @@ module.exports = class Subscriber extends EventEmitter /** * User API */ + + /** + * Send the initial and subsequent SUBSCRIBE request + * -param {String} body. Optional. + */ subscribe(body = null) { debug('subscribe()'); @@ -269,6 +288,10 @@ module.exports = class Subscriber extends EventEmitter this._send(body, headers); } + /** + * Send un-SUBSCRIBE + * -param {String} body. Optional. + */ unsubscribe(body = null) { debug('unsubscribe()'); @@ -282,6 +305,9 @@ module.exports = class Subscriber extends EventEmitter this._send(body, headers); } + /** + * Get dialog state + */ get state() { return this._state; diff --git a/lib/UA.d.ts b/lib/UA.d.ts index 395ac38fd..2985d1397 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -160,16 +160,19 @@ export interface SubscriberParams { export interface SubscriberOptions { event_name: string; accept: string; - expires: number; - content_type: string; - params: SubscriberParams; - credential: Credential; + expires?: number; + content_type?: string; + params?: SubscriberParams; + headers?: string[]; + credential?: Credential; } export interface NotifierOptions { subscribe: IncomingRequest; content_type: string; + headers?: string[]; pending?: boolean; + credential?: Credential; } declare enum UAStatus { From d77e41cc1c9d84fc11cb1b0a93758f3fa2f1fdbb Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 23 May 2021 20:33:26 +0300 Subject: [PATCH 14/70] added public method comments --- dist/jssip.js | 97 ++++++++++++++++++++++++++++++++++++++--------- lib/Notifier.js | 39 +++++++++++++++++-- lib/Subscriber.js | 46 +++++++++++++++++----- lib/UA.d.ts | 11 ++++-- 4 files changed, 159 insertions(+), 34 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index b602c5a25..f53b5defd 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16628,6 +16628,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(Notifier); + /** + * -param {Object} ua JsSIP UA + * -param {Object} options + * -param {IncomingRequest} subscribe + * -param {String} content_type Content-Type header value + * -param {Array} headers Optional. Additional SIP headers. + * -param {String} allow_events Allow-Events header value. Optional. + * -param {Object} credential. Will have priority over ua.configuration. Optional. + * -param {Boolean} pending Set initial dialog state as "pending". Optional. + */ function Notifier(ua, _ref) { var _this; @@ -16668,7 +16678,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _this.target = subscribe.from.uri.user; - subscribe.to_tag = Utils.newTag(); + subscribe.to_tag = Utils.newTag(); // NOTIFY request params set according received SUBSCRIBE + _this.params = { from: subscribe.to, from_tag: subscribe.to_tag, @@ -16676,11 +16687,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { to_tag: subscribe.from_tag, call_id: subscribe.call_id, cseq: Math.floor(Math.random() * 10000 + 1) - }; + }; // Dialog id + _this.id = "".concat(_this.params.call_id).concat(_this.params.from_tag).concat(_this.params.to_tag); debug('add dialog id=', _this.id); - _this._ua.newDialog(_assertThisInitialized(_this)); + _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timerstamp and timer + _this._setExpiresTimestamp(); @@ -16694,7 +16707,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this; } /** - * Callbacks + * NOTIFY transactions callbacks */ @@ -16729,6 +16742,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._dialogTerminated('receive notify non-OK response'); } } + /** + * Dialog callback + */ + }, { key: "receiveRequest", value: function receiveRequest(request) { @@ -16765,6 +16782,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * User API */ + /** + * Switch pending dialog state to active + */ + }, { key: "setActiveState", value: function setActiveState() { @@ -16774,6 +16795,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._state = 'active'; } } + /** + * Send the initial and subsequent NOTIFY request + * -param {String} body. Optional. + */ + }, { key: "sendNotify", value: function sendNotify() { @@ -16799,6 +16825,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); } + /** + * Send the final NOTIFY request + * -param {String} body Optional. + * -param {String} reason To construct Subscription-State. Optional. + */ + }, { key: "sendFinalNotify", value: function sendFinalNotify() { @@ -16817,6 +16849,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.terminated_reason = reason; this.sendNotify(body); } + /** + * Get dialog state + */ + }, { key: "state", get: function get() { @@ -22603,6 +22639,20 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(Subscriber); + /** + * -param {Object} ua JsSIP UA + * -param {String} target + * -param {Object} options + * -param {String} event_name Event header value + * -param {String} accept Accept header value + * -param {Number} expires Expires header value. Optional. Default is 900 + * -param {String} content_type Content-Type header value + * -param {String} allow_events Allow-Events header value. Optional. + * -param {Object} params Will have priority over ua.configuration. Optional. + * If set please define: to_uri, to_display_name, from_uri, from_display_name + * -param {Array} headers Optional. Additional SIP headers. + * -param {Object} credential. Will have priority over ua.configuration. Optional. + */ function Subscriber(ua, target, _ref) { var _this; @@ -22648,31 +22698,26 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.content_type = content_type; _this.is_first_notify_request = true; - /** - * params is optional. - * It is used if the user or domain differ from those set in JsSIP.UA config. - * If used please define properties: - * to_uri, to_display_name, from_uri, from_display_name - */ - _this.params = params ? Utils.cloneObject(params) : {}; if (!_this.params.from_uri) { _this.params.from_uri = _this._ua.configuration.uri; - } + } // set SUBSCRIBE dialog parameters + _this.params.from_tag = Utils.newTag(); _this.params.to_tag = null; _this.params.call_id = Utils.createRandomToken(20); - _this.params.cseq = Math.floor(Math.random() * 10000 + 1); + _this.params.cseq = Math.floor(Math.random() * 10000 + 1); // Create contact + _this.contact = ""); _this.contact += ";+sip.instance=\"\""); // Optional, used if credential is different from REGISTER/INVITE - _this.credential = credential; // dialog state: init, notify_wait, pending, active, terminated + _this.credential = credential; // Dialog state: init, notify_wait, pending, active, terminated - _this._state = 'init'; // dialog id + _this._state = 'init'; // Dialog id - _this.id = null; // to refresh subscription + _this.id = null; // To refresh subscription _this.expires_timer = null; _this.expires_timestamp = null; @@ -22694,7 +22739,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this; } /** - * Callbacks + * SUBSCRIBE transactions callbacks */ @@ -22747,6 +22792,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._dialogTerminated('receive subscribe non-OK response'); } } + /** + * Dialog callback + */ + }, { key: "receiveRequest", value: function receiveRequest(request) { @@ -22812,6 +22861,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * User API */ + /** + * Send the initial and subsequent SUBSCRIBE request + * -param {String} body. Optional. + */ + }, { key: "subscribe", value: function subscribe() { @@ -22834,6 +22888,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._send(body, headers); } + /** + * Send un-SUBSCRIBE + * -param {String} body. Optional. + */ + }, { key: "unsubscribe", value: function unsubscribe() { @@ -22846,6 +22905,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._send(body, headers); } + /** + * Get dialog state + */ + }, { key: "state", get: function get() { diff --git a/lib/Notifier.js b/lib/Notifier.js index 447291ed7..dd54bc84e 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -11,6 +11,16 @@ debugerror.log = console.warn.bind(console); */ module.exports = class Notifier extends EventEmitter { + /** + * -param {Object} ua JsSIP UA + * -param {Object} options + * -param {IncomingRequest} subscribe + * -param {String} content_type Content-Type header value + * -param {Array} headers Optional. Additional SIP headers. + * -param {String} allow_events Allow-Events header value. Optional. + * -param {Object} credential. Will have priority over ua.configuration. Optional. + * -param {Boolean} pending Set initial dialog state as "pending". Optional. + */ constructor(ua, { subscribe, content_type, headers, allow_events, credential, pending }) { @@ -50,6 +60,7 @@ module.exports = class Notifier extends EventEmitter this.target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); + // NOTIFY request params set according received SUBSCRIBE this.params = { from : subscribe.to, from_tag : subscribe.to_tag, @@ -59,13 +70,16 @@ module.exports = class Notifier extends EventEmitter cseq : Math.floor((Math.random() * 10000) + 1) }; + // Dialog id this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; debug('add dialog id=', this.id); this._ua.newDialog(this); + // Set expires timerstamp and timer this._setExpiresTimestamp(); this._setExpiresTimer(); + this.is_terminated = false; this.terminated_reason = undefined; @@ -76,7 +90,7 @@ module.exports = class Notifier extends EventEmitter } /** - * Callbacks + * NOTIFY transactions callbacks */ onAuthenticated() { @@ -114,6 +128,9 @@ module.exports = class Notifier extends EventEmitter } } + /** + * Dialog callback + */ receiveRequest(request) { if (request.method !== JsSIP_C.SUBSCRIBE) @@ -156,6 +173,10 @@ module.exports = class Notifier extends EventEmitter /** * User API */ + + /** + * Switch pending dialog state to active + */ setActiveState() { debug('setActiveState()'); @@ -166,6 +187,10 @@ module.exports = class Notifier extends EventEmitter } } + /** + * Send the initial and subsequent NOTIFY request + * -param {String} body. Optional. + */ sendNotify(body = null) { debug('sendNotify()'); @@ -195,7 +220,12 @@ module.exports = class Notifier extends EventEmitter this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); } - + + /** + * Send the final NOTIFY request + * -param {String} body Optional. + * -param {String} reason To construct Subscription-State. Optional. + */ sendFinalNotify(body = null, reason = null) { debug('sendFinalNotify()'); @@ -210,7 +240,10 @@ module.exports = class Notifier extends EventEmitter this.terminated_reason = reason; this.sendNotify(body); } - + + /** + * Get dialog state + */ get state() { return this._state; diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 69c53b8cb..3ef790120 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -11,6 +11,20 @@ debugerror.log = console.warn.bind(console); */ module.exports = class Subscriber extends EventEmitter { + /** + * -param {Object} ua JsSIP UA + * -param {String} target + * -param {Object} options + * -param {String} event_name Event header value + * -param {String} accept Accept header value + * -param {Number} expires Expires header value. Optional. Default is 900 + * -param {String} content_type Content-Type header value + * -param {String} allow_events Allow-Events header value. Optional. + * -param {Object} params Will have priority over ua.configuration. Optional. + * If set please define: to_uri, to_display_name, from_uri, from_display_name + * -param {Array} headers Optional. Additional SIP headers. + * -param {Object} credential. Will have priority over ua.configuration. Optional. + */ constructor(ua, target, { event_name, accept, expires, content_type, allow_events, params, headers, credential }) { @@ -53,12 +67,6 @@ module.exports = class Subscriber extends EventEmitter this.content_type = content_type; this.is_first_notify_request = true; - /** - * params is optional. - * It is used if the user or domain differ from those set in JsSIP.UA config. - * If used please define properties: - * to_uri, to_display_name, from_uri, from_display_name - */ this.params = params ? Utils.cloneObject(params) : {}; if (!this.params.from_uri) @@ -66,23 +74,26 @@ module.exports = class Subscriber extends EventEmitter this.params.from_uri = this._ua.configuration.uri; } + // set SUBSCRIBE dialog parameters this.params.from_tag = Utils.newTag(); this.params.to_tag = null; this.params.call_id = Utils.createRandomToken(20); this.params.cseq = Math.floor((Math.random() * 10000) + 1); + + // Create contact this.contact = ``; this.contact += `;+sip.instance=""`; // Optional, used if credential is different from REGISTER/INVITE this.credential = credential; - // dialog state: init, notify_wait, pending, active, terminated + // Dialog state: init, notify_wait, pending, active, terminated this._state = 'init'; - // dialog id + // Dialog id this.id = null; - // to refresh subscription + // To refresh subscription this.expires_timer = null; this.expires_timestamp = null; @@ -111,7 +122,7 @@ module.exports = class Subscriber extends EventEmitter } /** - * Callbacks + * SUBSCRIBE transactions callbacks */ onAuthenticated() { @@ -168,6 +179,9 @@ module.exports = class Subscriber extends EventEmitter } } + /** + * Dialog callback + */ receiveRequest(request) { if (request.method !== JsSIP_C.NOTIFY) @@ -247,6 +261,11 @@ module.exports = class Subscriber extends EventEmitter /** * User API */ + + /** + * Send the initial and subsequent SUBSCRIBE request + * -param {String} body. Optional. + */ subscribe(body = null) { debug('subscribe()'); @@ -269,6 +288,10 @@ module.exports = class Subscriber extends EventEmitter this._send(body, headers); } + /** + * Send un-SUBSCRIBE + * -param {String} body. Optional. + */ unsubscribe(body = null) { debug('unsubscribe()'); @@ -282,6 +305,9 @@ module.exports = class Subscriber extends EventEmitter this._send(body, headers); } + /** + * Get dialog state + */ get state() { return this._state; diff --git a/lib/UA.d.ts b/lib/UA.d.ts index 395ac38fd..2985d1397 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -160,16 +160,19 @@ export interface SubscriberParams { export interface SubscriberOptions { event_name: string; accept: string; - expires: number; - content_type: string; - params: SubscriberParams; - credential: Credential; + expires?: number; + content_type?: string; + params?: SubscriberParams; + headers?: string[]; + credential?: Credential; } export interface NotifierOptions { subscribe: IncomingRequest; content_type: string; + headers?: string[]; pending?: boolean; + credential?: Credential; } declare enum UAStatus { From 7c935c446ebb6dcb52c9e8191bbdb4455e77bdee Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 24 May 2021 01:44:57 +0300 Subject: [PATCH 15/70] Notifier: termination reason changed to number --- dist/jssip.js | 77 +++++++++++++++++++++++++++++++---------------- dist/jssip.min.js | 2 +- lib/Notifier.js | 45 +++++++++++++++++++++------ lib/Subscriber.js | 17 ++++++----- 4 files changed, 97 insertions(+), 44 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index eef502f48..714610084 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16619,6 +16619,15 @@ var debug = require('debug')('JsSIP:Notifier'); var debugerror = require('debug')('JsSIP:ERROR:Notifier'); debugerror.log = console.warn.bind(console); +var C = { + // Termination reason + TERMINATED_NOTIFY_RESPONSE_TIMEOUT: 0, + TERMINATED_NOTIFY_TRANSPORT_ERROR: 1, + TERMINATED_NOTIFY_NON_OK_RESPONSE: 2, + TERMINATED_SEND_FINAL_NOTIFY: 3, + TERMINATED_RECEIVED_UNSUBSCRIBE: 4, + TERMINATED_SUBSCRIPTION_EXPIRED: 5 +}; /** * It's implementation of RFC 6665 Notifier */ @@ -16712,6 +16721,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _createClass(Notifier, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "onAuthenticated", value: function onAuthenticated() { this.params.cseq++; @@ -16719,12 +16733,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onRequestTimeout", value: function onRequestTimeout() { - this._dialogTerminated('notify response timeout'); + this._dialogTerminated(C.TERMINATED_NOTIFY_RESPONSE_TIMEOUT); } }, { key: "onTransportError", value: function onTransportError() { - this._dialogTerminated('notify transport error'); + this._dialogTerminated(C.TERMINATED_NOTIFY_TRANSPORT_ERROR); } }, { key: "onReceiveResponse", @@ -16739,7 +16753,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } } else if (response.status_code >= 300) { - this._dialogTerminated('receive notify non-OK response'); + this._dialogTerminated(C.TERMINATED_NOTIFY_NON_OK_RESPONSE); } } /** @@ -16771,7 +16785,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.emit('subscribe', is_unsubscribe, request, body, content_type); if (is_unsubscribe) { - this._dialogTerminated('receive un-subscribe'); + this._dialogTerminated(C.TERMINATED_RECEIVED_UNSUBSCRIBE); } else { this._setExpiresTimestamp(); @@ -16865,23 +16879,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_dialogTerminated", value: function _dialogTerminated(reason) { - var _this2 = this; - if (this.is_terminated) { return; } this.is_terminated = true; this._state = 'terminated'; - clearTimeout(this.expires_timer); // If delay needed ? + clearTimeout(this.expires_timer); - setTimeout(function () { - debug('remove dialog id=', _this2.id); + if (this.id) { + debug('remove dialog id=', this.id); + + this._ua.destroyDialog(this); + } - _this2._ua.destroyDialog(_this2); - }, 32000); - debug("emit \"terminated\" ".concat(reason, "\"")); - this.emit('terminated', reason); + var sendFinalNotify = reason === C.TERMINATED_RECEIVED_UNSUBSCRIBE || reason === C.TERMINATED_SUBSCRIPTION_EXPIRED; + debug("emit \"terminated\" ".concat(reason, ", sendFinalNotify=").concat(sendFinalNotify)); + this.emit('terminated', reason, sendFinalNotify); } }, { key: "_setExpiresTimestamp", @@ -16897,22 +16911,31 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_setExpiresTimer", value: function _setExpiresTimer() { - var _this3 = this; + var _this2 = this; clearTimeout(this.expires_timer); setTimeout(function () { - if (_this3.is_final_notify_sent) { + if (_this2.is_final_notify_sent) { return; } - _this3.terminated_reason = 'timeout'; - _this3.is_final_notify_sent = true; + _this2.terminated_reason = 'timeout'; + _this2.is_final_notify_sent = true; - _this3.sendNotify(); + _this2.sendNotify(); - _this3._dialogTerminated('subscription expired'); + _this2._dialogTerminated(C.TERMINATED_SUBSCRIPTION_EXPIRED); }, this.expires * 1000); } + }], [{ + key: "C", + get: + /** + * Expose C object. + */ + function get() { + return C; + } }]); return Notifier; @@ -22930,15 +22953,17 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.is_terminated = true; this._state = 'terminated'; - clearTimeout(this.expires_timer); // remove dialog from dialogs table with some delay, to allow receiving final NOTIFY + clearTimeout(this.expires_timer); // remove dialog with some delay to receiving possible final NOTIFY - setTimeout(function () { - debug('removed dialog id=', _this2.id); + if (this.id) { + setTimeout(function () { + debug('removed dialog id=', _this2.id); - _this2._ua.destroyDialog(_this2); - }, 32000); - debug("emit \"terminated\" ".concat(reason, "\"")); - this.emit('terminated', reason); + _this2._ua.destroyDialog(_this2); + }, 32000); + debug("emit \"terminated\" ".concat(reason, "\"")); + this.emit('terminated', reason); + } } }, { key: "_send", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 2a2330473..f5d2348a8 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:b,LWS:E,SWS:A,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&&u("[a-f]")));return e},token:N,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,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=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:be,maddr_param:Ee,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,segment:Ke,param:Ye,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),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&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function b(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 E(){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 A(){var e;return e=null!==(e=E())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=E();null!==s;)r.push(s),s=E();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=E();null!==s;)r.push(s),s=E();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function k(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?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&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=E()))),e}function Y(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=E())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=Ne())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=b())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=b())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=C())&&null===(t=b())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=b())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),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=be())&&null===(e=Ee())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"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&&u('"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 be(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 Ee(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=N())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=b()),e}function ke(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function Ne(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=C())&&(t=b()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=b());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=C())&&(t=b());null!==t;)e.push(t),null===(t=De())&&null===(t=C())&&(t=b());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=Ve())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=We())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=C())&&(e=b()),e}function We(){var e;return null===(e=C())&&null===(e=b())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function Ve(){var e,t,r,s,l,a;if(l=i,null!==(e=Ke())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=b())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=b())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=b())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(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=b())&&null===(t=O())&&null===(t=k())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=b())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=N())){for(t=[],l=i,null!==(n=E())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=E())&&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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=bt()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),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,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function bt(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function Et(){var e;return null===(e=N())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=N())))),e}function Rt(){var e;return null===(e=wt())&&(e=bt()),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=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&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function Nt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=N())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=N()),e}function Dt(){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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=bt()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=E()))if(null!==(r=Wt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Wt())?l=[l,a]:(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,a;if(l=i,null!==(e=N()))if(null!==(t=E()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){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 Wt(){var e;return null===(e=Vt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){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&&u('"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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=V())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=N())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=V())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=bt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=bt())?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=bt()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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=bt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=bt())?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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=N()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"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&&u('"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=bt()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=N()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=bt()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=Sn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=bt()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=N())&&null!==(r=D())&&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&&u('"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&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"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=bn())?(s=i,null!==(t=B())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function bn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function En(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=bt()),e}function In(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=k())&&(t=E());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=E());return e}function kn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=Nn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=Nn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=Nn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 xn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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 Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=bt()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=N())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("notify response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("notify transport error")}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated("receive notify non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated("receive un-subscribe"):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){f("remove dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated("subscription expired"))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new E("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new E("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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||(m=!0)),"video"===C.type&&(_=!0,C.direction&&"sendrecv"!==C.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var S,b=s(o.getAudioTracks());try{for(b.s();!(S=b.n()).done;){var E=S.value;o.removeTrack(E)}}catch(e){b.e(e)}finally{b.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var k=I.value;o.removeTrack(k)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);new C(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new b(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new C(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new S(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(C,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),b=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:b}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;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)}}}]),n}(),E=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return C}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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:}}}]),n}(),R=function(e){l(n,f);var t=u(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:"C",get:function(){return C}},{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())}}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:b,AckClientTransaction:E,NonInviteServerTransaction:A,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":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:D,SLASH:P,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:De,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:Be,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=D()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));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,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?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=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=De())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=Pe())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=S())&&(t=E());else e=null;return e}function De(){var e,t;for(e=[],null===(t=Pe())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=Pe())&&null===(t=S())&&(t=E());return e}function Pe(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=P()))if(null!==(n=Dt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Dt(){var e;return null===(e=xt())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=P())&&null!==(n=k())&&null!==(r=P())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Dn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.TERMINATED_NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.TERMINATED_NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.TERMINATED_NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.TERMINATED_RECEIVED_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.TERMINATED_RECEIVED_UNSUBSCRIBE||e===d.TERMINATED_SUBSCRIPTION_EXPIRED;f('emit "terminated" '.concat(e,", sendFinalNotify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.TERMINATED_SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index dd54bc84e..298eaba01 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -6,11 +6,34 @@ const debugerror = require('debug')('JsSIP:ERROR:Notifier'); debugerror.log = console.warn.bind(console); +const C = { + // Termination reason + TERMINATED_NOTIFY_RESPONSE_TIMEOUT : 0, + TERMINATED_NOTIFY_TRANSPORT_ERROR : 1, + TERMINATED_NOTIFY_NON_OK_RESPONSE : 2, + TERMINATED_SEND_FINAL_NOTIFY : 3, + TERMINATED_RECEIVED_UNSUBSCRIBE : 4, + TERMINATED_SUBSCRIPTION_EXPIRED : 5 +}; + /** * It's implementation of RFC 6665 Notifier */ module.exports = class Notifier extends EventEmitter { + /** + * Expose C object. + */ + static get C() + { + return C; + } + + get C() + { + return C; + } + /** * -param {Object} ua JsSIP UA * -param {Object} options @@ -99,12 +122,12 @@ module.exports = class Notifier extends EventEmitter onRequestTimeout() { - this._dialogTerminated('notify response timeout'); + this._dialogTerminated(C.TERMINATED_NOTIFY_RESPONSE_TIMEOUT); } onTransportError() { - this._dialogTerminated('notify transport error'); + this._dialogTerminated(C.TERMINATED_NOTIFY_TRANSPORT_ERROR); } onReceiveResponse(response) @@ -124,7 +147,7 @@ module.exports = class Notifier extends EventEmitter } else if (response.status_code >= 300) { - this._dialogTerminated('receive notify non-OK response'); + this._dialogTerminated(C.TERMINATED_NOTIFY_NON_OK_RESPONSE); } } @@ -161,7 +184,7 @@ module.exports = class Notifier extends EventEmitter if (is_unsubscribe) { - this._dialogTerminated('receive un-subscribe'); + this._dialogTerminated(C.TERMINATED_RECEIVED_UNSUBSCRIBE); } else { @@ -263,15 +286,17 @@ module.exports = class Notifier extends EventEmitter this._state = 'terminated'; clearTimeout(this.expires_timer); - // If delay needed ? - setTimeout(() => + if (this.id) { debug('remove dialog id=', this.id); this._ua.destroyDialog(this); - }, 32000); + } - debug(`emit "terminated" ${reason}"`); - this.emit('terminated', reason); + const sendFinalNotify = (reason === C.TERMINATED_RECEIVED_UNSUBSCRIBE + || reason === C.TERMINATED_SUBSCRIPTION_EXPIRED); + + debug(`emit "terminated" ${reason}, sendFinalNotify=${sendFinalNotify}`); + this.emit('terminated', reason, sendFinalNotify); } _setExpiresTimestamp() @@ -299,7 +324,7 @@ module.exports = class Notifier extends EventEmitter this.terminated_reason = 'timeout'; this.is_final_notify_sent = true; this.sendNotify(); - this._dialogTerminated('subscription expired'); + this._dialogTerminated(C.TERMINATED_SUBSCRIPTION_EXPIRED); }, this.expires * 1000); } }; \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 06582eed9..b353236ff 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -328,16 +328,19 @@ module.exports = class Subscriber extends EventEmitter this._state = 'terminated'; clearTimeout(this.expires_timer); - // remove dialog from dialogs table with some delay, to allow receiving final NOTIFY - setTimeout(() => + // remove dialog with some delay to receiving possible final NOTIFY + if (this.id) { - debug('removed dialog id=', this.id); + setTimeout(() => + { + debug('removed dialog id=', this.id); - this._ua.destroyDialog(this); - }, 32000); + this._ua.destroyDialog(this); + }, 32000); - debug(`emit "terminated" ${reason}"`); - this.emit('terminated', reason); + debug(`emit "terminated" ${reason}"`); + this.emit('terminated', reason); + } } _send(body, headers) From 89fe3d5d570d45d263e050487c994679b8936f04 Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 24 May 2021 11:56:11 +0300 Subject: [PATCH 16/70] Subscriber termination text changed to code --- dist/jssip.js | 76 ++++++++++++++++++++++++++++++++--------------- dist/jssip.min.js | 2 +- lib/Notifier.js | 36 +++++++++++----------- lib/Subscriber.js | 40 ++++++++++++++++++++----- 4 files changed, 104 insertions(+), 50 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 714610084..77e7812e6 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16619,14 +16619,17 @@ var debug = require('debug')('JsSIP:Notifier'); var debugerror = require('debug')('JsSIP:ERROR:Notifier'); debugerror.log = console.warn.bind(console); +/** + * Termination code + */ + var C = { - // Termination reason - TERMINATED_NOTIFY_RESPONSE_TIMEOUT: 0, - TERMINATED_NOTIFY_TRANSPORT_ERROR: 1, - TERMINATED_NOTIFY_NON_OK_RESPONSE: 2, - TERMINATED_SEND_FINAL_NOTIFY: 3, - TERMINATED_RECEIVED_UNSUBSCRIBE: 4, - TERMINATED_SUBSCRIPTION_EXPIRED: 5 + NOTIFY_RESPONSE_TIMEOUT: 0, + NOTIFY_TRANSPORT_ERROR: 1, + NOTIFY_NON_OK_RESPONSE: 2, + SEND_FINAL_NOTIFY: 3, + RECEIVED_UNSUBSCRIBE: 4, + SUBSCRIPTION_EXPIRED: 5 }; /** * It's implementation of RFC 6665 Notifier @@ -16733,12 +16736,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onRequestTimeout", value: function onRequestTimeout() { - this._dialogTerminated(C.TERMINATED_NOTIFY_RESPONSE_TIMEOUT); + this._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); } }, { key: "onTransportError", value: function onTransportError() { - this._dialogTerminated(C.TERMINATED_NOTIFY_TRANSPORT_ERROR); + this._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); } }, { key: "onReceiveResponse", @@ -16753,7 +16756,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } } else if (response.status_code >= 300) { - this._dialogTerminated(C.TERMINATED_NOTIFY_NON_OK_RESPONSE); + this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); } } /** @@ -16785,7 +16788,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.emit('subscribe', is_unsubscribe, request, body, content_type); if (is_unsubscribe) { - this._dialogTerminated(C.TERMINATED_RECEIVED_UNSUBSCRIBE); + this._dialogTerminated(C.RECEIVED_UNSUBSCRIBE); } else { this._setExpiresTimestamp(); @@ -16878,7 +16881,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_dialogTerminated", - value: function _dialogTerminated(reason) { + value: function _dialogTerminated(termination_code) { if (this.is_terminated) { return; } @@ -16893,9 +16896,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._ua.destroyDialog(this); } - var sendFinalNotify = reason === C.TERMINATED_RECEIVED_UNSUBSCRIBE || reason === C.TERMINATED_SUBSCRIPTION_EXPIRED; - debug("emit \"terminated\" ".concat(reason, ", sendFinalNotify=").concat(sendFinalNotify)); - this.emit('terminated', reason, sendFinalNotify); + var send_final_notify = termination_code === C.RECEIVED_UNSUBSCRIBE || termination_code === C.SUBSCRIPTION_EXPIRED; + debug("emit \"terminated\" termination code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); + this.emit('terminated', termination_code, send_final_notify); } }, { key: "_setExpiresTimestamp", @@ -16924,7 +16927,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this2.sendNotify(); - _this2._dialogTerminated(C.TERMINATED_SUBSCRIPTION_EXPIRED); + _this2._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this.expires * 1000); } }], [{ @@ -22653,6 +22656,17 @@ var debug = require('debug')('JsSIP:Subscriber'); var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); debugerror.log = console.warn.bind(console); +/** + * Termination code + */ + +var C = { + SUBSCRIBE_RESPONSE_TIMEOUT: 0, + SUBSCRIBE_TRANSPORT_ERROR: 1, + SUBSCRIBE_NON_OK_RESPONSE: 2, + SEND_UNSUBSCRIBE: 3, + RECEIVE_FINAL_NOTIFY: 4 +}; /** * It's implementation of RFC 6665 Subscriber */ @@ -22767,6 +22781,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _createClass(Subscriber, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "onAuthenticated", value: function onAuthenticated() { this.params.cseq++; @@ -22774,12 +22793,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onRequestTimeout", value: function onRequestTimeout() { - this._dialogTerminated('subscribe response timeout'); + this._dialogTerminated(C.SUBSCRIBE_RESPONSE_TIMEOUT); } }, { key: "onTransportError", value: function onTransportError() { - this._dialogTerminated('subscribe transport error'); + this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); } }, { key: "onReceiveResponse", @@ -22812,7 +22831,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._scheduleSubscribe(this._calculateTimeoutMs(expires)); } } else if (response.status_code >= 300) { - this._dialogTerminated('receive subscribe non-OK response'); + this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); } } /** @@ -22877,7 +22896,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (is_final) { - this._dialogTerminated('receive final notify'); + this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY); } } /** @@ -22922,7 +22941,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; debug('unsubscribe()'); - this._dialogTerminated('send un-subscribe'); + this._dialogTerminated(C.SEND_UNSUBSCRIBE); var headers = ["Event: ".concat(this.event_name), 'Expires: 0']; @@ -22943,7 +22962,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_dialogTerminated", - value: function _dialogTerminated(reason) { + value: function _dialogTerminated(termination_code) { var _this2 = this; // to prevent duplicate emit terminated @@ -22961,8 +22980,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this2._ua.destroyDialog(_this2); }, 32000); - debug("emit \"terminated\" ".concat(reason, "\"")); - this.emit('terminated', reason); + debug("emit \"terminated\" termination code=".concat(termination_code, "\"")); + this.emit('terminated', termination_code); } } }, { @@ -22995,6 +23014,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._send(null, _this3.headers); }, timeout); } + }], [{ + key: "C", + get: + /** + * Expose C object. + */ + function get() { + return C; + } }]); return Subscriber; diff --git a/dist/jssip.min.js b/dist/jssip.min.js index f5d2348a8..2580ce5ab 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:D,SLASH:P,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:B,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:De,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:Be,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=D()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));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,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?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=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=De())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=Pe())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=S())&&(t=E());else e=null;return e}function De(){var e,t;for(e=[],null===(t=Pe())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=Pe())&&null===(t=S())&&(t=E());return e}function Pe(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Be();null!==n;)t.push(n),n=Be();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Be(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Be();null!==t;)e.push(t),t=Be();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=P()))if(null!==(n=Dt())){for(r=[],a=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Dt(){var e;return null===(e=xt())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Bt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Bt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Bt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=P())&&null!==(n=k())&&null!==(r=P())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=B())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Dn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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),Bn=Gn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.TERMINATED_NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.TERMINATED_NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.TERMINATED_NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.TERMINATED_RECEIVED_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.TERMINATED_RECEIVED_UNSUBSCRIBE||e===d.TERMINATED_SUBSCRIPTION_EXPIRED;f('emit "terminated" '.concat(e,", sendFinalNotify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.TERMINATED_SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,_||(_=[]),r.headers=_.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=d,(n=[{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated("subscribe response timeout")}},{key:"onTransportError",value:function(){this._dialogTerminated("subscribe transport error")}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated("receive subscribe non-OK response")}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated("receive final notify")}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated("send un-subscribe");var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" '.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVED_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVED_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,d||(d=[]),r.headers=d.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(d.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated(d.RECEIVE_FINAL_NOTIFY)}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated(d.SEND_UNSUBSCRIBE);var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 298eaba01..a61a5981d 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -6,14 +6,16 @@ const debugerror = require('debug')('JsSIP:ERROR:Notifier'); debugerror.log = console.warn.bind(console); +/** + * Termination code + */ const C = { - // Termination reason - TERMINATED_NOTIFY_RESPONSE_TIMEOUT : 0, - TERMINATED_NOTIFY_TRANSPORT_ERROR : 1, - TERMINATED_NOTIFY_NON_OK_RESPONSE : 2, - TERMINATED_SEND_FINAL_NOTIFY : 3, - TERMINATED_RECEIVED_UNSUBSCRIBE : 4, - TERMINATED_SUBSCRIPTION_EXPIRED : 5 + NOTIFY_RESPONSE_TIMEOUT : 0, + NOTIFY_TRANSPORT_ERROR : 1, + NOTIFY_NON_OK_RESPONSE : 2, + SEND_FINAL_NOTIFY : 3, + RECEIVED_UNSUBSCRIBE : 4, + SUBSCRIPTION_EXPIRED : 5 }; /** @@ -122,12 +124,12 @@ module.exports = class Notifier extends EventEmitter onRequestTimeout() { - this._dialogTerminated(C.TERMINATED_NOTIFY_RESPONSE_TIMEOUT); + this._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); } onTransportError() { - this._dialogTerminated(C.TERMINATED_NOTIFY_TRANSPORT_ERROR); + this._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); } onReceiveResponse(response) @@ -147,7 +149,7 @@ module.exports = class Notifier extends EventEmitter } else if (response.status_code >= 300) { - this._dialogTerminated(C.TERMINATED_NOTIFY_NON_OK_RESPONSE); + this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); } } @@ -184,7 +186,7 @@ module.exports = class Notifier extends EventEmitter if (is_unsubscribe) { - this._dialogTerminated(C.TERMINATED_RECEIVED_UNSUBSCRIBE); + this._dialogTerminated(C.RECEIVED_UNSUBSCRIBE); } else { @@ -275,7 +277,7 @@ module.exports = class Notifier extends EventEmitter /** * Private API. */ - _dialogTerminated(reason) + _dialogTerminated(termination_code) { if (this.is_terminated) { @@ -292,11 +294,11 @@ module.exports = class Notifier extends EventEmitter this._ua.destroyDialog(this); } - const sendFinalNotify = (reason === C.TERMINATED_RECEIVED_UNSUBSCRIBE - || reason === C.TERMINATED_SUBSCRIPTION_EXPIRED); + const send_final_notify = (termination_code === C.RECEIVED_UNSUBSCRIBE + || termination_code === C.SUBSCRIPTION_EXPIRED); - debug(`emit "terminated" ${reason}, sendFinalNotify=${sendFinalNotify}`); - this.emit('terminated', reason, sendFinalNotify); + debug(`emit "terminated" termination code=${termination_code}, send final notify=${send_final_notify}`); + this.emit('terminated', termination_code, send_final_notify); } _setExpiresTimestamp() @@ -324,7 +326,7 @@ module.exports = class Notifier extends EventEmitter this.terminated_reason = 'timeout'; this.is_final_notify_sent = true; this.sendNotify(); - this._dialogTerminated(C.TERMINATED_SUBSCRIPTION_EXPIRED); + this._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this.expires * 1000); } }; \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index b353236ff..6dc655aae 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -6,11 +6,35 @@ const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); debugerror.log = console.warn.bind(console); +/** + * Termination code + */ +const C = { + SUBSCRIBE_RESPONSE_TIMEOUT : 0, + SUBSCRIBE_TRANSPORT_ERROR : 1, + SUBSCRIBE_NON_OK_RESPONSE : 2, + SEND_UNSUBSCRIBE : 3, + RECEIVE_FINAL_NOTIFY : 4 +}; + /** * It's implementation of RFC 6665 Subscriber */ module.exports = class Subscriber extends EventEmitter { + /** + * Expose C object. + */ + static get C() + { + return C; + } + + get C() + { + return C; + } + /** * -param {Object} ua reference to JsSIP.UA * -param {String} target @@ -131,12 +155,12 @@ module.exports = class Subscriber extends EventEmitter onRequestTimeout() { - this._dialogTerminated('subscribe response timeout'); + this._dialogTerminated(C.SUBSCRIBE_RESPONSE_TIMEOUT); } onTransportError() { - this._dialogTerminated('subscribe transport error'); + this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); } onReceiveResponse(response) @@ -175,7 +199,7 @@ module.exports = class Subscriber extends EventEmitter } else if (response.status_code >= 300) { - this._dialogTerminated('receive subscribe non-OK response'); + this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); } } @@ -254,7 +278,7 @@ module.exports = class Subscriber extends EventEmitter if (is_final) { - this._dialogTerminated('receive final notify'); + this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY); } } @@ -296,7 +320,7 @@ module.exports = class Subscriber extends EventEmitter { debug('unsubscribe()'); - this._dialogTerminated('send un-subscribe'); + this._dialogTerminated(C.SEND_UNSUBSCRIBE); const headers = [ `Event: ${this.event_name}`, 'Expires: 0' @@ -316,7 +340,7 @@ module.exports = class Subscriber extends EventEmitter /** * Private API. */ - _dialogTerminated(reason) + _dialogTerminated(termination_code) { // to prevent duplicate emit terminated if (this.is_terminated) @@ -338,8 +362,8 @@ module.exports = class Subscriber extends EventEmitter this._ua.destroyDialog(this); }, 32000); - debug(`emit "terminated" ${reason}"`); - this.emit('terminated', reason); + debug(`emit "terminated" termination code=${termination_code}"`); + this.emit('terminated', termination_code); } } From 15cf6ddba95410c9405d34d96ad8323d77372ba5 Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 24 May 2021 14:44:03 +0300 Subject: [PATCH 17/70] changed constant name RECEIVE --- dist/jssip.js | 8 ++++---- dist/jssip.min.js | 2 +- lib/Notifier.js | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 77e7812e6..7fe51e12a 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16628,7 +16628,7 @@ var C = { NOTIFY_TRANSPORT_ERROR: 1, NOTIFY_NON_OK_RESPONSE: 2, SEND_FINAL_NOTIFY: 3, - RECEIVED_UNSUBSCRIBE: 4, + RECEIVE_UNSUBSCRIBE: 4, SUBSCRIPTION_EXPIRED: 5 }; /** @@ -16704,7 +16704,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.id = "".concat(_this.params.call_id).concat(_this.params.from_tag).concat(_this.params.to_tag); debug('add dialog id=', _this.id); - _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timerstamp and timer + _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires time-stamp and timer _this._setExpiresTimestamp(); @@ -16788,7 +16788,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.emit('subscribe', is_unsubscribe, request, body, content_type); if (is_unsubscribe) { - this._dialogTerminated(C.RECEIVED_UNSUBSCRIBE); + this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); } else { this._setExpiresTimestamp(); @@ -16896,7 +16896,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._ua.destroyDialog(this); } - var send_final_notify = termination_code === C.RECEIVED_UNSUBSCRIBE || termination_code === C.SUBSCRIPTION_EXPIRED; + var send_final_notify = termination_code === C.RECEIVE_UNSUBSCRIBE || termination_code === C.SUBSCRIPTION_EXPIRED; debug("emit \"terminated\" termination code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); this.emit('terminated', termination_code, send_final_notify); } diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 2580ce5ab..c5f53ad15 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVED_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVED_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,d||(d=[]),r.headers=d.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(d.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated(d.RECEIVE_FINAL_NOTIFY)}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated(d.SEND_UNSUBSCRIBE);var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,d||(d=[]),r.headers=d.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(d.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated(d.RECEIVE_FINAL_NOTIFY)}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated(d.SEND_UNSUBSCRIBE);var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index a61a5981d..649211e0b 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -14,7 +14,7 @@ const C = { NOTIFY_TRANSPORT_ERROR : 1, NOTIFY_NON_OK_RESPONSE : 2, SEND_FINAL_NOTIFY : 3, - RECEIVED_UNSUBSCRIBE : 4, + RECEIVE_UNSUBSCRIBE : 4, SUBSCRIPTION_EXPIRED : 5 }; @@ -101,7 +101,7 @@ module.exports = class Notifier extends EventEmitter debug('add dialog id=', this.id); this._ua.newDialog(this); - // Set expires timerstamp and timer + // Set expires time-stamp and timer this._setExpiresTimestamp(); this._setExpiresTimer(); @@ -186,7 +186,7 @@ module.exports = class Notifier extends EventEmitter if (is_unsubscribe) { - this._dialogTerminated(C.RECEIVED_UNSUBSCRIBE); + this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); } else { @@ -294,7 +294,7 @@ module.exports = class Notifier extends EventEmitter this._ua.destroyDialog(this); } - const send_final_notify = (termination_code === C.RECEIVED_UNSUBSCRIBE + const send_final_notify = (termination_code === C.RECEIVE_UNSUBSCRIBE || termination_code === C.SUBSCRIPTION_EXPIRED); debug(`emit "terminated" termination code=${termination_code}, send final notify=${send_final_notify}`); From a11eb27e750bf5a004e0cd5bd420624a992302b7 Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 24 May 2021 17:34:49 +0300 Subject: [PATCH 18/70] Added missed NOTIFY Contact --- dist/jssip.js | 4 +++- dist/jssip.min.js | 2 +- lib/Notifier.js | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 7fe51e12a..3e00ca449 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16681,10 +16681,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.content_type = content_type; _this.expires = parseInt(subscribe.getHeader('expires')); _this.credential = credential; - _this.contact = ""); _this.rcseq = subscribe.cseq; + _this.contact = ""); _this.headers = headers ? headers : []; + _this.headers.push("Contact: ".concat(_this.contact)); + if (_this.allow_events) { _this.headers.push("Allow-Events: ".concat(_this.allow_events)); } diff --git a/dist/jssip.min.js b/dist/jssip.min.js index c5f53ad15..b3d9acba9 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=i||[],n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,d||(d=[]),r.headers=d.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(d.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated(d.RECEIVE_FINAL_NOTIFY)}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated(d.SEND_UNSUBSCRIBE);var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.headers=i||[],n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,d||(d=[]),r.headers=d.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(d.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated(d.RECEIVE_FINAL_NOTIFY)}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated(d.SEND_UNSUBSCRIBE);var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 649211e0b..b8eb74fcf 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -71,17 +71,17 @@ module.exports = class Notifier extends EventEmitter this.content_type = content_type; this.expires = parseInt(subscribe.getHeader('expires')); this.credential = credential; - - this.contact = ``; - this.rcseq = subscribe.cseq; + this.contact = ``; + this.headers = headers ? headers : []; + this.headers.push(`Contact: ${this.contact}`); if (this.allow_events) { this.headers.push(`Allow-Events: ${this.allow_events}`); } - + this.target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); From 7db192e6258309878b33acc51ea39f16d2a7459f Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 24 May 2021 17:58:09 +0300 Subject: [PATCH 19/70] Added missed NOTIFY Contact --- dist/jssip.js | 17 +++++++---------- dist/jssip.min.js | 2 +- lib/Notifier.js | 10 +++++----- lib/Subscriber.js | 10 +++------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 3e00ca449..323cb9d0b 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16681,9 +16681,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.content_type = content_type; _this.expires = parseInt(subscribe.getHeader('expires')); _this.credential = credential; - _this.rcseq = subscribe.cseq; _this.contact = ""); - _this.headers = headers ? headers : []; + _this.rcseq = subscribe.cseq; + _this.headers = Utils.cloneArray(headers); + + _this.headers.push("Event: ".concat(_this.event_name)); _this.headers.push("Contact: ".concat(_this.contact)); @@ -16834,7 +16836,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var headers = this.headers.slice(); headers.push("Subscription-State: ".concat(subs_state)); - headers.push("Event: ".concat(this.event_name)); if (body) { headers.push("Content-Type: ".concat(this.content_type)); @@ -22737,7 +22738,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.content_type = content_type; _this.is_first_notify_request = true; - _this.params = params ? Utils.cloneObject(params) : {}; + _this.params = Utils.cloneObject(params); if (!_this.params.from_uri) { _this.params.from_uri = _this._ua.configuration.uri; @@ -22760,12 +22761,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.expires_timer = null; _this.expires_timestamp = null; - - if (!headers) { - headers = []; - } - - _this.headers = headers.concat(["Event: ".concat(_this.event_name), "Accept: ".concat(_this.accept), "Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); + _this.headers = Utils.cloneArray(headers); + _this.headers = _this.headers.concat(["Event: ".concat(_this.event_name), "Accept: ".concat(_this.accept), "Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); if (_this.allow_events) { _this.headers.push("Allow-Events: ".concat(_this.allow_events)); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index b3d9acba9..e98a971d9 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.headers=i||[],n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),n.push("Event: ".concat(this.event_name)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,d||(d=[]),r.headers=d.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(d.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated(d.RECEIVE_FINAL_NOTIFY)}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated(d.SEND_UNSUBSCRIBE);var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=h.cloneArray(i),n.headers.push("Event: ".concat(n.event_name)),n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,r.headers=c.cloneArray(d),r.headers=r.headers.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(d.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated(d.RECEIVE_FINAL_NOTIFY)}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated(d.SEND_UNSUBSCRIBE);var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index b8eb74fcf..00bd6b03d 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -71,17 +71,18 @@ module.exports = class Notifier extends EventEmitter this.content_type = content_type; this.expires = parseInt(subscribe.getHeader('expires')); this.credential = credential; + this.contact = ``; this.rcseq = subscribe.cseq; - this.contact = ``; - - this.headers = headers ? headers : []; + + this.headers = Utils.cloneArray(headers); + this.headers.push(`Event: ${this.event_name}`); this.headers.push(`Contact: ${this.contact}`); if (this.allow_events) { this.headers.push(`Allow-Events: ${this.allow_events}`); } - + this.target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); @@ -234,7 +235,6 @@ module.exports = class Notifier extends EventEmitter const headers = this.headers.slice(); headers.push(`Subscription-State: ${subs_state}`); - headers.push(`Event: ${this.event_name}`); if (body) { diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 6dc655aae..a85218e02 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -91,7 +91,7 @@ module.exports = class Subscriber extends EventEmitter this.content_type = content_type; this.is_first_notify_request = true; - this.params = params ? Utils.cloneObject(params) : {}; + this.params = Utils.cloneObject(params); if (!this.params.from_uri) { @@ -121,12 +121,8 @@ module.exports = class Subscriber extends EventEmitter this.expires_timer = null; this.expires_timestamp = null; - if (!headers) - { - headers = []; - } - - this.headers = headers.concat([ + this.headers = Utils.cloneArray(headers); + this.headers = this.headers.concat([ `Event: ${this.event_name}`, `Accept: ${this.accept}`, `Expires: ${this.expires}`, From 75d2bc060ea0fae684692853d3d7f6f25b7a9cd2 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 25 May 2021 15:53:18 +0300 Subject: [PATCH 20/70] check NOTIFY event id --- dist/jssip.js | 67 ++++++++++++++++++++++++++++++++++++++++------- dist/jssip.min.js | 2 +- lib/Subscriber.js | 67 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 114 insertions(+), 22 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 323cb9d0b..6895d3840 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22654,6 +22654,8 @@ var JsSIP_C = require('./Constants'); var Utils = require('./Utils'); +var Grammar = require('./Grammar'); + var debug = require('debug')('JsSIP:Subscriber'); var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); @@ -22668,7 +22670,8 @@ var C = { SUBSCRIBE_TRANSPORT_ERROR: 1, SUBSCRIBE_NON_OK_RESPONSE: 2, SEND_UNSUBSCRIBE: 3, - RECEIVE_FINAL_NOTIFY: 4 + RECEIVE_FINAL_NOTIFY: 4, + RECEIVE_BAD_NOTIFY: 5 }; /** * It's implementation of RFC 6665 Subscriber @@ -22683,7 +22686,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * -param {Object} ua reference to JsSIP.UA * -param {String} target * -param {Object} options - * -param {String} event_name Event header value + * -param {String} event_name Event header value. May end with optional ;id=xxx * -param {String} accept Accept header value * -param {Number} expires Expires header value. Optional. Default is 900 * -param {String} content_type Content-Type header value @@ -22721,7 +22724,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { throw new TypeError('event_name is undefined'); } - _this.event_name = event_name; + var parsed = Grammar.parse(event_name, 'Event'); + + if (parsed === -1) { + throw new TypeError('event_name - wrong format'); + } + + _this.event_name = parsed.event; + _this.event_id = parsed.params && parsed.params.id; if (!accept) { throw new TypeError('accept is undefined'); @@ -22762,7 +22772,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this.expires_timer = null; _this.expires_timestamp = null; _this.headers = Utils.cloneArray(headers); - _this.headers = _this.headers.concat(["Event: ".concat(_this.event_name), "Accept: ".concat(_this.accept), "Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); + var event_value = _this.event_name; + + if (_this.event_id) { + event_value += ";id=".concat(_this.event_id); + } + + _this.headers = _this.headers.concat(["Event: ".concat(event_value), "Expires: ".concat(_this.expires), "Accept: ".concat(_this.accept), "Contact: ".concat(_this.contact)]); if (_this.allow_events) { _this.headers.push("Allow-Events: ".concat(_this.allow_events)); @@ -22841,15 +22857,44 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "receiveRequest", value: function receiveRequest(request) { if (request.method !== JsSIP_C.NOTIFY) { + debugerror('received non-NOTIFY request'); request.reply(405); + return; + } // RFC 6665 8.2.1. Check if event header matches + + + var event_header = request.parseHeader('Event'); + + if (!event_header) { + debugerror('missed Event header'); + request.reply(400); + + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + return; } + var event_name = event_header.event; + var event_id = event_header.params && event_header.params.id; + + if (event_name !== this.event_name || event_id !== this.event_id) { + debugerror('Event header does not match SUBSCRIBE'); + request.reply(489); + + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + + return; + } // Process Subscription-State header + + var subs_state = request.parseHeader('subscription-state'); if (!subs_state) { - debugerror('missed header Subscription-State'); + debugerror('missed Subscription-State header'); request.reply(400); + + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + return; } @@ -22938,13 +22983,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "unsubscribe", value: function unsubscribe() { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('unsubscribe()'); - - this._dialogTerminated(C.SEND_UNSUBSCRIBE); + debug('unsubscribe()'); // Set header Expires: 0 - var headers = ["Event: ".concat(this.event_name), 'Expires: 0']; + var headers = this.headers.map(function (s) { + return s.startsWith('Expires') ? 'Expires: 0' : s; + }); this._send(body, headers); + + this._dialogTerminated(C.SEND_UNSUBSCRIBE); } /** * Get dialog state @@ -23026,7 +23073,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return Subscriber; }(EventEmitter); -},{"./Constants":2,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ "use strict"; var T1 = 500, diff --git a/dist/jssip.min.js b/dist/jssip.min.js index e98a971d9..58ed3b490 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=h.cloneArray(i),n.headers.push("Event: ".concat(n.event_name)),n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=p,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,r.headers=c.cloneArray(d),r.headers=r.headers.concat(["Event: ".concat(r.event_name),"Accept: ".concat(r.accept),"Expires: ".concat(r.expires),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),h("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void f("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(d.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===u.NOTIFY){var t=e.parseHeader("subscription-state");if(!t)return f("missed header Subscription-State"),void e.reply(400);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var n=t.state.toLowerCase(),r=this._state;if("terminated"!==r&&"terminated"!==n&&(this._state=n,void 0!==t.expires)){var s=t.expires,i=(new Date).getTime()+1e3*s;this.expires_timestamp-i>2e3&&(h("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=i,this._scheduleSubscribe(this._calculateTimeoutMs(s)))}"active"!==r&&"active"===n&&(h('emit "active"'),this.emit("active"));var o=e.body,l="terminated"===n;if(o){var a=e.getHeader("content-type");h('emit "notify"'),this.emit("notify",l,e,o,a)}l&&this._dialogTerminated(d.RECEIVE_FINAL_NOTIFY)}else e.reply(405)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;h("unsubscribe()"),this._dialogTerminated(d.SEND_UNSUBSCRIBE);var t=["Event: ".concat(this.event_name),"Expires: 0"];this._send(e,t)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){h("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),h('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;h("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=h.cloneArray(i),n.headers.push("Event: ".concat(n.event_name)),n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=m,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,r.headers=c.cloneArray(_);var g=r.event_name;return r.event_id&&(g+=";id=".concat(r.event_id)),r.headers=r.headers.concat(["Event: ".concat(g),"Expires: ".concat(r.expires),"Accept: ".concat(r.accept),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),f("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void d("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this.event_name||r!==this.event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this.expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=a,this._scheduleSubscribe(this._calculateTimeoutMs(l)))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("unsubscribe()");var t=this.headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(e,t),this._dialogTerminated(_.SEND_UNSUBSCRIBE)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){f("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;f("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index a85218e02..9a5382b60 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -1,6 +1,7 @@ const EventEmitter = require('events').EventEmitter; const JsSIP_C = require('./Constants'); const Utils = require('./Utils'); +const Grammar = require('./Grammar'); const debug = require('debug')('JsSIP:Subscriber'); const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); @@ -14,7 +15,8 @@ const C = { SUBSCRIBE_TRANSPORT_ERROR : 1, SUBSCRIBE_NON_OK_RESPONSE : 2, SEND_UNSUBSCRIBE : 3, - RECEIVE_FINAL_NOTIFY : 4 + RECEIVE_FINAL_NOTIFY : 4, + RECEIVE_BAD_NOTIFY : 5 }; /** @@ -39,7 +41,7 @@ module.exports = class Subscriber extends EventEmitter * -param {Object} ua reference to JsSIP.UA * -param {String} target * -param {Object} options - * -param {String} event_name Event header value + * -param {String} event_name Event header value. May end with optional ;id=xxx * -param {String} accept Accept header value * -param {Number} expires Expires header value. Optional. Default is 900 * -param {String} content_type Content-Type header value @@ -70,8 +72,16 @@ module.exports = class Subscriber extends EventEmitter throw new TypeError('event_name is undefined'); } - this.event_name = event_name; + const parsed = Grammar.parse(event_name, 'Event'); + + if (parsed === -1) + { + throw new TypeError('event_name - wrong format'); + } + this.event_name = parsed.event; + this.event_id = parsed.params && parsed.params.id; + if (!accept) { throw new TypeError('accept is undefined'); @@ -122,10 +132,17 @@ module.exports = class Subscriber extends EventEmitter this.expires_timestamp = null; this.headers = Utils.cloneArray(headers); + let event_value = this.event_name; + + if (this.event_id) + { + event_value += `;id=${this.event_id}`; + } + this.headers = this.headers.concat([ - `Event: ${this.event_name}`, - `Accept: ${this.accept}`, + `Event: ${event_value}`, `Expires: ${this.expires}`, + `Accept: ${this.accept}`, `Contact: ${this.contact}` ]); @@ -206,17 +223,44 @@ module.exports = class Subscriber extends EventEmitter { if (request.method !== JsSIP_C.NOTIFY) { + debugerror('received non-NOTIFY request'); request.reply(405); return; } + // RFC 6665 8.2.1. Check if event header matches + const event_header = request.parseHeader('Event'); + + if (!event_header) + { + debugerror('missed Event header'); + request.reply(400); + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + + return; + } + + const event_name = event_header.event; + const event_id = event_header.params && event_header.params.id; + + if (event_name !== this.event_name || event_id !== this.event_id) + { + debugerror('Event header does not match SUBSCRIBE'); + request.reply(489); + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + + return; + } + + // Process Subscription-State header const subs_state = request.parseHeader('subscription-state'); if (!subs_state) { - debugerror('missed header Subscription-State'); + debugerror('missed Subscription-State header'); request.reply(400); + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); return; } @@ -316,13 +360,14 @@ module.exports = class Subscriber extends EventEmitter { debug('unsubscribe()'); - this._dialogTerminated(C.SEND_UNSUBSCRIBE); - const headers = [ - `Event: ${this.event_name}`, - 'Expires: 0' - ]; + // Set header Expires: 0 + const headers = this.headers.map((s) => + { + return s.startsWith('Expires') ? 'Expires: 0' : s; + }); this._send(body, headers); + this._dialogTerminated(C.SEND_UNSUBSCRIBE); } /** From 7ffaf2fd5c4a734ff87b73befdecca42b8ed29b6 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 25 May 2021 16:59:32 +0300 Subject: [PATCH 21/70] added FAILED_AUTHENTICATION & bug fixing --- dist/jssip.js | 23 +++++++++++++++-------- dist/jssip.min.js | 2 +- lib/Notifier.js | 17 +++++++++++------ lib/Subscriber.js | 23 ++++++++++++++--------- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 6895d3840..82fcbfd72 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16627,9 +16627,10 @@ var C = { NOTIFY_RESPONSE_TIMEOUT: 0, NOTIFY_TRANSPORT_ERROR: 1, NOTIFY_NON_OK_RESPONSE: 2, - SEND_FINAL_NOTIFY: 3, - RECEIVE_UNSUBSCRIBE: 4, - SUBSCRIPTION_EXPIRED: 5 + NOTIFY_FAILED_AUTHENTICATION: 3, + SEND_FINAL_NOTIFY: 4, + RECEIVE_UNSUBSCRIBE: 5, + SUBSCRIPTION_EXPIRED: 6 }; /** * It's implementation of RFC 6665 Notifier @@ -16759,6 +16760,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.params.route_set = this.route_set; } } + } else if (response.status_code === 401 || response.status_code === 407) { + this._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); } else if (response.status_code >= 300) { this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); } @@ -22669,9 +22672,10 @@ var C = { SUBSCRIBE_RESPONSE_TIMEOUT: 0, SUBSCRIBE_TRANSPORT_ERROR: 1, SUBSCRIBE_NON_OK_RESPONSE: 2, - SEND_UNSUBSCRIBE: 3, - RECEIVE_FINAL_NOTIFY: 4, - RECEIVE_BAD_NOTIFY: 5 + SUBSCRIBE_FAILED_AUTHENTICATION: 3, + SEND_UNSUBSCRIBE: 4, + RECEIVE_FINAL_NOTIFY: 5, + RECEIVE_BAD_NOTIFY: 6 }; /** * It's implementation of RFC 6665 Subscriber @@ -22845,6 +22849,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._scheduleSubscribe(this._calculateTimeoutMs(expires)); } + } else if (response.status_code === 401 || response.status_code === 407) { + this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); } else if (response.status_code >= 300) { this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); } @@ -23026,9 +23032,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this2._ua.destroyDialog(_this2); }, 32000); - debug("emit \"terminated\" termination code=".concat(termination_code, "\"")); - this.emit('terminated', termination_code); } + + debug("emit \"terminated\" termination code=".concat(termination_code, "\"")); + this.emit('terminated', termination_code); } }, { key: "_send", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 58ed3b490..fa14abcf5 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=h.cloneArray(i),n.headers.push("Event: ".concat(n.event_name)),n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=m,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,r.headers=c.cloneArray(_);var g=r.event_name;return r.event_id&&(g+=";id=".concat(r.event_id)),r.headers=r.headers.concat(["Event: ".concat(g),"Expires: ".concat(r.expires),"Accept: ".concat(r.accept),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),f("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void d("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this.event_name||r!==this.event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this.expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=a,this._scheduleSubscribe(this._calculateTimeoutMs(l)))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("unsubscribe()");var t=this.headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(e,t),this._dialogTerminated(_.SEND_UNSUBSCRIBE)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(setTimeout(function(){f("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e)))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;f("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=h.cloneArray(i),n.headers.push("Event: ".concat(n.event_name)),n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):401===e.status_code||407===e.status_code?this._dialogTerminated(d.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=m,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,r.headers=c.cloneArray(_);var g=r.event_name;return r.event_id&&(g+=";id=".concat(r.event_id)),r.headers=r.headers.concat(["Event: ".concat(g),"Expires: ".concat(r.expires),"Accept: ".concat(r.accept),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),f("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void d("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this.event_name||r!==this.event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this.expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=a,this._scheduleSubscribe(this._calculateTimeoutMs(l)))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("unsubscribe()");var t=this.headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(e,t),this._dialogTerminated(_.SEND_UNSUBSCRIBE)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&setTimeout(function(){f("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;f("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 00bd6b03d..7d1005976 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -10,12 +10,13 @@ debugerror.log = console.warn.bind(console); * Termination code */ const C = { - NOTIFY_RESPONSE_TIMEOUT : 0, - NOTIFY_TRANSPORT_ERROR : 1, - NOTIFY_NON_OK_RESPONSE : 2, - SEND_FINAL_NOTIFY : 3, - RECEIVE_UNSUBSCRIBE : 4, - SUBSCRIPTION_EXPIRED : 5 + NOTIFY_RESPONSE_TIMEOUT : 0, + NOTIFY_TRANSPORT_ERROR : 1, + NOTIFY_NON_OK_RESPONSE : 2, + NOTIFY_FAILED_AUTHENTICATION : 3, + SEND_FINAL_NOTIFY : 4, + RECEIVE_UNSUBSCRIBE : 5, + SUBSCRIPTION_EXPIRED : 6 }; /** @@ -148,6 +149,10 @@ module.exports = class Notifier extends EventEmitter } } } + else if (response.status_code === 401 || response.status_code === 407) + { + this._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); + } else if (response.status_code >= 300) { this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 9a5382b60..586da7e56 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -11,12 +11,13 @@ debugerror.log = console.warn.bind(console); * Termination code */ const C = { - SUBSCRIBE_RESPONSE_TIMEOUT : 0, - SUBSCRIBE_TRANSPORT_ERROR : 1, - SUBSCRIBE_NON_OK_RESPONSE : 2, - SEND_UNSUBSCRIBE : 3, - RECEIVE_FINAL_NOTIFY : 4, - RECEIVE_BAD_NOTIFY : 5 + SUBSCRIBE_RESPONSE_TIMEOUT : 0, + SUBSCRIBE_TRANSPORT_ERROR : 1, + SUBSCRIBE_NON_OK_RESPONSE : 2, + SUBSCRIBE_FAILED_AUTHENTICATION : 3, + SEND_UNSUBSCRIBE : 4, + RECEIVE_FINAL_NOTIFY : 5, + RECEIVE_BAD_NOTIFY : 6 }; /** @@ -210,6 +211,10 @@ module.exports = class Subscriber extends EventEmitter this._scheduleSubscribe(this._calculateTimeoutMs(expires)); } } + else if (response.status_code === 401 || response.status_code === 407) + { + this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); + } else if (response.status_code >= 300) { this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); @@ -402,10 +407,10 @@ module.exports = class Subscriber extends EventEmitter this._ua.destroyDialog(this); }, 32000); - - debug(`emit "terminated" termination code=${termination_code}"`); - this.emit('terminated', termination_code); } + + debug(`emit "terminated" termination code=${termination_code}"`); + this.emit('terminated', termination_code); } _send(body, headers) From 3c8d4402c13056c78643b444096f74941a6fb963 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 25 May 2021 18:01:29 +0300 Subject: [PATCH 22/70] notifier terminated. bug fixing --- dist/jssip.js | 2 +- dist/jssip.min.js | 2 +- lib/Notifier.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 82fcbfd72..1087d5221 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16867,7 +16867,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.is_final_notify_sent = true; - this._dialogTerminated('send final notify'); + this._dialogTerminated(C.SEND_FINAL_NOTIFY); this.terminated_reason = reason; this.sendNotify(body); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index fa14abcf5..585a7eef2 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=h.cloneArray(i),n.headers.push("Event: ".concat(n.event_name)),n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):401===e.status_code||407===e.status_code?this._dialogTerminated(d.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated("send final notify"),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=m,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,r.headers=c.cloneArray(_);var g=r.event_name;return r.event_id&&(g+=";id=".concat(r.event_id)),r.headers=r.headers.concat(["Event: ".concat(g),"Expires: ".concat(r.expires),"Accept: ".concat(r.accept),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),f("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void d("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this.event_name||r!==this.event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this.expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=a,this._scheduleSubscribe(this._calculateTimeoutMs(l)))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("unsubscribe()");var t=this.headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(e,t),this._dialogTerminated(_.SEND_UNSUBSCRIBE)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&setTimeout(function(){f("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;f("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=h.cloneArray(i),n.headers.push("Event: ".concat(n.event_name)),n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):401===e.status_code||407===e.status_code?this._dialogTerminated(d.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated(d.SEND_FINAL_NOTIFY),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=m,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,r.headers=c.cloneArray(_);var g=r.event_name;return r.event_id&&(g+=";id=".concat(r.event_id)),r.headers=r.headers.concat(["Event: ".concat(g),"Expires: ".concat(r.expires),"Accept: ".concat(r.accept),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),f("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void d("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this.event_name||r!==this.event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this.expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=a,this._scheduleSubscribe(this._calculateTimeoutMs(l)))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("unsubscribe()");var t=this.headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(e,t),this._dialogTerminated(_.SEND_UNSUBSCRIBE)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&setTimeout(function(){f("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;f("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 7d1005976..9a09366cb 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -266,7 +266,7 @@ module.exports = class Notifier extends EventEmitter } this.is_final_notify_sent = true; - this._dialogTerminated('send final notify'); + this._dialogTerminated(C.SEND_FINAL_NOTIFY); this.terminated_reason = reason; this.sendNotify(body); } From fd1c6d073c286f91ce87860e90a24398a9f53282 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 25 May 2021 23:03:18 +0300 Subject: [PATCH 23/70] style: private starts with _ --- dist/jssip.js | 293 +++++++++++++++++++++++----------------------- dist/jssip.min.js | 2 +- lib/Notifier.js | 142 +++++++++++----------- lib/Subscriber.js | 163 +++++++++++++------------- 4 files changed, 303 insertions(+), 297 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 1087d5221..d96e72c84 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16666,38 +16666,37 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { debug('new'); _this = _super.call(this); _this._ua = ua; - _this.expires_timestamp = null; - _this.expires_timer = null; + _this._expires_timestamp = null; + _this._expires_timer = null; _this._state = pending ? 'pending' : 'active'; - _this.is_final_notify_sent = false; - _this.is_first_notify_response = true; - _this.id = null; - _this.allow_events = allow_events; - _this.event_name = subscribe.getHeader('event'); + _this._is_final_notify_sent = false; + _this._is_first_notify_response = true; + _this._id = null; + _this._allow_events = allow_events; + _this._event_name = subscribe.getHeader('event'); if (!content_type) { throw new TypeError('content_type is undefined'); } - _this.content_type = content_type; - _this.expires = parseInt(subscribe.getHeader('expires')); - _this.credential = credential; - _this.contact = ""); - _this.rcseq = subscribe.cseq; - _this.headers = Utils.cloneArray(headers); + _this._content_type = content_type; + _this._expires = parseInt(subscribe.getHeader('expires')); + _this._credential = credential; + _this._contact = ""); + _this._headers = Utils.cloneArray(headers); - _this.headers.push("Event: ".concat(_this.event_name)); + _this._headers.push("Event: ".concat(_this._event_name)); - _this.headers.push("Contact: ".concat(_this.contact)); + _this._headers.push("Contact: ".concat(_this._contact)); - if (_this.allow_events) { - _this.headers.push("Allow-Events: ".concat(_this.allow_events)); + if (_this._allow_events) { + _this._headers.push("Allow-Events: ".concat(_this._allow_events)); } - _this.target = subscribe.from.uri.user; + _this._target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); // NOTIFY request params set according received SUBSCRIBE - _this.params = { + _this._params = { from: subscribe.to, from_tag: subscribe.to_tag, to: subscribe.from, @@ -16706,21 +16705,19 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { cseq: Math.floor(Math.random() * 10000 + 1) }; // Dialog id - _this.id = "".concat(_this.params.call_id).concat(_this.params.from_tag).concat(_this.params.to_tag); - debug('add dialog id=', _this.id); - - _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires time-stamp and timer + _this._id = "".concat(_this._params.call_id).concat(_this._params.from_tag).concat(_this._params.to_tag); + debug('add dialog id=', _this._id); + _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timer and timestamp - _this._setExpiresTimestamp(); _this._setExpiresTimer(); - _this.is_terminated = false; - _this.terminated_reason = undefined; // Custom session empty object for high level use. + _this._is_terminated = false; + _this._terminated_reason = undefined; // Custom session empty object for high level use. _this.data = {}; - subscribe.reply(200, null, ["Expires: ".concat(_this.expires), "Contact: ".concat(_this.contact)]); + subscribe.reply(200, null, ["Expires: ".concat(_this._expires), "Contact: ".concat(_this._contact)]); return _this; } /** @@ -16736,7 +16733,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onAuthenticated", value: function onAuthenticated() { - this.params.cseq++; + this._params.cseq++; } }, { key: "onRequestTimeout", @@ -16752,12 +16749,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "onReceiveResponse", value: function onReceiveResponse(response) { if (response.status_code >= 200 && response.status_code < 300) { - if (this.is_first_notify_response) { - this.is_first_notify_response = false; - this.route_set = response.getHeaders('record-route').reverse(); + if (this._is_first_notify_response) { + this._is_first_notify_response = false; + var route_set = response.getHeaders('record-route').reverse(); - if (this.route_set.length > 0) { - this.params.route_set = this.route_set; + if (route_set.length > 0) { + this._params.route_set = route_set; } } } else if (response.status_code === 401 || response.status_code === 407) { @@ -16786,19 +16783,17 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { debug("Missed expires header. Set by default ".concat(h)); } - this.expires = parseInt(h); - request.reply(200, null, ["Expires: ".concat(this.expires), "Contact: ".concat(this.contact)]); + this._expires = parseInt(h); + request.reply(200, null, ["Expires: ".concat(this._expires), "Contact: ".concat(this._contact)]); var body = request.body; var content_type = request.getHeader('content-type'); - var is_unsubscribe = this.expires === 0; + var is_unsubscribe = this._expires === 0; debug('emit "subscribe"'); this.emit('subscribe', is_unsubscribe, request, body, content_type); if (is_unsubscribe) { this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); } else { - this._setExpiresTimestamp(); - this._setExpiresTimer(); } } @@ -16832,21 +16827,28 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var subs_state = this._state; if (this._state !== 'terminated') { - subs_state += ";expires=".concat(this._getExpiresTimestamp()); - } else if (this.terminated_reason) { - subs_state += ";reason=".concat(this.terminated_reason); + var expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); + + if (expires < 0) { + expires = 0; + } + + subs_state += ";expires=".concat(expires); + } else if (this._terminated_reason) { + subs_state += ";reason=".concat(this._terminated_reason); } - var headers = this.headers.slice(); + var headers = this._headers.slice(); + headers.push("Subscription-State: ".concat(subs_state)); if (body) { - headers.push("Content-Type: ".concat(this.content_type)); + headers.push("Content-Type: ".concat(this._content_type)); } - this.params.cseq++; + this._params.cseq++; - this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, this, this.credential); + this._ua.sendRequest(JsSIP_C.NOTIFY, this._target, this._params, headers, body, this, this._credential); } /** * Send the final NOTIFY request @@ -16861,15 +16863,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; debug('sendFinalNotify()'); - if (this.is_final_notify_sent) { + if (this._is_final_notify_sent) { return; } - this.is_final_notify_sent = true; + this._is_final_notify_sent = true; this._dialogTerminated(C.SEND_FINAL_NOTIFY); - this.terminated_reason = reason; + this._terminated_reason = reason; this.sendNotify(body); } /** @@ -16881,6 +16883,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { get: function get() { return this._state; } + /** + * Get dialog id + */ + + }, { + key: "id", + get: function get() { + return this._id; + } /** * Private API. */ @@ -16888,16 +16899,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_dialogTerminated", value: function _dialogTerminated(termination_code) { - if (this.is_terminated) { + if (this._is_terminated) { return; } - this.is_terminated = true; + this._is_terminated = true; this._state = 'terminated'; - clearTimeout(this.expires_timer); + clearTimeout(this._expires_timer); - if (this.id) { - debug('remove dialog id=', this.id); + if (this._id) { + debug('remove dialog id=', this._id); this._ua.destroyDialog(this); } @@ -16906,35 +16917,25 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { debug("emit \"terminated\" termination code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); this.emit('terminated', termination_code, send_final_notify); } - }, { - key: "_setExpiresTimestamp", - value: function _setExpiresTimestamp() { - this.expires_timestamp = new Date().getTime() + this.expires * 1000; - } - }, { - key: "_getExpiresTimestamp", - value: function _getExpiresTimestamp() { - var delta = Math.floor((this.expires_timestamp - new Date().getTime()) / 1000); - return delta >= 0 ? delta : 0; - } }, { key: "_setExpiresTimer", value: function _setExpiresTimer() { var _this2 = this; - clearTimeout(this.expires_timer); + this._expires_timestamp = new Date().getTime() + this._expires * 1000; + clearTimeout(this._expires_timer); setTimeout(function () { - if (_this2.is_final_notify_sent) { + if (_this2._is_final_notify_sent) { return; } - _this2.terminated_reason = 'timeout'; - _this2.is_final_notify_sent = true; + _this2._terminated_reason = 'timeout'; + _this2._is_final_notify_sent = true; _this2.sendNotify(); _this2._dialogTerminated(C.SUBSCRIPTION_EXPIRED); - }, this.expires * 1000); + }, this._expires * 1000); } }], [{ key: "C", @@ -22722,7 +22723,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { throw new TypeError('target is undefined'); } - _this.target = target; + _this._target = target; if (!event_name) { throw new TypeError('event_name is undefined'); @@ -22734,62 +22735,61 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { throw new TypeError('event_name - wrong format'); } - _this.event_name = parsed.event; - _this.event_id = parsed.params && parsed.params.id; + _this._event_name = parsed.event; + _this._event_id = parsed.params && parsed.params.id; if (!accept) { throw new TypeError('accept is undefined'); } - _this.accept = accept; + _this._accept = accept; if (!expires) { expires = 900; } - _this.expires = expires; - _this.allow_events = allow_events; // used to subscribe with body + _this._expires = expires; + _this._allow_events = allow_events; // used to subscribe with body - _this.content_type = content_type; - _this.is_first_notify_request = true; - _this.params = Utils.cloneObject(params); + _this._content_type = content_type; + _this._is_first_notify_request = true; + _this._params = Utils.cloneObject(params); - if (!_this.params.from_uri) { - _this.params.from_uri = _this._ua.configuration.uri; + if (!_this._params.from_uri) { + _this._params.from_uri = _this._ua.configuration.uri; } // set SUBSCRIBE dialog parameters - _this.params.from_tag = Utils.newTag(); - _this.params.to_tag = null; - _this.params.call_id = Utils.createRandomToken(20); - _this.params.cseq = Math.floor(Math.random() * 10000 + 1); // Create contact + _this._params.from_tag = Utils.newTag(); + _this._params.to_tag = null; + _this._params.call_id = Utils.createRandomToken(20); + _this._params.cseq = Math.floor(Math.random() * 10000 + 1); // Create contact - _this.contact = ""); - _this.contact += ";+sip.instance=\"\""); // Optional, used if credential is different from REGISTER/INVITE + _this._contact = ""); + _this._contact += ";+sip.instance=\"\""); // Optional, used if credential is different from REGISTER/INVITE - _this.credential = credential; // Dialog state: init, notify_wait, pending, active, terminated + _this._credential = credential; // Dialog state: init, notify_wait, pending, active, terminated _this._state = 'init'; // Dialog id - _this.id = null; // To refresh subscription + _this._id = null; // To refresh subscription - _this.expires_timer = null; - _this.expires_timestamp = null; - _this.headers = Utils.cloneArray(headers); - var event_value = _this.event_name; + _this._expires_timer = null; + _this._expires_timestamp = null; + _this._headers = Utils.cloneArray(headers); + var event_value = _this._event_name; - if (_this.event_id) { - event_value += ";id=".concat(_this.event_id); + if (_this._event_id) { + event_value += ";id=".concat(_this._event_id); } - _this.headers = _this.headers.concat(["Event: ".concat(event_value), "Expires: ".concat(_this.expires), "Accept: ".concat(_this.accept), "Contact: ".concat(_this.contact)]); + _this._headers = _this._headers.concat(["Event: ".concat(event_value), "Expires: ".concat(_this._expires), "Accept: ".concat(_this._accept), "Contact: ".concat(_this._contact)]); - if (_this.allow_events) { - _this.headers.push("Allow-Events: ".concat(_this.allow_events)); + if (_this._allow_events) { + _this._headers.push("Allow-Events: ".concat(_this._allow_events)); } - _this.is_terminated = false; - _this.route_set = null; // Custom session empty object for high level use. + _this._is_terminated = false; // Custom session empty object for high level use. _this.data = {}; return _this; @@ -22807,7 +22807,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onAuthenticated", value: function onAuthenticated() { - this.params.cseq++; + this._params.cseq++; } }, { key: "onRequestTimeout", @@ -22823,31 +22823,33 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "onReceiveResponse", value: function onReceiveResponse(response) { if (response.status_code >= 200 && response.status_code < 300) { - if (this.params.to_tag === null) { - this.params.to_tag = response.to_tag; - this.id = "".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag); - debug('added dialog id=', this.id); + if (this._params.to_tag === null) { + this._params.to_tag = response.to_tag; + this._id = "".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag); + debug('added dialog id=', this._id); this._ua.newDialog(this); - this.route_set = response.getHeaders('record-route').reverse(); + var route_set = response.getHeaders('record-route').reverse(); - if (this.route_set.length > 0) { - this.params.route_set = this.route_set; + if (route_set.length > 0) { + this._params.route_set = route_set; } } - var expires = this._getExpires(response); + var expires_value = response.getHeader('expires'); - if (expires === -1) { - debugerror('response without Expires header'); - return; + if (!expires_value) { + debugerror('response without Expires header'); // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header + // Use workaround expires value. + + expires_value = '900'; } - if (expires > 0) { - this.expires_timestamp = new Date().getTime() + expires * 1000; + var expires = parseInt(expires_value); - this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + if (expires > 0) { + this._scheduleSubscribe(expires); } } else if (response.status_code === 401 || response.status_code === 407) { this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); @@ -22883,7 +22885,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var event_name = event_header.event; var event_id = event_header.params && event_header.params.id; - if (event_name !== this.event_name || event_id !== this.event_id) { + if (event_name !== this._event_name || event_id !== this._event_id) { debugerror('Event header does not match SUBSCRIBE'); request.reply(489); @@ -22906,8 +22908,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(200); - if (this.is_first_notify_request) { - this.is_first_notify_request = false; // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? + if (this._is_first_notify_request) { + this._is_first_notify_request = false; // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? } var new_state = subs_state.state.toLowerCase(); @@ -22921,12 +22923,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var expires_timestamp = new Date().getTime() + expires * 1000; var max_time_deviation = 2000; // expiration time is shorter and the difference is not too small - if (this.expires_timestamp - expires_timestamp > max_time_deviation) { + if (this._expires_timestamp - expires_timestamp > max_time_deviation) { debug('update sending re-SUBSCRIBE time'); - clearTimeout(this.expires_timer); - this.expires_timestamp = expires_timestamp; - this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + this._scheduleSubscribe(expires); } } } @@ -22968,14 +22968,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._state = 'notify_wait'; } - var headers = this.headers.slice(); + var headers = this._headers.slice(); if (body) { - if (!this.content_type) { + if (!this._content_type) { throw new TypeError('content_type is undefined'); } - headers.push("Content-Type: ".concat(this.content_type)); + headers.push("Content-Type: ".concat(this._content_type)); } this._send(body, headers); @@ -22991,7 +22991,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; debug('unsubscribe()'); // Set header Expires: 0 - var headers = this.headers.map(function (s) { + var headers = this._headers.map(function (s) { return s.startsWith('Expires') ? 'Expires: 0' : s; }); @@ -23008,6 +23008,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { get: function get() { return this._state; } + /** + * Get dialog id + */ + + }, { + key: "id", + get: function get() { + return this._id; + } /** * Private API. */ @@ -23018,15 +23027,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this2 = this; // to prevent duplicate emit terminated - if (this.is_terminated) { + if (this._is_terminated) { return; } - this.is_terminated = true; + this._is_terminated = true; this._state = 'terminated'; - clearTimeout(this.expires_timer); // remove dialog with some delay to receiving possible final NOTIFY + clearTimeout(this._expires_timer); // remove dialog with some delay to receiving possible final NOTIFY - if (this.id) { + if (this._id) { setTimeout(function () { debug('removed dialog id=', _this2.id); @@ -23040,31 +23049,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_send", value: function _send(body, headers) { - this.params.cseq++; + this._params.cseq++; - this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this.target, this.params, headers, body, this, this.credential); - } - }, { - key: "_getExpires", - value: function _getExpires(r) { - var e = r.getHeader('expires'); - return e ? parseInt(e) : -1; - } - }, { - key: "_calculateTimeoutMs", - value: function _calculateTimeoutMs(expires) { - return expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; + this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this._target, this._params, headers, body, this, this._credential); } }, { key: "_scheduleSubscribe", - value: function _scheduleSubscribe(timeout) { + value: function _scheduleSubscribe(expires) { var _this3 = this; + var timeout = expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; + this._expires_timestamp = new Date().getTime() + expires * 1000; debug("next SUBSCRIBE will be sent in ".concat(Math.floor(timeout / 1000), " sec")); - this.expires_timer = setTimeout(function () { - _this3.expires_timer = undefined; + clearTimeout(this._expires_timer); + this._expires_timer = setTimeout(function () { + _this3._expires_timer = null; - _this3._send(null, _this3.headers); + _this3._send(null, _this3._headers); }, timeout); } }], [{ diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 585a7eef2..8ceeaf9b8 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:x,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:xe,hname:Ue,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=xe())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),null!==s&&null!==(l=xe())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function xe(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=xt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=xt())),e}function xt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=xt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=x())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=x())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=xn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,a,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 kn(){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 xn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=U())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n.rcseq=r.cseq,n.headers=h.cloneArray(i),n.headers.push("Event: ".concat(n.event_name)),n.headers.push("Contact: ".concat(n.contact)),n.allow_events&&n.headers.push("Allow-Events: ".concat(n.allow_events)),n.target=r.from.uri.user,r.to_tag=h.newTag(),n.params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n.id="".concat(n.params.call_id).concat(n.params.from_tag).concat(n.params.to_tag),f("add dialog id=",n.id),n._ua.newDialog(l(n)),n._setExpiresTimestamp(),n._setExpiresTimer(),n.is_terminated=!1,n.terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n.expires),"Contact: ".concat(n.contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){e.status_code>=200&&e.status_code<300?this.is_first_notify_response&&(this.is_first_notify_response=!1,this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set)):401===e.status_code||407===e.status_code?this._dialogTerminated(d.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this.expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this.expires),"Contact: ".concat(this.contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this.expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):(this._setExpiresTimestamp(),this._setExpiresTimer())}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;"terminated"!==this._state?t+=";expires=".concat(this._getExpiresTimestamp()):this.terminated_reason&&(t+=";reason=".concat(this.terminated_reason));var n=this.headers.slice();n.push("Subscription-State: ".concat(t)),e&&n.push("Content-Type: ".concat(this.content_type)),this.params.cseq++,this._ua.sendRequest(c.NOTIFY,this.target,this.params,n,e,this,this.credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this.is_final_notify_sent||(this.is_final_notify_sent=!0,this._dialogTerminated(d.SEND_FINAL_NOTIFY),this.terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){if(!this.is_terminated){this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&(f("remove dialog id=",this.id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimestamp",value:function(){this.expires_timestamp=(new Date).getTime()+1e3*this.expires}},{key:"_getExpiresTimestamp",value:function(){var e=Math.floor((this.expires_timestamp-(new Date).getTime())/1e3);return e>=0?e:0}},{key:"_setExpiresTimer",value:function(){var e=this;clearTimeout(this.expires_timer),setTimeout(function(){e.is_final_notify_sent||(e.terminated_reason="timeout",e.is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this.expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r.contact+=';+sip.instance=""'),r.credential=m,r._state="init",r.id=null,r.expires_timer=null,r.expires_timestamp=null,r.headers=c.cloneArray(_);var g=r.event_name;return r.event_id&&(g+=";id=".concat(r.event_id)),r.headers=r.headers.concat(["Event: ".concat(g),"Expires: ".concat(r.expires),"Accept: ".concat(r.accept),"Contact: ".concat(r.contact)]),r.allow_events&&r.headers.push("Allow-Events: ".concat(r.allow_events)),r.is_terminated=!1,r.route_set=null,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this.params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){null===this.params.to_tag&&(this.params.to_tag=e.to_tag,this.id="".concat(this.params.call_id).concat(this.params.from_tag).concat(this.params.to_tag),f("added dialog id=",this.id),this._ua.newDialog(this),this.route_set=e.getHeaders("record-route").reverse(),this.route_set.length>0&&(this.params.route_set=this.route_set));var t=this._getExpires(e);if(-1===t)return void d("response without Expires header");t>0&&(this.expires_timestamp=(new Date).getTime()+1e3*t,this._scheduleSubscribe(this._calculateTimeoutMs(t)))}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this.event_name||r!==this.event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this.is_first_notify_request&&(this.is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this.expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),clearTimeout(this.expires_timer),this.expires_timestamp=a,this._scheduleSubscribe(this._calculateTimeoutMs(l)))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this.headers.slice();if(e){if(!this.content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this.content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("unsubscribe()");var t=this.headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(e,t),this._dialogTerminated(_.SEND_UNSUBSCRIBE)}},{key:"state",get:function(){return this._state}},{key:"_dialogTerminated",value:function(e){var t=this;this.is_terminated||(this.is_terminated=!0,this._state="terminated",clearTimeout(this.expires_timer),this.id&&setTimeout(function(){f("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this.params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this.target,this.params,t,e,this,this.credential)}},{key:"_getExpires",value:function(e){var t=e.getHeader("expires");return t?parseInt(t):-1}},{key:"_calculateTimeoutMs",value:function(e){return e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3}},{key:"_scheduleSubscribe",value:function(e){var t=this;f("next SUBSCRIBE will be sent in ".concat(Math.floor(e/1e3)," sec")),this.expires_timer=setTimeout(function(){t.expires_timer=void 0,t._send(null,t.headers)},e)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer(),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n._expires),"Contact: ".concat(n._contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(d.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._is_final_notify_sent||(this._is_final_notify_sent=!0,this._dialogTerminated(d.SEND_FINAL_NOTIFY),this._terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("unsubscribe()");var t=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(e,t),this._dialogTerminated(_.SEND_UNSUBSCRIBE)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=this;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&setTimeout(function(){f("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 9a09366cb..e81cfc3f6 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -55,40 +55,38 @@ module.exports = class Notifier extends EventEmitter super(); this._ua = ua; - this.expires_timestamp = null; - this.expires_timer = null; + this._expires_timestamp = null; + this._expires_timer = null; this._state = pending ? 'pending' : 'active'; - this.is_final_notify_sent = false; - this.is_first_notify_response = true; - this.id = null; - this.allow_events = allow_events; - this.event_name = subscribe.getHeader('event'); + this._is_final_notify_sent = false; + this._is_first_notify_response = true; + this._id = null; + this._allow_events = allow_events; + this._event_name = subscribe.getHeader('event'); if (!content_type) { throw new TypeError('content_type is undefined'); } - this.content_type = content_type; - this.expires = parseInt(subscribe.getHeader('expires')); - this.credential = credential; - this.contact = ``; - this.rcseq = subscribe.cseq; + this._content_type = content_type; + this._expires = parseInt(subscribe.getHeader('expires')); + this._credential = credential; + this._contact = ``; + this._headers = Utils.cloneArray(headers); + this._headers.push(`Event: ${this._event_name}`); + this._headers.push(`Contact: ${this._contact}`); - this.headers = Utils.cloneArray(headers); - this.headers.push(`Event: ${this.event_name}`); - this.headers.push(`Contact: ${this.contact}`); - - if (this.allow_events) + if (this._allow_events) { - this.headers.push(`Allow-Events: ${this.allow_events}`); + this._headers.push(`Allow-Events: ${this._allow_events}`); } - this.target = subscribe.from.uri.user; + this._target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); // NOTIFY request params set according received SUBSCRIBE - this.params = { + this._params = { from : subscribe.to, from_tag : subscribe.to_tag, to : subscribe.from, @@ -98,22 +96,21 @@ module.exports = class Notifier extends EventEmitter }; // Dialog id - this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + this._id = `${this._params.call_id}${this._params.from_tag}${this._params.to_tag}`; - debug('add dialog id=', this.id); + debug('add dialog id=', this._id); this._ua.newDialog(this); - // Set expires time-stamp and timer - this._setExpiresTimestamp(); + // Set expires timer and timestamp this._setExpiresTimer(); - this.is_terminated = false; - this.terminated_reason = undefined; + this._is_terminated = false; + this._terminated_reason = undefined; // Custom session empty object for high level use. this.data = {}; - subscribe.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); + subscribe.reply(200, null, [ `Expires: ${this._expires}`, `Contact: ${this._contact}` ]); } /** @@ -121,7 +118,7 @@ module.exports = class Notifier extends EventEmitter */ onAuthenticated() { - this.params.cseq++; + this._params.cseq++; } onRequestTimeout() @@ -138,14 +135,15 @@ module.exports = class Notifier extends EventEmitter { if (response.status_code >= 200 && response.status_code < 300) { - if (this.is_first_notify_response) + if (this._is_first_notify_response) { - this.is_first_notify_response = false; - this.route_set = response.getHeaders('record-route').reverse(); + this._is_first_notify_response = false; + + const route_set = response.getHeaders('record-route').reverse(); - if (this.route_set.length > 0) + if (route_set.length > 0) { - this.params.route_set = this.route_set; + this._params.route_set = route_set; } } } @@ -180,12 +178,12 @@ module.exports = class Notifier extends EventEmitter debug(`Missed expires header. Set by default ${h}`); } - this.expires = parseInt(h); - request.reply(200, null, [ `Expires: ${this.expires}`, `Contact: ${this.contact}` ]); + this._expires = parseInt(h); + request.reply(200, null, [ `Expires: ${this._expires}`, `Contact: ${this._contact}` ]); const body = request.body; const content_type = request.getHeader('content-type'); - const is_unsubscribe = this.expires === 0; + const is_unsubscribe = this._expires === 0; debug('emit "subscribe"'); this.emit('subscribe', is_unsubscribe, request, body, content_type); @@ -196,7 +194,6 @@ module.exports = class Notifier extends EventEmitter } else { - this._setExpiresTimestamp(); this._setExpiresTimer(); } } @@ -230,25 +227,32 @@ module.exports = class Notifier extends EventEmitter if (this._state !== 'terminated') { - subs_state += `;expires=${this._getExpiresTimestamp()}`; + let expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); + + if (expires < 0) + { + expires = 0; + } + + subs_state += `;expires=${expires}`; } - else if (this.terminated_reason) + else if (this._terminated_reason) { - subs_state += `;reason=${this.terminated_reason}`; + subs_state += `;reason=${this._terminated_reason}`; } - const headers = this.headers.slice(); + const headers = this._headers.slice(); headers.push(`Subscription-State: ${subs_state}`); if (body) { - headers.push(`Content-Type: ${this.content_type}`); + headers.push(`Content-Type: ${this._content_type}`); } - this.params.cseq++; - this._ua.sendRequest(JsSIP_C.NOTIFY, this.target, this.params, headers, body, - this, this.credential); + this._params.cseq++; + this._ua.sendRequest(JsSIP_C.NOTIFY, this._target, this._params, headers, body, + this, this._credential); } /** @@ -260,14 +264,14 @@ module.exports = class Notifier extends EventEmitter { debug('sendFinalNotify()'); - if (this.is_final_notify_sent) + if (this._is_final_notify_sent) { return; } - this.is_final_notify_sent = true; + this._is_final_notify_sent = true; this._dialogTerminated(C.SEND_FINAL_NOTIFY); - this.terminated_reason = reason; + this._terminated_reason = reason; this.sendNotify(body); } @@ -278,24 +282,32 @@ module.exports = class Notifier extends EventEmitter { return this._state; } + + /** + * Get dialog id + */ + get id() + { + return this._id; + } /** * Private API. */ _dialogTerminated(termination_code) { - if (this.is_terminated) + if (this._is_terminated) { return; } - this.is_terminated = true; + this._is_terminated = true; this._state = 'terminated'; - clearTimeout(this.expires_timer); + clearTimeout(this._expires_timer); - if (this.id) + if (this._id) { - debug('remove dialog id=', this.id); + debug('remove dialog id=', this._id); this._ua.destroyDialog(this); } @@ -306,32 +318,22 @@ module.exports = class Notifier extends EventEmitter this.emit('terminated', termination_code, send_final_notify); } - _setExpiresTimestamp() - { - this.expires_timestamp = new Date().getTime() + (this.expires * 1000); - } - - _getExpiresTimestamp() - { - const delta = Math.floor((this.expires_timestamp - new Date().getTime()) / 1000); - - return delta >= 0 ? delta : 0; - } - _setExpiresTimer() { - clearTimeout(this.expires_timer); + this._expires_timestamp = new Date().getTime() + (this._expires * 1000); + + clearTimeout(this._expires_timer); setTimeout(() => { - if (this.is_final_notify_sent) + if (this._is_final_notify_sent) { return; } - this.terminated_reason = 'timeout'; - this.is_final_notify_sent = true; + this._terminated_reason = 'timeout'; + this._is_final_notify_sent = true; this.sendNotify(); this._dialogTerminated(C.SUBSCRIPTION_EXPIRED); - }, this.expires * 1000); + }, this._expires * 1000); } }; \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 586da7e56..ebd136e1d 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -66,7 +66,7 @@ module.exports = class Subscriber extends EventEmitter throw new TypeError('target is undefined'); } - this.target = target; + this._target = target; if (!event_name) { @@ -80,80 +80,80 @@ module.exports = class Subscriber extends EventEmitter throw new TypeError('event_name - wrong format'); } - this.event_name = parsed.event; - this.event_id = parsed.params && parsed.params.id; + this._event_name = parsed.event; + this._event_id = parsed.params && parsed.params.id; if (!accept) { throw new TypeError('accept is undefined'); } - this.accept = accept; + this._accept = accept; if (!expires) { expires = 900; } - this.expires = expires; - this.allow_events = allow_events; + this._expires = expires; + this._allow_events = allow_events; // used to subscribe with body - this.content_type = content_type; - this.is_first_notify_request = true; + this._content_type = content_type; - this.params = Utils.cloneObject(params); + this._is_first_notify_request = true; - if (!this.params.from_uri) + this._params = Utils.cloneObject(params); + + if (!this._params.from_uri) { - this.params.from_uri = this._ua.configuration.uri; + this._params.from_uri = this._ua.configuration.uri; } // set SUBSCRIBE dialog parameters - this.params.from_tag = Utils.newTag(); - this.params.to_tag = null; - this.params.call_id = Utils.createRandomToken(20); - this.params.cseq = Math.floor((Math.random() * 10000) + 1); + this._params.from_tag = Utils.newTag(); + this._params.to_tag = null; + this._params.call_id = Utils.createRandomToken(20); + this._params.cseq = Math.floor((Math.random() * 10000) + 1); // Create contact - this.contact = ``; - this.contact += `;+sip.instance=""`; + this._contact = ``; + this._contact += `;+sip.instance=""`; // Optional, used if credential is different from REGISTER/INVITE - this.credential = credential; + this._credential = credential; // Dialog state: init, notify_wait, pending, active, terminated this._state = 'init'; // Dialog id - this.id = null; + this._id = null; // To refresh subscription - this.expires_timer = null; - this.expires_timestamp = null; + this._expires_timer = null; + this._expires_timestamp = null; - this.headers = Utils.cloneArray(headers); - let event_value = this.event_name; + this._headers = Utils.cloneArray(headers); + let event_value = this._event_name; - if (this.event_id) + if (this._event_id) { - event_value += `;id=${this.event_id}`; + event_value += `;id=${this._event_id}`; } - this.headers = this.headers.concat([ + this._headers = this._headers.concat([ `Event: ${event_value}`, - `Expires: ${this.expires}`, - `Accept: ${this.accept}`, - `Contact: ${this.contact}` + `Expires: ${this._expires}`, + `Accept: ${this._accept}`, + `Contact: ${this._contact}` ]); - if (this.allow_events) + if (this._allow_events) { - this.headers.push(`Allow-Events: ${this.allow_events}`); + this._headers.push(`Allow-Events: ${this._allow_events}`); } - this.is_terminated = false; - this.route_set = null; + this._is_terminated = false; // Custom session empty object for high level use. this.data = {}; @@ -164,7 +164,7 @@ module.exports = class Subscriber extends EventEmitter */ onAuthenticated() { - this.params.cseq++; + this._params.cseq++; } onRequestTimeout() @@ -181,34 +181,38 @@ module.exports = class Subscriber extends EventEmitter { if (response.status_code >= 200 && response.status_code < 300) { - if (this.params.to_tag === null) + if (this._params.to_tag === null) { - this.params.to_tag = response.to_tag; - this.id = `${this.params.call_id}${this.params.from_tag}${this.params.to_tag}`; + this._params.to_tag = response.to_tag; + this._id = `${this._params.call_id}${this._params.from_tag}${this._params.to_tag}`; - debug('added dialog id=', this.id); + debug('added dialog id=', this._id); this._ua.newDialog(this); - this.route_set = response.getHeaders('record-route').reverse(); + const route_set = response.getHeaders('record-route').reverse(); - if (this.route_set.length > 0) + if (route_set.length > 0) { - this.params.route_set = this.route_set; + this._params.route_set = route_set; } } - const expires = this._getExpires(response); - if (expires === -1) + let expires_value = response.getHeader('expires'); + + if (!expires_value) { debugerror('response without Expires header'); - return; + // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header + // Use workaround expires value. + expires_value = '900'; } - if (expires > 0) + const expires = parseInt(expires_value); + + if (expires > 0) { - this.expires_timestamp = new Date().getTime() + (expires * 1000); - this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + this._scheduleSubscribe(expires); } } else if (response.status_code === 401 || response.status_code === 407) @@ -249,7 +253,7 @@ module.exports = class Subscriber extends EventEmitter const event_name = event_header.event; const event_id = event_header.params && event_header.params.id; - if (event_name !== this.event_name || event_id !== this.event_id) + if (event_name !== this._event_name || event_id !== this._event_id) { debugerror('Event header does not match SUBSCRIBE'); request.reply(489); @@ -272,9 +276,9 @@ module.exports = class Subscriber extends EventEmitter request.reply(200); - if (this.is_first_notify_request) + if (this._is_first_notify_request) { - this.is_first_notify_request = false; + this._is_first_notify_request = false; // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? } @@ -292,13 +296,11 @@ module.exports = class Subscriber extends EventEmitter const max_time_deviation = 2000; // expiration time is shorter and the difference is not too small - if (this.expires_timestamp - expires_timestamp > max_time_deviation) + if (this._expires_timestamp - expires_timestamp > max_time_deviation) { debug('update sending re-SUBSCRIBE time'); - clearTimeout(this.expires_timer); - this.expires_timestamp = expires_timestamp; - this._scheduleSubscribe(this._calculateTimeoutMs(expires)); + this._scheduleSubscribe(expires); } } } @@ -343,15 +345,15 @@ module.exports = class Subscriber extends EventEmitter { this._state = 'notify_wait'; } - const headers = this.headers.slice(); + const headers = this._headers.slice(); if (body) { - if (!this.content_type) + if (!this._content_type) { throw new TypeError('content_type is undefined'); } - headers.push(`Content-Type: ${this.content_type}`); + headers.push(`Content-Type: ${this._content_type}`); } this._send(body, headers); @@ -366,7 +368,7 @@ module.exports = class Subscriber extends EventEmitter debug('unsubscribe()'); // Set header Expires: 0 - const headers = this.headers.map((s) => + const headers = this._headers.map((s) => { return s.startsWith('Expires') ? 'Expires: 0' : s; }); @@ -382,6 +384,14 @@ module.exports = class Subscriber extends EventEmitter { return this._state; } + + /** + * Get dialog id + */ + get id() + { + return this._id; + } /** * Private API. @@ -389,17 +399,17 @@ module.exports = class Subscriber extends EventEmitter _dialogTerminated(termination_code) { // to prevent duplicate emit terminated - if (this.is_terminated) + if (this._is_terminated) { return; } - this.is_terminated = true; + this._is_terminated = true; this._state = 'terminated'; - clearTimeout(this.expires_timer); + clearTimeout(this._expires_timer); // remove dialog with some delay to receiving possible final NOTIFY - if (this.id) + if (this._id) { setTimeout(() => { @@ -415,32 +425,25 @@ module.exports = class Subscriber extends EventEmitter _send(body, headers) { - this.params.cseq++; - this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this.target, this.params, headers, - body, this, this.credential); + this._params.cseq++; + this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this._target, this._params, headers, + body, this, this._credential); } - _getExpires(r) + _scheduleSubscribe(expires) { - const e = r.getHeader('expires'); - - return e ? parseInt(e) : -1; - } - - _calculateTimeoutMs(expires) - { - return expires >= 140 ? (expires * 1000 / 2) + const timeout = expires >= 140 ? (expires * 1000 / 2) + Math.floor(((expires / 2) - 70) * 1000 * Math.random()) : (expires * 1000) - 5000; - } - _scheduleSubscribe(timeout) - { + this._expires_timestamp = new Date().getTime() + (expires * 1000); + debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); - this.expires_timer = setTimeout(() => + clearTimeout(this._expires_timer); + this._expires_timer = setTimeout(() => { - this.expires_timer = undefined; - this._send(null, this.headers); + this._expires_timer = null; + this._send(null, this._headers); }, timeout); } }; \ No newline at end of file From d23b4770e0047e74a487e488dd3d11283b58343a Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 26 May 2021 13:01:53 +0300 Subject: [PATCH 24/70] improved ts definitions --- lib/Notifier.d.ts | 13 +++++++++++++ lib/Subscriber.d.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/Notifier.d.ts b/lib/Notifier.d.ts index a1922e2b8..4ab1188fa 100644 --- a/lib/Notifier.d.ts +++ b/lib/Notifier.d.ts @@ -2,9 +2,22 @@ import {EventEmitter} from 'events' import {SUBSCRIBE, NOTIFY} from './Constants' import * as Utils from './Utils' +declare enum NotifierTerminatedCode { + NOTIFY_RESPONSE_TIMEOUT = 0, + NOTIFY_TRANSPORT_ERROR = 1, + NOTIFY_NON_OK_RESPONSE = 2, + NOTIFY_FAILED_AUTHENTICATION = 3, + SEND_FINAL_NOTIFY = 4, + RECEIVE_UNSUBSCRIBE = 5, + SUBSCRIPTION_EXPIRED = 6 +} + export class Notifier extends EventEmitter { setActiveState(): void; sendNotify(body?: string): void; sendFinalNotify(body?: string, reason?: string): void; get state(): string; + get id(): string; + static get C(): typeof NotifierTerminatedCode; + get C(): typeof NotifierTerminatedCode; } \ No newline at end of file diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts index ef94efc90..db018fba6 100644 --- a/lib/Subscriber.d.ts +++ b/lib/Subscriber.d.ts @@ -2,8 +2,21 @@ import {EventEmitter} from 'events' import {SUBSCRIBE, NOTIFY} from './Constants' import * as Utils from './Utils' +declare enum SubscriberTerminatedCode { + SUBSCRIBE_RESPONSE_TIMEOUT = 0, + SUBSCRIBE_TRANSPORT_ERROR = 1, + SUBSCRIBE_NON_OK_RESPONSE = 2, + SUBSCRIBE_FAILED_AUTHENTICATION = 3, + SEND_UNSUBSCRIBE = 4, + RECEIVE_FINAL_NOTIFY = 5, + RECEIVE_BAD_NOTIFY = 6 +} + export class Subscriber extends EventEmitter { subscribe(body?: string): void; unsubscribe(body?: string): void; get state(): string; + get id(): string; + static get C(): typeof SubscriberTerminatedCode; + get C(): typeof SubscriberTerminatedCode; } \ No newline at end of file From b4d25354bfa0915060f6e2847693116e237805de Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 26 May 2021 21:35:27 +0300 Subject: [PATCH 25/70] subscriber termination according rfc 6665 4.1.2 --- dist/jssip.js | 41 ++++++++++++++++++++++++++++------------- dist/jssip.min.js | 2 +- lib/Subscriber.d.ts | 2 +- lib/Subscriber.js | 40 ++++++++++++++++++++++++++++++---------- 4 files changed, 60 insertions(+), 25 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index d96e72c84..cc4013ed0 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22674,7 +22674,7 @@ var C = { SUBSCRIBE_TRANSPORT_ERROR: 1, SUBSCRIBE_NON_OK_RESPONSE: 2, SUBSCRIBE_FAILED_AUTHENTICATION: 3, - SEND_UNSUBSCRIBE: 4, + UNSUBSCRIBE_TIMEOUT: 4, RECEIVE_FINAL_NOTIFY: 5, RECEIVE_BAD_NOTIFY: 6 }; @@ -22775,7 +22775,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._id = null; // To refresh subscription _this._expires_timer = null; - _this._expires_timestamp = null; + _this._expires_timestamp = null; // To prvent duplicate un-SUBSCRIBE sending. + + _this._send_unsubscribe = false; // After send un-subscribe wait final NOTIFY limited time. + + _this._unsubscribe_timeout_timer = null; _this._headers = Utils.cloneArray(headers); var event_value = _this._event_name; @@ -22988,16 +22992,29 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "unsubscribe", value: function unsubscribe() { + var _this2 = this; + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('unsubscribe()'); // Set header Expires: 0 + debug('unsubscribe()'); // Prevent duplication unsubscribe. + + if (this._send_unsubscribe) { + debugerror('unsubscribe has already been sent'); + return; + } + + this._send_unsubscribe = true; // Set header Expires: 0 var headers = this._headers.map(function (s) { return s.startsWith('Expires') ? 'Expires: 0' : s; }); - this._send(body, headers); + this._send(body, headers); // Waiting for the final notify for a while + - this._dialogTerminated(C.SEND_UNSUBSCRIBE); + var final_notify_timeout = 30000; + this._unsubscribe_timeout_timer = setTimeout(function () { + _this2._dialogTerminated(C.UNSUBSCRIBE_TIMEOUT); + }, final_notify_timeout); } /** * Get dialog state @@ -23024,23 +23041,21 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_dialogTerminated", value: function _dialogTerminated(termination_code) { - var _this2 = this; - // to prevent duplicate emit terminated if (this._is_terminated) { return; } this._is_terminated = true; - this._state = 'terminated'; - clearTimeout(this._expires_timer); // remove dialog with some delay to receiving possible final NOTIFY + this._state = 'terminated'; // clear timers + + clearTimeout(this._expires_timer); + clearTimeout(this._unsubscribe_timeout_timer); if (this._id) { - setTimeout(function () { - debug('removed dialog id=', _this2.id); + debug('removed dialog id=', this.id); - _this2._ua.destroyDialog(_this2); - }, 32000); + this._ua.destroyDialog(this); } debug("emit \"terminated\" termination code=".concat(termination_code, "\"")); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 8ceeaf9b8..233c42dd9 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer(),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n._expires),"Contact: ".concat(n._contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(d.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._is_final_notify_sent||(this._is_final_notify_sent=!0,this._dialogTerminated(d.SEND_FINAL_NOTIFY),this._terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("unsubscribe()");var t=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(e,t),this._dialogTerminated(_.SEND_UNSUBSCRIBE)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=this;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&setTimeout(function(){f("removed dialog id=",t.id),t._ua.destroyDialog(t)},32e3),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer(),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n._expires),"Contact: ".concat(n._contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(d.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._is_final_notify_sent||(this._is_final_notify_sent=!0,this._dialogTerminated(d.SEND_FINAL_NOTIFY),this._terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts index db018fba6..94b91e7c9 100644 --- a/lib/Subscriber.d.ts +++ b/lib/Subscriber.d.ts @@ -7,7 +7,7 @@ declare enum SubscriberTerminatedCode { SUBSCRIBE_TRANSPORT_ERROR = 1, SUBSCRIBE_NON_OK_RESPONSE = 2, SUBSCRIBE_FAILED_AUTHENTICATION = 3, - SEND_UNSUBSCRIBE = 4, + UNSUBSCRIBE_TIMEOUT = 4, RECEIVE_FINAL_NOTIFY = 5, RECEIVE_BAD_NOTIFY = 6 } diff --git a/lib/Subscriber.js b/lib/Subscriber.js index ebd136e1d..790a9950b 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -15,7 +15,7 @@ const C = { SUBSCRIBE_TRANSPORT_ERROR : 1, SUBSCRIBE_NON_OK_RESPONSE : 2, SUBSCRIBE_FAILED_AUTHENTICATION : 3, - SEND_UNSUBSCRIBE : 4, + UNSUBSCRIBE_TIMEOUT : 4, RECEIVE_FINAL_NOTIFY : 5, RECEIVE_BAD_NOTIFY : 6 }; @@ -131,7 +131,13 @@ module.exports = class Subscriber extends EventEmitter // To refresh subscription this._expires_timer = null; - this._expires_timestamp = null; + this._expires_timestamp = null; + + // To prvent duplicate un-SUBSCRIBE sending. + this._send_unsubscribe = false; + + // After send un-subscribe wait final NOTIFY limited time. + this._unsubscribe_timeout_timer = null; this._headers = Utils.cloneArray(headers); let event_value = this._event_name; @@ -367,6 +373,15 @@ module.exports = class Subscriber extends EventEmitter { debug('unsubscribe()'); + // Prevent duplication unsubscribe. + if (this._send_unsubscribe) + { + debugerror('unsubscribe has already been sent'); + + return; + } + this._send_unsubscribe = true; + // Set header Expires: 0 const headers = this._headers.map((s) => { @@ -374,7 +389,14 @@ module.exports = class Subscriber extends EventEmitter }); this._send(body, headers); - this._dialogTerminated(C.SEND_UNSUBSCRIBE); + + // Waiting for the final notify for a while + const final_notify_timeout = 30000; + + this._unsubscribe_timeout_timer = setTimeout(() => + { + this._dialogTerminated(C.UNSUBSCRIBE_TIMEOUT); + }, final_notify_timeout); } /** @@ -406,17 +428,15 @@ module.exports = class Subscriber extends EventEmitter this._is_terminated = true; this._state = 'terminated'; + + // clear timers clearTimeout(this._expires_timer); + clearTimeout(this._unsubscribe_timeout_timer); - // remove dialog with some delay to receiving possible final NOTIFY if (this._id) { - setTimeout(() => - { - debug('removed dialog id=', this.id); - - this._ua.destroyDialog(this); - }, 32000); + debug('removed dialog id=', this.id); + this._ua.destroyDialog(this); } debug(`emit "terminated" termination code=${termination_code}"`); From 293344a18ad61d4c4f1cf519ce074bebe254a74c Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 27 May 2021 01:02:59 +0300 Subject: [PATCH 26/70] adding fetch-subscribe support. work in progress --- dist/jssip.js | 45 +++++++++++++++++++++++++++++---------------- dist/jssip.min.js | 2 +- lib/Notifier.js | 36 +++++++++++++++++++++++++----------- lib/Subscriber.js | 12 +++++++----- 4 files changed, 62 insertions(+), 33 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index cc4013ed0..d620f8a2a 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16703,21 +16703,31 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { to_tag: subscribe.from_tag, call_id: subscribe.call_id, cseq: Math.floor(Math.random() * 10000 + 1) - }; // Dialog id + }; // For non-fetch subscribe add dialog - _this._id = "".concat(_this._params.call_id).concat(_this._params.from_tag).concat(_this._params.to_tag); - debug('add dialog id=', _this._id); + if (_this._expires > 0) { + // Dialog id + _this._id = "".concat(_this._params.call_id).concat(_this._params.from_tag).concat(_this._params.to_tag); + debug('add dialog id=', _this._id); - _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timer and timestamp + _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timer and timestamp - _this._setExpiresTimer(); + _this._setExpiresTimer(); + } _this._is_terminated = false; _this._terminated_reason = undefined; // Custom session empty object for high level use. _this.data = {}; - subscribe.reply(200, null, ["Expires: ".concat(_this._expires), "Contact: ".concat(_this._contact)]); + subscribe.reply(200, null, ["Expires: ".concat(_this._expires), "Contact: ".concat(_this._contact)]); // RFC 6665 4.4.3: fetch subscribe + + if (_this._expires === 0) { + debug('fetch subscribe'); + + _this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); + } + return _this; } /** @@ -16823,7 +16833,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendNotify", value: function sendNotify() { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('sendNotify()'); + debug('sendNotify()'); // Prevent send notify after final notify + + if (this._is_final_notify_sent) { + debugerror('final notify has sent'); + return; + } + var subs_state = this._state; if (this._state !== 'terminated') { @@ -16862,11 +16878,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; debug('sendFinalNotify()'); - - if (this._is_final_notify_sent) { - return; - } - this._is_final_notify_sent = true; this._dialogTerminated(C.SEND_FINAL_NOTIFY); @@ -22744,7 +22755,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._accept = accept; - if (!expires) { + if (expires !== 0 && !expires) { expires = 900; } @@ -22827,6 +22838,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "onReceiveResponse", value: function onReceiveResponse(response) { if (response.status_code >= 200 && response.status_code < 300) { + // add dialog to stack dialogs table if (this._params.to_tag === null) { this._params.to_tag = response.to_tag; this._id = "".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag); @@ -22839,11 +22851,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (route_set.length > 0) { this._params.route_set = route_set; } - } + } // check expires value + var expires_value = response.getHeader('expires'); - if (!expires_value) { + if (expires_value !== 0 && !expires_value) { debugerror('response without Expires header'); // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header // Use workaround expires value. @@ -22985,7 +22998,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._send(body, headers); } /** - * Send un-SUBSCRIBE + * Send un-SUBSCRIBE (or fetch-SUBSCRIBE if in constructor set expires=0) * -param {String} body. Optional. */ diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 233c42dd9..b2bb6f566 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer(),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n._expires),"Contact: ".concat(n._contact)]),n}return t=_,r=[{key:"C",get:function(){return d}}],(n=[{key:"C",get:function(){return d}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(d.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(d.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(d.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(d.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(d.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("sendNotify()");var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._is_final_notify_sent||(this._is_final_notify_sent=!0,this._dialogTerminated(d.SEND_FINAL_NOTIFY),this._terminated_reason=t,this.sendNotify(e))}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===d.RECEIVE_UNSUBSCRIBE||e===d.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(d.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),_}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n._expires),"Contact: ".concat(n._contact)]),0===n._expires&&(f("fetch subscribe"),n._dialogTerminated(_.RECEIVE_UNSUBSCRIBE)),n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY),this._terminated_reason=t,this.sendNotify(e)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.RECEIVE_UNSUBSCRIBE||e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index e81cfc3f6..48c7b4292 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -95,14 +95,18 @@ module.exports = class Notifier extends EventEmitter cseq : Math.floor((Math.random() * 10000) + 1) }; - // Dialog id - this._id = `${this._params.call_id}${this._params.from_tag}${this._params.to_tag}`; + // For non-fetch subscribe add dialog + if (this._expires > 0) + { + // Dialog id + this._id = `${this._params.call_id}${this._params.from_tag}${this._params.to_tag}`; - debug('add dialog id=', this._id); - this._ua.newDialog(this); + debug('add dialog id=', this._id); + this._ua.newDialog(this); - // Set expires timer and timestamp - this._setExpiresTimer(); + // Set expires timer and timestamp + this._setExpiresTimer(); + } this._is_terminated = false; this._terminated_reason = undefined; @@ -111,6 +115,13 @@ module.exports = class Notifier extends EventEmitter this.data = {}; subscribe.reply(200, null, [ `Expires: ${this._expires}`, `Contact: ${this._contact}` ]); + + // RFC 6665 4.4.3: fetch subscribe + if (this._expires === 0) + { + debug('fetch subscribe'); + this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); + } } /** @@ -223,6 +234,14 @@ module.exports = class Notifier extends EventEmitter { debug('sendNotify()'); + // Prevent send notify after final notify + if (this._is_final_notify_sent) + { + debugerror('final notify has sent'); + + return; + } + let subs_state = this._state; if (this._state !== 'terminated') @@ -264,11 +283,6 @@ module.exports = class Notifier extends EventEmitter { debug('sendFinalNotify()'); - if (this._is_final_notify_sent) - { - return; - } - this._is_final_notify_sent = true; this._dialogTerminated(C.SEND_FINAL_NOTIFY); this._terminated_reason = reason; diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 790a9950b..57b22919c 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -90,7 +90,7 @@ module.exports = class Subscriber extends EventEmitter this._accept = accept; - if (!expires) + if (expires !== 0 && !expires) { expires = 900; } @@ -131,7 +131,7 @@ module.exports = class Subscriber extends EventEmitter // To refresh subscription this._expires_timer = null; - this._expires_timestamp = null; + this._expires_timestamp = null; // To prvent duplicate un-SUBSCRIBE sending. this._send_unsubscribe = false; @@ -187,6 +187,7 @@ module.exports = class Subscriber extends EventEmitter { if (response.status_code >= 200 && response.status_code < 300) { + // add dialog to stack dialogs table if (this._params.to_tag === null) { this._params.to_tag = response.to_tag; @@ -196,16 +197,17 @@ module.exports = class Subscriber extends EventEmitter this._ua.newDialog(this); const route_set = response.getHeaders('record-route').reverse(); - + if (route_set.length > 0) { this._params.route_set = route_set; } } + // check expires value let expires_value = response.getHeader('expires'); - if (!expires_value) + if (expires_value !== 0 && !expires_value) { debugerror('response without Expires header'); @@ -366,7 +368,7 @@ module.exports = class Subscriber extends EventEmitter } /** - * Send un-SUBSCRIBE + * Send un-SUBSCRIBE (or fetch-SUBSCRIBE if in constructor set expires=0) * -param {String} body. Optional. */ unsubscribe(body = null) From 83477141217da27f9c2f6e8d02af7f88c66223c6 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 27 May 2021 10:14:12 +0300 Subject: [PATCH 27/70] added fetch-subscribe support --- dist/jssip.js | 32 +++++++++++++++++++------------- dist/jssip.min.js | 2 +- lib/Notifier.d.ts | 1 + lib/Notifier.js | 35 +++++++++++++++++++++-------------- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index d620f8a2a..1f17a4b54 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16666,6 +16666,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { debug('new'); _this = _super.call(this); _this._ua = ua; + _this._initial_subscribe = subscribe; _this._expires_timestamp = null; _this._expires_timer = null; _this._state = pending ? 'pending' : 'active'; @@ -16720,14 +16721,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._terminated_reason = undefined; // Custom session empty object for high level use. _this.data = {}; - subscribe.reply(200, null, ["Expires: ".concat(_this._expires), "Contact: ".concat(_this._contact)]); // RFC 6665 4.4.3: fetch subscribe - - if (_this._expires === 0) { - debug('fetch subscribe'); - - _this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); - } - return _this; } /** @@ -16774,7 +16767,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } /** - * Dialog callback + * Dialog callback. + * Called also for initial subscribe + * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0) */ }, { @@ -16811,6 +16806,17 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * User API */ + /** + * The called after constructor and event settings. + * To use events 'subscribe' and 'terminated' for initial subscribe + */ + + }, { + key: "start", + value: function start() { + debug('start()'); + this.receiveRequest(this._initial_subscribe); + } /** * Switch pending dialog state to active */ @@ -16878,12 +16884,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; debug('sendFinalNotify()'); + this._state = 'terminated'; + this._terminated_reason = reason; + this.sendNotify(body); this._is_final_notify_sent = true; this._dialogTerminated(C.SEND_FINAL_NOTIFY); - - this._terminated_reason = reason; - this.sendNotify(body); } /** * Get dialog state @@ -16924,7 +16930,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._ua.destroyDialog(this); } - var send_final_notify = termination_code === C.RECEIVE_UNSUBSCRIBE || termination_code === C.SUBSCRIPTION_EXPIRED; + var send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; debug("emit \"terminated\" termination code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); this.emit('terminated', termination_code, send_final_notify); } diff --git a/dist/jssip.min.js b/dist/jssip.min.js index b2bb6f566..1f7c994f7 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},r.reply(200,null,["Expires: ".concat(n._expires),"Contact: ".concat(n._contact)]),0===n._expires&&(f("fetch subscribe"),n._dialogTerminated(_.RECEIVE_UNSUBSCRIBE)),n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY),this._terminated_reason=t,this.sendNotify(e)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.RECEIVE_UNSUBSCRIBE||e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.d.ts b/lib/Notifier.d.ts index 4ab1188fa..9216c9ccc 100644 --- a/lib/Notifier.d.ts +++ b/lib/Notifier.d.ts @@ -13,6 +13,7 @@ declare enum NotifierTerminatedCode { } export class Notifier extends EventEmitter { + start(): void; setActiveState(): void; sendNotify(body?: string): void; sendFinalNotify(body?: string, reason?: string): void; diff --git a/lib/Notifier.js b/lib/Notifier.js index 48c7b4292..41433099e 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -55,6 +55,7 @@ module.exports = class Notifier extends EventEmitter super(); this._ua = ua; + this._initial_subscribe = subscribe; this._expires_timestamp = null; this._expires_timer = null; this._state = pending ? 'pending' : 'active'; @@ -113,15 +114,6 @@ module.exports = class Notifier extends EventEmitter // Custom session empty object for high level use. this.data = {}; - - subscribe.reply(200, null, [ `Expires: ${this._expires}`, `Contact: ${this._contact}` ]); - - // RFC 6665 4.4.3: fetch subscribe - if (this._expires === 0) - { - debug('fetch subscribe'); - this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); - } } /** @@ -169,7 +161,9 @@ module.exports = class Notifier extends EventEmitter } /** - * Dialog callback + * Dialog callback. + * Called also for initial subscribe + * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0) */ receiveRequest(request) { @@ -213,6 +207,17 @@ module.exports = class Notifier extends EventEmitter * User API */ + /** + * The called after constructor and event settings. + * To use events 'subscribe' and 'terminated' for initial subscribe + */ + start() + { + debug('start()'); + + this.receiveRequest(this._initial_subscribe); + } + /** * Switch pending dialog state to active */ @@ -283,10 +288,13 @@ module.exports = class Notifier extends EventEmitter { debug('sendFinalNotify()'); - this._is_final_notify_sent = true; - this._dialogTerminated(C.SEND_FINAL_NOTIFY); + this._state = 'terminated'; this._terminated_reason = reason; + this.sendNotify(body); + + this._is_final_notify_sent = true; + this._dialogTerminated(C.SEND_FINAL_NOTIFY); } /** @@ -325,8 +333,7 @@ module.exports = class Notifier extends EventEmitter this._ua.destroyDialog(this); } - const send_final_notify = (termination_code === C.RECEIVE_UNSUBSCRIBE - || termination_code === C.SUBSCRIPTION_EXPIRED); + const send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; debug(`emit "terminated" termination code=${termination_code}, send final notify=${send_final_notify}`); this.emit('terminated', termination_code, send_final_notify); From 4799f5734e8819d196ebebf0d2fadcb578e707a9 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 27 May 2021 11:46:23 +0300 Subject: [PATCH 28/70] method arguments use camelCase --- dist/jssip.js | 76 ++++++++++++++++++++++++++++------------------- dist/jssip.min.js | 2 +- lib/Notifier.js | 20 ++++++------- lib/Subscriber.js | 51 ++++++++++++++++++++----------- lib/UA.d.ts | 8 +++-- 5 files changed, 94 insertions(+), 63 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 1f17a4b54..66ff5b65c 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16645,9 +16645,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * -param {Object} ua JsSIP UA * -param {Object} options * -param {IncomingRequest} subscribe - * -param {String} content_type Content-Type header value + * -param {String} contentType Content-Type header value * -param {Array} headers Optional. Additional SIP headers. - * -param {String} allow_events Allow-Events header value. Optional. + * -param {String} allowEvents Allow-Events header value. Optional. * -param {Object} credential. Will have priority over ua.configuration. Optional. * -param {Boolean} pending Set initial dialog state as "pending". Optional. */ @@ -16655,9 +16655,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this; var subscribe = _ref.subscribe, - content_type = _ref.content_type, + contentType = _ref.contentType, headers = _ref.headers, - allow_events = _ref.allow_events, + allowEvents = _ref.allowEvents, credential = _ref.credential, pending = _ref.pending; @@ -16673,14 +16673,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._is_final_notify_sent = false; _this._is_first_notify_response = true; _this._id = null; - _this._allow_events = allow_events; + _this._allow_events = allowEvents; _this._event_name = subscribe.getHeader('event'); - if (!content_type) { - throw new TypeError('content_type is undefined'); + if (!contentType) { + throw new TypeError('contentType is undefined'); } - _this._content_type = content_type; + _this._content_type = contentType; _this._expires = parseInt(subscribe.getHeader('expires')); _this._credential = credential; _this._contact = ""); @@ -16807,7 +16807,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { */ /** - * The called after constructor and event settings. + * The called after constructor and event handlers settings. * To use events 'subscribe' and 'terminated' for initial subscribe */ @@ -16875,7 +16875,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { /** * Send the final NOTIFY request * -param {String} body Optional. - * -param {String} reason To construct Subscription-State. Optional. + * -param {String} reason Optional. To construct Subscription-State. */ }, { @@ -16931,7 +16931,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } var send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; - debug("emit \"terminated\" termination code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); + debug("emit \"terminated\" code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); this.emit('terminated', termination_code, send_final_notify); } }, { @@ -22708,11 +22708,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * -param {Object} ua reference to JsSIP.UA * -param {String} target * -param {Object} options - * -param {String} event_name Event header value. May end with optional ;id=xxx + * -param {String} eventName Event header value. May end with optional ;id=xxx * -param {String} accept Accept header value * -param {Number} expires Expires header value. Optional. Default is 900 - * -param {String} content_type Content-Type header value - * -param {String} allow_events Allow-Events header value. Optional. + * -param {String} contentType Content-Type header value + * -param {String} allowEvents Allow-Events header value. Optional. * -param {Object} params Will have priority over ua.configuration. Optional. * If set please define: to_uri, to_display_name, from_uri, from_display_name * -param {Array} headers Optional. Additional SIP headers. @@ -22721,11 +22721,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { function Subscriber(ua, target, _ref) { var _this; - var event_name = _ref.event_name, + var eventName = _ref.eventName, accept = _ref.accept, expires = _ref.expires, - content_type = _ref.content_type, - allow_events = _ref.allow_events, + contentType = _ref.contentType, + allowEvents = _ref.allowEvents, params = _ref.params, headers = _ref.headers, credential = _ref.credential; @@ -22742,14 +22742,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._target = target; - if (!event_name) { - throw new TypeError('event_name is undefined'); + if (!eventName) { + throw new TypeError('eventName is undefined'); } - var parsed = Grammar.parse(event_name, 'Event'); + var parsed = Grammar.parse(eventName, 'Event'); if (parsed === -1) { - throw new TypeError('event_name - wrong format'); + throw new TypeError('eventName - wrong format'); } _this._event_name = parsed.event; @@ -22766,9 +22766,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _this._expires = expires; - _this._allow_events = allow_events; // used to subscribe with body + _this._allow_events = allowEvents; // used to subscribe with body - _this._content_type = content_type; + _this._content_type = contentType; _this._is_first_notify_request = true; _this._params = Utils.cloneObject(params); @@ -22959,8 +22959,20 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.emit('active'); } - var body = request.body; - var is_final = new_state === 'terminated'; // notify event fired for NOTIFY with body + var body = request.body; // Check if the NOTIFY is final + // For final NOTIFY get optional Subscription-State reason + + var is_final; + var reason; + + if (new_state === 'terminated') { + is_final = true; + reason = undefined; + } else { + is_final = false; + reason = subs_state.reason; + } // notify event fired for NOTIFY with body + if (body) { var content_type = request.getHeader('content-type'); @@ -22969,7 +22981,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (is_final) { - this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY); + this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason); } } /** @@ -22977,7 +22989,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { */ /** - * Send the initial and subsequent SUBSCRIBE request + * Send the initial (non-fetch) and subsequent SUBSCRIBE * -param {String} body. Optional. */ @@ -23004,7 +23016,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._send(body, headers); } /** - * Send un-SUBSCRIBE (or fetch-SUBSCRIBE if in constructor set expires=0) + * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0) * -param {String} body. Optional. */ @@ -23059,7 +23071,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_dialogTerminated", - value: function _dialogTerminated(termination_code) { + value: function _dialogTerminated(terminationCode) { + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; + // to prevent duplicate emit terminated if (this._is_terminated) { return; @@ -23077,8 +23091,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._ua.destroyDialog(this); } - debug("emit \"terminated\" termination code=".concat(termination_code, "\"")); - this.emit('terminated', termination_code); + debug("emit \"terminated\" code=".concat(terminationCode, " ").concat(reason)); + this.emit('terminated', terminationCode, reason); } }, { key: "_send", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 1f7c994f7..aa6804772 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" termination code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}h&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" termination code='.concat(e,'"')),this.emit("terminated",e))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c,h,p=e.body;if("terminated"===i?(c=!0,h=void 0):(c=!1,h=s.reason),p){var m=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",c,e,p,m)}c&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,h)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e," ").concat(t)),this.emit("terminated",e,t))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 41433099e..a40023da2 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -41,13 +41,13 @@ module.exports = class Notifier extends EventEmitter * -param {Object} ua JsSIP UA * -param {Object} options * -param {IncomingRequest} subscribe - * -param {String} content_type Content-Type header value + * -param {String} contentType Content-Type header value * -param {Array} headers Optional. Additional SIP headers. - * -param {String} allow_events Allow-Events header value. Optional. + * -param {String} allowEvents Allow-Events header value. Optional. * -param {Object} credential. Will have priority over ua.configuration. Optional. * -param {Boolean} pending Set initial dialog state as "pending". Optional. */ - constructor(ua, { subscribe, content_type, headers, allow_events, + constructor(ua, { subscribe, contentType, headers, allowEvents, credential, pending }) { debug('new'); @@ -62,15 +62,15 @@ module.exports = class Notifier extends EventEmitter this._is_final_notify_sent = false; this._is_first_notify_response = true; this._id = null; - this._allow_events = allow_events; + this._allow_events = allowEvents; this._event_name = subscribe.getHeader('event'); - if (!content_type) + if (!contentType) { - throw new TypeError('content_type is undefined'); + throw new TypeError('contentType is undefined'); } - this._content_type = content_type; + this._content_type = contentType; this._expires = parseInt(subscribe.getHeader('expires')); this._credential = credential; this._contact = ``; @@ -208,7 +208,7 @@ module.exports = class Notifier extends EventEmitter */ /** - * The called after constructor and event settings. + * The called after constructor and event handlers settings. * To use events 'subscribe' and 'terminated' for initial subscribe */ start() @@ -282,7 +282,7 @@ module.exports = class Notifier extends EventEmitter /** * Send the final NOTIFY request * -param {String} body Optional. - * -param {String} reason To construct Subscription-State. Optional. + * -param {String} reason Optional. To construct Subscription-State. */ sendFinalNotify(body = null, reason = null) { @@ -335,7 +335,7 @@ module.exports = class Notifier extends EventEmitter const send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; - debug(`emit "terminated" termination code=${termination_code}, send final notify=${send_final_notify}`); + debug(`emit "terminated" code=${termination_code}, send final notify=${send_final_notify}`); this.emit('terminated', termination_code, send_final_notify); } diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 57b22919c..a51492a31 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -42,18 +42,18 @@ module.exports = class Subscriber extends EventEmitter * -param {Object} ua reference to JsSIP.UA * -param {String} target * -param {Object} options - * -param {String} event_name Event header value. May end with optional ;id=xxx + * -param {String} eventName Event header value. May end with optional ;id=xxx * -param {String} accept Accept header value * -param {Number} expires Expires header value. Optional. Default is 900 - * -param {String} content_type Content-Type header value - * -param {String} allow_events Allow-Events header value. Optional. + * -param {String} contentType Content-Type header value + * -param {String} allowEvents Allow-Events header value. Optional. * -param {Object} params Will have priority over ua.configuration. Optional. * If set please define: to_uri, to_display_name, from_uri, from_display_name * -param {Array} headers Optional. Additional SIP headers. * -param {Object} credential. Will have priority over ua.configuration. Optional. */ - constructor(ua, target, { event_name, accept, expires, content_type, - allow_events, params, headers, credential }) + constructor(ua, target, { eventName, accept, expires, contentType, + allowEvents, params, headers, credential }) { debug('new'); @@ -68,16 +68,16 @@ module.exports = class Subscriber extends EventEmitter this._target = target; - if (!event_name) + if (!eventName) { - throw new TypeError('event_name is undefined'); + throw new TypeError('eventName is undefined'); } - const parsed = Grammar.parse(event_name, 'Event'); + const parsed = Grammar.parse(eventName, 'Event'); if (parsed === -1) { - throw new TypeError('event_name - wrong format'); + throw new TypeError('eventName - wrong format'); } this._event_name = parsed.event; @@ -96,10 +96,10 @@ module.exports = class Subscriber extends EventEmitter } this._expires = expires; - this._allow_events = allow_events; + this._allow_events = allowEvents; // used to subscribe with body - this._content_type = content_type; + this._content_type = contentType; this._is_first_notify_request = true; @@ -320,7 +320,22 @@ module.exports = class Subscriber extends EventEmitter } const body = request.body; - const is_final = new_state === 'terminated'; + + // Check if the NOTIFY is final + // For final NOTIFY get optional Subscription-State reason + let is_final; + let reason; + + if (new_state === 'terminated') + { + is_final = true; + reason = undefined; + } + else + { + is_final = false; + reason = subs_state.reason; + } // notify event fired for NOTIFY with body if (body) @@ -333,7 +348,7 @@ module.exports = class Subscriber extends EventEmitter if (is_final) { - this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY); + this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason); } } @@ -342,7 +357,7 @@ module.exports = class Subscriber extends EventEmitter */ /** - * Send the initial and subsequent SUBSCRIBE request + * Send the initial (non-fetch) and subsequent SUBSCRIBE * -param {String} body. Optional. */ subscribe(body = null) @@ -368,7 +383,7 @@ module.exports = class Subscriber extends EventEmitter } /** - * Send un-SUBSCRIBE (or fetch-SUBSCRIBE if in constructor set expires=0) + * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0) * -param {String} body. Optional. */ unsubscribe(body = null) @@ -420,7 +435,7 @@ module.exports = class Subscriber extends EventEmitter /** * Private API. */ - _dialogTerminated(termination_code) + _dialogTerminated(terminationCode, reason = undefined) { // to prevent duplicate emit terminated if (this._is_terminated) @@ -441,8 +456,8 @@ module.exports = class Subscriber extends EventEmitter this._ua.destroyDialog(this); } - debug(`emit "terminated" termination code=${termination_code}"`); - this.emit('terminated', termination_code); + debug(`emit "terminated" code=${terminationCode} ${reason}`); + this.emit('terminated', terminationCode, reason); } _send(body, headers) diff --git a/lib/UA.d.ts b/lib/UA.d.ts index 2985d1397..ac35622d0 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -158,10 +158,11 @@ export interface SubscriberParams { } export interface SubscriberOptions { - event_name: string; + eventName: string; accept: string; expires?: number; - content_type?: string; + contentType?: string; + allowEvents?: string; params?: SubscriberParams; headers?: string[]; credential?: Credential; @@ -169,7 +170,8 @@ export interface SubscriberOptions { export interface NotifierOptions { subscribe: IncomingRequest; - content_type: string; + contentType: string; + allowEvents?: string; headers?: string[]; pending?: boolean; credential?: Credential; From 6f5d248923f87a2fc48f63e55e8622af6b906321 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 27 May 2021 13:00:55 +0300 Subject: [PATCH 29/70] added terminated reason and retry-after --- dist/jssip.js | 51 ++++++++++++++++++++++++++++------------------- dist/jssip.min.js | 2 +- lib/Notifier.js | 25 +++++++++++++++++------ lib/Subscriber.js | 31 ++++++++++++---------------- 4 files changed, 63 insertions(+), 46 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 66ff5b65c..0ac2659c7 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16715,10 +16715,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._setExpiresTimer(); - } + } // To prevent duplicate emit 'terminated' + - _this._is_terminated = false; - _this._terminated_reason = undefined; // Custom session empty object for high level use. + _this._is_terminated = false; // Optional. Used to build terminated Subscription-State + + _this._terminated_reason = null; + _this._terminated_retry_after = null; // Custom session empty object for high level use. _this.data = {}; return _this; @@ -16856,8 +16859,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } subs_state += ";expires=".concat(expires); - } else if (this._terminated_reason) { - subs_state += ";reason=".concat(this._terminated_reason); + } else { + if (this._terminated_reason) { + subs_state += ";reason=".concat(this._terminated_reason); + } + + if (this._terminated_retry_after !== null) { + subs_state += ";retry-after=".concat(this._terminated_retry_after); + } } var headers = this._headers.slice(); @@ -16875,7 +16884,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { /** * Send the final NOTIFY request * -param {String} body Optional. - * -param {String} reason Optional. To construct Subscription-State. + * -param {String} reason Optional. To build Subscription-State header + * -param {Number} retryAfter Optional. To build Subscription-State header */ }, { @@ -16883,9 +16893,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function sendFinalNotify() { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; debug('sendFinalNotify()'); this._state = 'terminated'; this._terminated_reason = reason; + this._terminated_retry_after = retryAfter; this.sendNotify(body); this._is_final_notify_sent = true; @@ -22960,19 +22972,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } var body = request.body; // Check if the NOTIFY is final - // For final NOTIFY get optional Subscription-State reason - - var is_final; - var reason; - - if (new_state === 'terminated') { - is_final = true; - reason = undefined; - } else { - is_final = false; - reason = subs_state.reason; - } // notify event fired for NOTIFY with body + var is_final = new_state === 'terminated'; // notify event fired for NOTIFY with body if (body) { var content_type = request.getHeader('content-type'); @@ -22981,7 +22982,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (is_final) { - this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason); + var reason = subs_state.reason; + var retry_after = undefined; + + if (subs_state.params && subs_state.params['retry-after'] !== undefined) { + retry_after = parseInt(subs_state.params['retry-after']); + } + + this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason, retry_after); } } /** @@ -23073,6 +23081,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "_dialogTerminated", value: function _dialogTerminated(terminationCode) { var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; + var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; // to prevent duplicate emit terminated if (this._is_terminated) { @@ -23091,8 +23100,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._ua.destroyDialog(this); } - debug("emit \"terminated\" code=".concat(terminationCode, " ").concat(reason)); - this.emit('terminated', terminationCode, reason); + debug("emit \"terminated\" code=".concat(terminationCode)); + this.emit('terminated', terminationCode, reason, retryAfter); } }, { key: "_send", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index aa6804772..80ec97247 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=void 0,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c,h,p=e.body;if("terminated"===i?(c=!0,h=void 0):(c=!1,h=s.reason),p){var m=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",c,e,p,m)}c&&this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,h)}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e," ").concat(t)),this.emit("terminated",e,t))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index a40023da2..b634078bd 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -109,8 +109,12 @@ module.exports = class Notifier extends EventEmitter this._setExpiresTimer(); } + // To prevent duplicate emit 'terminated' this._is_terminated = false; - this._terminated_reason = undefined; + + // Optional. Used to build terminated Subscription-State + this._terminated_reason = null; + this._terminated_retry_after = null; // Custom session empty object for high level use. this.data = {}; @@ -260,11 +264,18 @@ module.exports = class Notifier extends EventEmitter subs_state += `;expires=${expires}`; } - else if (this._terminated_reason) + else { - subs_state += `;reason=${this._terminated_reason}`; + if (this._terminated_reason) + { + subs_state += `;reason=${this._terminated_reason}`; + } + if (this._terminated_retry_after !== null) + { + subs_state += `;retry-after=${this._terminated_retry_after}`; + } } - + const headers = this._headers.slice(); headers.push(`Subscription-State: ${subs_state}`); @@ -282,14 +293,16 @@ module.exports = class Notifier extends EventEmitter /** * Send the final NOTIFY request * -param {String} body Optional. - * -param {String} reason Optional. To construct Subscription-State. + * -param {String} reason Optional. To build Subscription-State header + * -param {Number} retryAfter Optional. To build Subscription-State header */ - sendFinalNotify(body = null, reason = null) + sendFinalNotify(body = null, reason = null, retryAfter = null) { debug('sendFinalNotify()'); this._state = 'terminated'; this._terminated_reason = reason; + this._terminated_retry_after = retryAfter; this.sendNotify(body); diff --git a/lib/Subscriber.js b/lib/Subscriber.js index a51492a31..5cc52fce4 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -322,20 +322,7 @@ module.exports = class Subscriber extends EventEmitter const body = request.body; // Check if the NOTIFY is final - // For final NOTIFY get optional Subscription-State reason - let is_final; - let reason; - - if (new_state === 'terminated') - { - is_final = true; - reason = undefined; - } - else - { - is_final = false; - reason = subs_state.reason; - } + const is_final = new_state === 'terminated'; // notify event fired for NOTIFY with body if (body) @@ -348,7 +335,15 @@ module.exports = class Subscriber extends EventEmitter if (is_final) { - this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason); + const reason = subs_state.reason; + let retry_after = undefined; + + if (subs_state.params && subs_state.params['retry-after'] !== undefined) + { + retry_after = parseInt(subs_state.params['retry-after']); + } + + this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason, retry_after); } } @@ -435,7 +430,7 @@ module.exports = class Subscriber extends EventEmitter /** * Private API. */ - _dialogTerminated(terminationCode, reason = undefined) + _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) { // to prevent duplicate emit terminated if (this._is_terminated) @@ -456,8 +451,8 @@ module.exports = class Subscriber extends EventEmitter this._ua.destroyDialog(this); } - debug(`emit "terminated" code=${terminationCode} ${reason}`); - this.emit('terminated', terminationCode, reason); + debug(`emit "terminated" code=${terminationCode}`); + this.emit('terminated', terminationCode, reason, retryAfter); } _send(body, headers) From 582d205b9c0998194ddd2a8c9a72269c0affb567 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 28 May 2021 11:25:13 +0300 Subject: [PATCH 30/70] improved comment --- dist/jssip.js | 3 +-- lib/Notifier.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 0ac2659c7..b07299c37 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16810,8 +16810,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { */ /** - * The called after constructor and event handlers settings. - * To use events 'subscribe' and 'terminated' for initial subscribe + * Should be called after creating the Notifier instance and setting the event handlers */ }, { diff --git a/lib/Notifier.js b/lib/Notifier.js index b634078bd..4884d23f7 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -212,8 +212,7 @@ module.exports = class Notifier extends EventEmitter */ /** - * The called after constructor and event handlers settings. - * To use events 'subscribe' and 'terminated' for initial subscribe + * Should be called after creating the Notifier instance and setting the event handlers */ start() { From f30ad3b63b35dba05fce9c36a9b5c0a4ca86ea7b Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 28 May 2021 12:17:53 +0300 Subject: [PATCH 31/70] fixed: Notifier expires_timer is not updated --- dist/jssip.js | 2 +- dist/jssip.min.js | 2 +- lib/Notifier.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index b07299c37..729abab93 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16952,7 +16952,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._expires_timestamp = new Date().getTime() + this._expires * 1000; clearTimeout(this._expires_timer); - setTimeout(function () { + this._expires_timer = setTimeout(function () { if (_this2._is_final_notify_sent) { return; } diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 80ec97247..93094480f 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 4884d23f7..752866a59 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -356,7 +356,7 @@ module.exports = class Notifier extends EventEmitter this._expires_timestamp = new Date().getTime() + (this._expires * 1000); clearTimeout(this._expires_timer); - setTimeout(() => + this._expires_timer = setTimeout(() => { if (this._is_final_notify_sent) { From 5569b5f5d9f3302784970c9c54291bc81d9d187f Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 28 May 2021 13:25:48 +0300 Subject: [PATCH 32/70] comments about state --- dist/jssip.js | 8 +++++--- lib/Notifier.js | 4 ++++ lib/Subscriber.js | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 729abab93..d29663f81 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16668,10 +16668,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._ua = ua; _this._initial_subscribe = subscribe; _this._expires_timestamp = null; - _this._expires_timer = null; + _this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait + _this._state = pending ? 'pending' : 'active'; _this._is_final_notify_sent = false; - _this._is_first_notify_response = true; + _this._is_first_notify_response = true; // dialog id + _this._id = null; _this._allow_events = allowEvents; _this._event_name = subscribe.getHeader('event'); @@ -22796,7 +22798,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._contact = ""); _this._contact += ";+sip.instance=\"\""); // Optional, used if credential is different from REGISTER/INVITE - _this._credential = credential; // Dialog state: init, notify_wait, pending, active, terminated + _this._credential = credential; // Subscriber state: init, notify_wait, pending, active, terminated _this._state = 'init'; // Dialog id diff --git a/lib/Notifier.js b/lib/Notifier.js index 752866a59..84666869b 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -58,9 +58,13 @@ module.exports = class Notifier extends EventEmitter this._initial_subscribe = subscribe; this._expires_timestamp = null; this._expires_timer = null; + + // Notifier state: pending, active, terminated. Not used: init, resp_wait this._state = pending ? 'pending' : 'active'; this._is_final_notify_sent = false; this._is_first_notify_response = true; + + // dialog id this._id = null; this._allow_events = allowEvents; this._event_name = subscribe.getHeader('event'); diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 5cc52fce4..34502baab 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -123,7 +123,7 @@ module.exports = class Subscriber extends EventEmitter // Optional, used if credential is different from REGISTER/INVITE this._credential = credential; - // Dialog state: init, notify_wait, pending, active, terminated + // Subscriber state: init, notify_wait, pending, active, terminated this._state = 'init'; // Dialog id From 933247f12dc7b8b568e5c94c63a02383ed020f49 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 28 May 2021 15:05:26 +0300 Subject: [PATCH 33/70] fixed: NOTIFY Subscription-State expires is small. Update expires time before (not after) event 'subscribe' --- dist/jssip.js | 7 +++++-- dist/jssip.min.js | 2 +- lib/Notifier.js | 9 +++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index d29663f81..1caaf5239 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16798,13 +16798,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var body = request.body; var content_type = request.getHeader('content-type'); var is_unsubscribe = this._expires === 0; + + if (!is_unsubscribe) { + this._setExpiresTimer(); + } + debug('emit "subscribe"'); this.emit('subscribe', is_unsubscribe, request, body, content_type); if (is_unsubscribe) { this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); - } else { - this._setExpiresTimer(); } } /** diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 93094480f..5d0902024 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s?this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE):this._setExpiresTimer()}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 84666869b..404d954bb 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -198,6 +198,11 @@ module.exports = class Notifier extends EventEmitter const content_type = request.getHeader('content-type'); const is_unsubscribe = this._expires === 0; + if (!is_unsubscribe) + { + this._setExpiresTimer(); + } + debug('emit "subscribe"'); this.emit('subscribe', is_unsubscribe, request, body, content_type); @@ -205,10 +210,6 @@ module.exports = class Notifier extends EventEmitter { this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); } - else - { - this._setExpiresTimer(); - } } /** From ec42af7c15b3dd91b48f8a5c5f5772fe7693be4f Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 31 May 2021 13:51:51 +0300 Subject: [PATCH 34/70] subscriber: optional custom contact and cseq --- dist/jssip.js | 19 +++++++++++++++---- dist/jssip.min.js | 2 +- lib/Subscriber.js | 25 +++++++++++++++++++------ lib/UA.d.ts | 1 + 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 1caaf5239..c913ec01b 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22732,6 +22732,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * -param {Object} params Will have priority over ua.configuration. Optional. * If set please define: to_uri, to_display_name, from_uri, from_display_name * -param {Array} headers Optional. Additional SIP headers. + * -param {String} contact Optional. Custom SUBSCRIBE contact. * -param {Object} credential. Will have priority over ua.configuration. Optional. */ function Subscriber(ua, target, _ref) { @@ -22744,6 +22745,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { allowEvents = _ref.allowEvents, params = _ref.params, headers = _ref.headers, + contact = _ref.contact, credential = _ref.credential; _classCallCheck(this, Subscriber); @@ -22795,11 +22797,20 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._params.from_tag = Utils.newTag(); _this._params.to_tag = null; - _this._params.call_id = Utils.createRandomToken(20); - _this._params.cseq = Math.floor(Math.random() * 10000 + 1); // Create contact + _this._params.call_id = Utils.createRandomToken(20); // Create cseq if not defined custom cseq + + if (_this._params.cseq === undefined) { + _this._params.cseq = Math.floor(Math.random() * 10000 + 1); + } // Create contact if not defined custom contact + + + if (!contact) { + _this._contact = ""); + _this._contact += ";+sip.instance=\"\""); + } else { + _this._contact = contact; + } // Optional, used if credential is different from REGISTER/INVITE - _this._contact = ""); - _this._contact += ";+sip.instance=\"\""); // Optional, used if credential is different from REGISTER/INVITE _this._credential = credential; // Subscriber state: init, notify_wait, pending, active, terminated diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 5d0902024..ad6cbb91a 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""'),r._credential=m,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var g=r._event_name;return r._event_id&&(g+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(g),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""')),r._credential=v,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var y=r._event_name;return r._event_id&&(y+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(y),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 34502baab..94f3ffd29 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -50,10 +50,11 @@ module.exports = class Subscriber extends EventEmitter * -param {Object} params Will have priority over ua.configuration. Optional. * If set please define: to_uri, to_display_name, from_uri, from_display_name * -param {Array} headers Optional. Additional SIP headers. + * -param {String} contact Optional. Custom SUBSCRIBE contact. * -param {Object} credential. Will have priority over ua.configuration. Optional. */ constructor(ua, target, { eventName, accept, expires, contentType, - allowEvents, params, headers, credential }) + allowEvents, params, headers, contact, credential }) { debug('new'); @@ -114,12 +115,24 @@ module.exports = class Subscriber extends EventEmitter this._params.from_tag = Utils.newTag(); this._params.to_tag = null; this._params.call_id = Utils.createRandomToken(20); - this._params.cseq = Math.floor((Math.random() * 10000) + 1); + + // Create cseq if not defined custom cseq + if (this._params.cseq === undefined) + { + this._params.cseq = Math.floor((Math.random() * 10000) + 1); + } - // Create contact - this._contact = ``; - this._contact += `;+sip.instance=""`; - + // Create contact if not defined custom contact + if (!contact) + { + this._contact = ``; + this._contact += `;+sip.instance=""`; + } + else + { + this._contact = contact; + } + // Optional, used if credential is different from REGISTER/INVITE this._credential = credential; diff --git a/lib/UA.d.ts b/lib/UA.d.ts index ac35622d0..47d9546d6 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -165,6 +165,7 @@ export interface SubscriberOptions { allowEvents?: string; params?: SubscriberParams; headers?: string[]; + contact?: string; credential?: Credential; } From 491a2084584bfffbb630b464f9643fb682515ef3 Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 31 May 2021 14:30:36 +0300 Subject: [PATCH 35/70] subscriber: custom contact set via headers, not as special argument --- dist/jssip.js | 23 +++++++++++------------ dist/jssip.min.js | 2 +- lib/Subscriber.js | 29 ++++++++++++----------------- lib/UA.d.ts | 1 - 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index c913ec01b..c196d1eb6 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22732,7 +22732,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * -param {Object} params Will have priority over ua.configuration. Optional. * If set please define: to_uri, to_display_name, from_uri, from_display_name * -param {Array} headers Optional. Additional SIP headers. - * -param {String} contact Optional. Custom SUBSCRIBE contact. * -param {Object} credential. Will have priority over ua.configuration. Optional. */ function Subscriber(ua, target, _ref) { @@ -22745,7 +22744,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { allowEvents = _ref.allowEvents, params = _ref.params, headers = _ref.headers, - contact = _ref.contact, credential = _ref.credential; _classCallCheck(this, Subscriber); @@ -22801,14 +22799,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (_this._params.cseq === undefined) { _this._params.cseq = Math.floor(Math.random() * 10000 + 1); - } // Create contact if not defined custom contact - - - if (!contact) { - _this._contact = ""); - _this._contact += ";+sip.instance=\"\""); - } else { - _this._contact = contact; } // Optional, used if credential is different from REGISTER/INVITE @@ -22824,14 +22814,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._send_unsubscribe = false; // After send un-subscribe wait final NOTIFY limited time. _this._unsubscribe_timeout_timer = null; - _this._headers = Utils.cloneArray(headers); var event_value = _this._event_name; if (_this._event_id) { event_value += ";id=".concat(_this._event_id); } - _this._headers = _this._headers.concat(["Event: ".concat(event_value), "Expires: ".concat(_this._expires), "Accept: ".concat(_this._accept), "Contact: ".concat(_this._contact)]); + _this._headers = Utils.cloneArray(headers); + _this._headers = _this._headers.concat(["Event: ".concat(event_value), "Expires: ".concat(_this._expires), "Accept: ".concat(_this._accept)]); + + if (!_this._headers.find(function (h) { + return h.startsWith('Contact'); + })) { + var contact = "Contact: "); + contact += ";+sip.instance=\"\""); + + _this._headers.push(contact); + } if (_this._allow_events) { _this._headers.push("Allow-Events: ".concat(_this._allow_events)); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index ad6cbb91a..cabe7bc66 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n"),r._contact+=';+sip.instance=""')),r._credential=v,r._state="init",r._id=null,r._expires_timer=null,r._expires_timestamp=null,r._send_unsubscribe=!1,r._unsubscribe_timeout_timer=null,r._headers=c.cloneArray(_);var y=r._event_name;return r._event_id&&(y+=";id=".concat(r._event_id)),r._headers=r._headers.concat(["Event: ".concat(y),"Expires: ".concat(r._expires),"Accept: ".concat(r._accept),"Contact: ".concat(r._contact)]),r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),r._headers.push(y)}return r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 94f3ffd29..f786fe609 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -50,11 +50,10 @@ module.exports = class Subscriber extends EventEmitter * -param {Object} params Will have priority over ua.configuration. Optional. * If set please define: to_uri, to_display_name, from_uri, from_display_name * -param {Array} headers Optional. Additional SIP headers. - * -param {String} contact Optional. Custom SUBSCRIBE contact. * -param {Object} credential. Will have priority over ua.configuration. Optional. */ constructor(ua, target, { eventName, accept, expires, contentType, - allowEvents, params, headers, contact, credential }) + allowEvents, params, headers, credential }) { debug('new'); @@ -121,17 +120,6 @@ module.exports = class Subscriber extends EventEmitter { this._params.cseq = Math.floor((Math.random() * 10000) + 1); } - - // Create contact if not defined custom contact - if (!contact) - { - this._contact = ``; - this._contact += `;+sip.instance=""`; - } - else - { - this._contact = contact; - } // Optional, used if credential is different from REGISTER/INVITE this._credential = credential; @@ -152,20 +140,27 @@ module.exports = class Subscriber extends EventEmitter // After send un-subscribe wait final NOTIFY limited time. this._unsubscribe_timeout_timer = null; - this._headers = Utils.cloneArray(headers); let event_value = this._event_name; if (this._event_id) { event_value += `;id=${this._event_id}`; } - + + this._headers = Utils.cloneArray(headers); this._headers = this._headers.concat([ `Event: ${event_value}`, `Expires: ${this._expires}`, - `Accept: ${this._accept}`, - `Contact: ${this._contact}` + `Accept: ${this._accept}` ]); + + if (!this._headers.find((h) => h.startsWith('Contact'))) + { + let contact = `Contact: `; + + contact += `;+sip.instance=""`; + this._headers.push(contact); + } if (this._allow_events) { diff --git a/lib/UA.d.ts b/lib/UA.d.ts index 47d9546d6..ac35622d0 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -165,7 +165,6 @@ export interface SubscriberOptions { allowEvents?: string; params?: SubscriberParams; headers?: string[]; - contact?: string; credential?: Credential; } From 1df3b9c4989d36b2938efb4915d6467e59795dbf Mon Sep 17 00:00:00 2001 From: Igor Kolosov Date: Tue, 1 Jun 2021 10:32:45 +0300 Subject: [PATCH 36/70] Update lib/Notifier.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Luis Millán --- lib/Notifier.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index 404d954bb..73d20df8c 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -20,7 +20,7 @@ const C = { }; /** - * It's implementation of RFC 6665 Notifier + * RFC 6665 Notifier implementation. */ module.exports = class Notifier extends EventEmitter { @@ -374,4 +374,4 @@ module.exports = class Notifier extends EventEmitter this._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this._expires * 1000); } -}; \ No newline at end of file +}; From 6258013e47f2f2bbe1d109bf5553e62dcaf07c73 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 1 Jun 2021 12:46:20 +0300 Subject: [PATCH 37/70] points at end of sentence --- lib/Notifier.js | 47 +++++++++++++++++++------------------- lib/Subscriber.js | 58 +++++++++++++++++++++++------------------------ 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index 73d20df8c..d60f37ef4 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -7,7 +7,7 @@ const debugerror = require('debug')('JsSIP:ERROR:Notifier'); debugerror.log = console.warn.bind(console); /** - * Termination code + * Termination codes. */ const C = { NOTIFY_RESPONSE_TIMEOUT : 0, @@ -59,12 +59,12 @@ module.exports = class Notifier extends EventEmitter this._expires_timestamp = null; this._expires_timer = null; - // Notifier state: pending, active, terminated. Not used: init, resp_wait + // Notifier state: pending, active, terminated. Not used: init, resp_wait. this._state = pending ? 'pending' : 'active'; this._is_final_notify_sent = false; this._is_first_notify_response = true; - // dialog id + // Dialog id. this._id = null; this._allow_events = allowEvents; this._event_name = subscribe.getHeader('event'); @@ -90,7 +90,7 @@ module.exports = class Notifier extends EventEmitter this._target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); - // NOTIFY request params set according received SUBSCRIBE + // NOTIFY request params set according received SUBSCRIBE. this._params = { from : subscribe.to, from_tag : subscribe.to_tag, @@ -100,23 +100,23 @@ module.exports = class Notifier extends EventEmitter cseq : Math.floor((Math.random() * 10000) + 1) }; - // For non-fetch subscribe add dialog + // For non-fetch subscribe add dialog. if (this._expires > 0) { - // Dialog id + // Dialog id. this._id = `${this._params.call_id}${this._params.from_tag}${this._params.to_tag}`; debug('add dialog id=', this._id); this._ua.newDialog(this); - // Set expires timer and timestamp + // Set expires timer and time-stamp. this._setExpiresTimer(); } - // To prevent duplicate emit 'terminated' + // To prevent duplicate emit 'terminated'. this._is_terminated = false; - // Optional. Used to build terminated Subscription-State + // Optional. Used to build terminated Subscription-State. this._terminated_reason = null; this._terminated_retry_after = null; @@ -125,7 +125,7 @@ module.exports = class Notifier extends EventEmitter } /** - * NOTIFY transactions callbacks + * NOTIFY transactions callbacks. */ onAuthenticated() { @@ -170,8 +170,8 @@ module.exports = class Notifier extends EventEmitter /** * Dialog callback. - * Called also for initial subscribe - * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0) + * Called also for initial subscribe. + * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). */ receiveRequest(request) { @@ -186,7 +186,7 @@ module.exports = class Notifier extends EventEmitter if (h === undefined || h === null) { - // Missed header Expires. RFC 6665 3.1.1. Set default expires value + // Missed header Expires. RFC 6665 3.1.1. Set default expires value. h = '900'; debug(`Missed expires header. Set by default ${h}`); } @@ -217,7 +217,7 @@ module.exports = class Notifier extends EventEmitter */ /** - * Should be called after creating the Notifier instance and setting the event handlers + * Should be called after creating the Notifier instance and setting the event handlers. */ start() { @@ -227,7 +227,7 @@ module.exports = class Notifier extends EventEmitter } /** - * Switch pending dialog state to active + * Switch pending dialog state to active. */ setActiveState() { @@ -240,14 +240,14 @@ module.exports = class Notifier extends EventEmitter } /** - * Send the initial and subsequent NOTIFY request + * Send the initial and subsequent NOTIFY request. * -param {String} body. Optional. */ sendNotify(body = null) { debug('sendNotify()'); - // Prevent send notify after final notify + // Prevent send notify after final notify. if (this._is_final_notify_sent) { debugerror('final notify has sent'); @@ -296,9 +296,10 @@ module.exports = class Notifier extends EventEmitter /** * Send the final NOTIFY request + * * -param {String} body Optional. - * -param {String} reason Optional. To build Subscription-State header - * -param {Number} retryAfter Optional. To build Subscription-State header + * -param {String} reason Optional. To build Subscription-State header. + * -param {Number} retryAfter Optional. To build Subscription-State header. */ sendFinalNotify(body = null, reason = null, retryAfter = null) { @@ -315,7 +316,7 @@ module.exports = class Notifier extends EventEmitter } /** - * Get dialog state + * Get dialog state. */ get state() { @@ -323,7 +324,7 @@ module.exports = class Notifier extends EventEmitter } /** - * Get dialog id + * Get dialog id. */ get id() { @@ -331,7 +332,7 @@ module.exports = class Notifier extends EventEmitter } /** - * Private API. + * Private API */ _dialogTerminated(termination_code) { @@ -374,4 +375,4 @@ module.exports = class Notifier extends EventEmitter this._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this._expires * 1000); } -}; +}; \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index f786fe609..00706f41a 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -8,7 +8,7 @@ const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); debugerror.log = console.warn.bind(console); /** - * Termination code + * Termination codes. */ const C = { SUBSCRIBE_RESPONSE_TIMEOUT : 0, @@ -21,7 +21,7 @@ const C = { }; /** - * It's implementation of RFC 6665 Subscriber + * It's implementation of RFC 6665 Subscriber. */ module.exports = class Subscriber extends EventEmitter { @@ -43,9 +43,9 @@ module.exports = class Subscriber extends EventEmitter * -param {String} target * -param {Object} options * -param {String} eventName Event header value. May end with optional ;id=xxx - * -param {String} accept Accept header value - * -param {Number} expires Expires header value. Optional. Default is 900 - * -param {String} contentType Content-Type header value + * -param {String} accept Accept header value. + * -param {Number} expires Expires header value. Optional. Default is 900. + * -param {String} contentType Content-Type header value. * -param {String} allowEvents Allow-Events header value. Optional. * -param {Object} params Will have priority over ua.configuration. Optional. * If set please define: to_uri, to_display_name, from_uri, from_display_name @@ -98,7 +98,7 @@ module.exports = class Subscriber extends EventEmitter this._expires = expires; this._allow_events = allowEvents; - // used to subscribe with body + // Used to subscribe with body. this._content_type = contentType; this._is_first_notify_request = true; @@ -110,27 +110,27 @@ module.exports = class Subscriber extends EventEmitter this._params.from_uri = this._ua.configuration.uri; } - // set SUBSCRIBE dialog parameters + // Set SUBSCRIBE dialog parameters. this._params.from_tag = Utils.newTag(); this._params.to_tag = null; this._params.call_id = Utils.createRandomToken(20); - // Create cseq if not defined custom cseq + // Create cseq if not defined custom cseq. if (this._params.cseq === undefined) { this._params.cseq = Math.floor((Math.random() * 10000) + 1); } - // Optional, used if credential is different from REGISTER/INVITE + // Optional, used if credential is different from REGISTER/INVITE. this._credential = credential; - // Subscriber state: init, notify_wait, pending, active, terminated + // Subscriber state: init, notify_wait, pending, active, terminated. this._state = 'init'; - // Dialog id + // Dialog id. this._id = null; - // To refresh subscription + // To refresh subscription. this._expires_timer = null; this._expires_timestamp = null; @@ -195,7 +195,7 @@ module.exports = class Subscriber extends EventEmitter { if (response.status_code >= 200 && response.status_code < 300) { - // add dialog to stack dialogs table + // Add dialog to stack dialogs table. if (this._params.to_tag === null) { this._params.to_tag = response.to_tag; @@ -212,14 +212,14 @@ module.exports = class Subscriber extends EventEmitter } } - // check expires value + // Check expires value. let expires_value = response.getHeader('expires'); if (expires_value !== 0 && !expires_value) { debugerror('response without Expires header'); - // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header + // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header. // Use workaround expires value. expires_value = '900'; } @@ -242,7 +242,7 @@ module.exports = class Subscriber extends EventEmitter } /** - * Dialog callback + * Dialog callback. */ receiveRequest(request) { @@ -254,7 +254,7 @@ module.exports = class Subscriber extends EventEmitter return; } - // RFC 6665 8.2.1. Check if event header matches + // RFC 6665 8.2.1. Check if event header matches. const event_header = request.parseHeader('Event'); if (!event_header) @@ -278,7 +278,7 @@ module.exports = class Subscriber extends EventEmitter return; } - // Process Subscription-State header + // Process Subscription-State header. const subs_state = request.parseHeader('subscription-state'); if (!subs_state) @@ -311,7 +311,7 @@ module.exports = class Subscriber extends EventEmitter const expires_timestamp = new Date().getTime() + (expires * 1000); const max_time_deviation = 2000; - // expiration time is shorter and the difference is not too small + // Expiration time is shorter and the difference is not too small. if (this._expires_timestamp - expires_timestamp > max_time_deviation) { debug('update sending re-SUBSCRIBE time'); @@ -329,10 +329,10 @@ module.exports = class Subscriber extends EventEmitter const body = request.body; - // Check if the NOTIFY is final + // Check if the NOTIFY is final. const is_final = new_state === 'terminated'; - // notify event fired for NOTIFY with body + // Notify event fired for NOTIFY with body. if (body) { const content_type = request.getHeader('content-type'); @@ -360,7 +360,7 @@ module.exports = class Subscriber extends EventEmitter */ /** - * Send the initial (non-fetch) and subsequent SUBSCRIBE + * Send the initial (non-fetch) and subsequent SUBSCRIBE. * -param {String} body. Optional. */ subscribe(body = null) @@ -386,7 +386,7 @@ module.exports = class Subscriber extends EventEmitter } /** - * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0) + * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0). * -param {String} body. Optional. */ unsubscribe(body = null) @@ -402,7 +402,7 @@ module.exports = class Subscriber extends EventEmitter } this._send_unsubscribe = true; - // Set header Expires: 0 + // Set header Expires: 0. const headers = this._headers.map((s) => { return s.startsWith('Expires') ? 'Expires: 0' : s; @@ -410,7 +410,7 @@ module.exports = class Subscriber extends EventEmitter this._send(body, headers); - // Waiting for the final notify for a while + // Waiting for the final notify for a while. const final_notify_timeout = 30000; this._unsubscribe_timeout_timer = setTimeout(() => @@ -420,7 +420,7 @@ module.exports = class Subscriber extends EventEmitter } /** - * Get dialog state + * Get dialog state. */ get state() { @@ -428,7 +428,7 @@ module.exports = class Subscriber extends EventEmitter } /** - * Get dialog id + * Get dialog id. */ get id() { @@ -440,7 +440,7 @@ module.exports = class Subscriber extends EventEmitter */ _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) { - // to prevent duplicate emit terminated + // To prevent duplicate emit terminated event. if (this._is_terminated) { return; @@ -449,7 +449,7 @@ module.exports = class Subscriber extends EventEmitter this._is_terminated = true; this._state = 'terminated'; - // clear timers + // Clear timers. clearTimeout(this._expires_timer); clearTimeout(this._unsubscribe_timeout_timer); From d77ffde7b5621efc872fbef60e25cc7826105ca4 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 1 Jun 2021 21:10:13 +0300 Subject: [PATCH 38/70] after review modifications --- dist/jssip.js | 389 +++++++++++++++++++++---------------------- dist/jssip.min.js | 2 +- lib/Notifier.d.ts | 4 +- lib/Notifier.js | 122 ++++++++------ lib/RequestSender.js | 33 ++-- lib/Subscriber.d.ts | 2 +- lib/Subscriber.js | 114 ++++++------- lib/UA.d.ts | 21 +-- lib/UA.js | 30 +--- 9 files changed, 343 insertions(+), 374 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index c196d1eb6..a16a3fd29 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16614,13 +16614,17 @@ var JsSIP_C = require('./Constants'); var Utils = require('./Utils'); +var SIPMessage = require('./SIPMessage'); + +var RequestSender = require('./RequestSender'); + var debug = require('debug')('JsSIP:Notifier'); var debugerror = require('debug')('JsSIP:ERROR:Notifier'); debugerror.log = console.warn.bind(console); /** - * Termination code + * Termination codes. */ var C = { @@ -16633,7 +16637,7 @@ var C = { SUBSCRIPTION_EXPIRED: 6 }; /** - * It's implementation of RFC 6665 Notifier + * RFC 6665 Notifier implementation. */ module.exports = /*#__PURE__*/function (_EventEmitter) { @@ -16642,62 +16646,75 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(Notifier); /** - * -param {Object} ua JsSIP UA - * -param {Object} options - * -param {IncomingRequest} subscribe - * -param {String} contentType Content-Type header value - * -param {Array} headers Optional. Additional SIP headers. - * -param {String} allowEvents Allow-Events header value. Optional. - * -param {Object} credential. Will have priority over ua.configuration. Optional. - * -param {Boolean} pending Set initial dialog state as "pending". Optional. + * @param {UA} ua - JsSIP User Agent instance. + * @param {IncomingRequest} subscribe - Subscribe request. + * @param {string} contentType - Content-Type header value. + * @param {NotifierOptions} options - Optional parameters. + * @param {Array} extraHeaders - Additional SIP headers. + * @param {string} allowEvents - Allow-Events header value. + * @param {boolean} pending - Set initial dialog state as "pending". */ - function Notifier(ua, _ref) { + function Notifier(ua, subscribe, contentType, _ref) { var _this; - var subscribe = _ref.subscribe, - contentType = _ref.contentType, - headers = _ref.headers, + var extraHeaders = _ref.extraHeaders, allowEvents = _ref.allowEvents, - credential = _ref.credential, pending = _ref.pending; _classCallCheck(this, Notifier); debug('new'); _this = _super.call(this); + + if (!subscribe) { + throw new TypeError('subscribe is undefined'); + } + + if (!contentType) { + throw new TypeError('contentType is undefined'); + } + _this._ua = ua; _this._initial_subscribe = subscribe; _this._expires_timestamp = null; - _this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait + _this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait. _this._state = pending ? 'pending' : 'active'; _this._is_final_notify_sent = false; - _this._is_first_notify_response = true; // dialog id + _this._is_first_notify_response = true; // To prevent duplicate emit 'terminated'. - _this._id = null; - _this._allow_events = allowEvents; - _this._event_name = subscribe.getHeader('event'); + _this._is_terminated = false; // Optional. Used to build terminated Subscription-State. - if (!contentType) { - throw new TypeError('contentType is undefined'); - } + _this._terminated_reason = null; + _this._terminated_retry_after = null; // Custom session empty object for high level use. + _this.data = {}; // Dialog id. + + _this._id = null; + var eventName = subscribe.getHeader('event'); _this._content_type = contentType; _this._expires = parseInt(subscribe.getHeader('expires')); - _this._credential = credential; - _this._contact = ""); - _this._headers = Utils.cloneArray(headers); + _this._headers = Utils.cloneArray(extraHeaders); + + _this._headers.push("Event: ".concat(eventName)); // Use contact from extraHeaders or create it. + + + _this._contact = _this._headers.find(function (header) { + return header.startsWith('Contact'); + }); - _this._headers.push("Event: ".concat(_this._event_name)); + if (!_this._contact) { + _this._contact = "Contact: "); - _this._headers.push("Contact: ".concat(_this._contact)); + _this._headers.push(_this._contact); + } - if (_this._allow_events) { - _this._headers.push("Allow-Events: ".concat(_this._allow_events)); + if (allowEvents) { + _this._headers.push("Allow-Events: ".concat(allowEvents)); } _this._target = subscribe.from.uri.user; - subscribe.to_tag = Utils.newTag(); // NOTIFY request params set according received SUBSCRIBE + subscribe.to_tag = Utils.newTag(); // NOTIFY request params set according received SUBSCRIBE. _this._params = { from: subscribe.to, @@ -16706,30 +16723,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { to_tag: subscribe.from_tag, call_id: subscribe.call_id, cseq: Math.floor(Math.random() * 10000 + 1) - }; // For non-fetch subscribe add dialog + }; // For non-fetch subscribe add dialog. if (_this._expires > 0) { - // Dialog id + // Dialog id. _this._id = "".concat(_this._params.call_id).concat(_this._params.from_tag).concat(_this._params.to_tag); debug('add dialog id=', _this._id); - _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timer and timestamp + _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timer and time-stamp. _this._setExpiresTimer(); - } // To prevent duplicate emit 'terminated' - - - _this._is_terminated = false; // Optional. Used to build terminated Subscription-State - - _this._terminated_reason = null; - _this._terminated_retry_after = null; // Custom session empty object for high level use. + } - _this.data = {}; return _this; } /** - * NOTIFY transactions callbacks + * NOTIFY transactions callbacks. */ @@ -16773,8 +16783,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } /** * Dialog callback. - * Called also for initial subscribe - * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0) + * Called also for initial subscribe. + * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). */ }, { @@ -16785,16 +16795,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - var h = request.getHeader('expires'); + var expiresValue = request.getHeader('expires'); - if (h === undefined || h === null) { - // Missed header Expires. RFC 6665 3.1.1. Set default expires value - h = '900'; - debug("Missed expires header. Set by default ".concat(h)); + if (expiresValue === undefined || expiresValue === null) { + // Missed header Expires. RFC 6665 3.1.1. Set default expires value. + expiresValue = '900'; + debug("Missed expires header. Set by default ".concat(expiresValue)); } - this._expires = parseInt(h); - request.reply(200, null, ["Expires: ".concat(this._expires), "Contact: ".concat(this._contact)]); + this._expires = parseInt(expiresValue); + request.reply(200, null, ["Expires: ".concat(this._expires), "".concat(this._contact)]); var body = request.body; var content_type = request.getHeader('content-type'); var is_unsubscribe = this._expires === 0; @@ -16815,7 +16825,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { */ /** - * Should be called after creating the Notifier instance and setting the event handlers + * Should be called after creating the Notifier instance and setting the event handlers. */ }, { @@ -16825,7 +16835,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.receiveRequest(this._initial_subscribe); } /** - * Switch pending dialog state to active + * Switch pending dialog state to active. */ }, { @@ -16838,15 +16848,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } /** - * Send the initial and subsequent NOTIFY request - * -param {String} body. Optional. + * Send the initial and subsequent NOTIFY request. + * @param {string} body - notify request body. */ }, { - key: "sendNotify", - value: function sendNotify() { + key: "notify", + value: function notify() { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('sendNotify()'); // Prevent send notify after final notify + debug('notify()'); // Prevent send notify after final notify. if (this._is_final_notify_sent) { debugerror('final notify has sent'); @@ -16881,34 +16891,37 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { headers.push("Content-Type: ".concat(this._content_type)); } - this._params.cseq++; + this._params.cseq++; // Create & send request. - this._ua.sendRequest(JsSIP_C.NOTIFY, this._target, this._params, headers, body, this, this._credential); + var request = new SIPMessage.OutgoingRequest(JsSIP_C.NOTIFY, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); + var requestSender = new RequestSender(this._ua, request, this); + requestSender.send(); } /** - * Send the final NOTIFY request - * -param {String} body Optional. - * -param {String} reason Optional. To build Subscription-State header - * -param {Number} retryAfter Optional. To build Subscription-State header + * Terminate. (Send the final NOTIFY request). + * + * @param {string} body - Notify message body. + * @param {string} reason - Set Subscription-State reason parameter. + * @param {number} retryAfter - Set Subscription-State retry-after parameter. */ }, { - key: "sendFinalNotify", - value: function sendFinalNotify() { + key: "terminate", + value: function terminate() { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - debug('sendFinalNotify()'); + debug('terminate()'); this._state = 'terminated'; this._terminated_reason = reason; this._terminated_retry_after = retryAfter; - this.sendNotify(body); + this.notify(body); this._is_final_notify_sent = true; this._dialogTerminated(C.SEND_FINAL_NOTIFY); } /** - * Get dialog state + * Get dialog state. */ }, { @@ -16917,7 +16930,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return this._state; } /** - * Get dialog id + * Get dialog id. */ }, { @@ -16926,7 +16939,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return this._id; } /** - * Private API. + * Private API */ }, { @@ -16965,7 +16978,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this2._terminated_reason = 'timeout'; _this2._is_final_notify_sent = true; - _this2.sendNotify(); + _this2.notify(); _this2._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this._expires * 1000); @@ -16983,7 +16996,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return Notifier; }(EventEmitter); -},{"./Constants":2,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ +},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } @@ -21574,8 +21587,6 @@ var EventHandlers = { module.exports = /*#__PURE__*/function () { function RequestSender(ua, request, eventHandlers) { - var config2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; - _classCallCheck(this, RequestSender); this._ua = ua; @@ -21584,8 +21595,7 @@ module.exports = /*#__PURE__*/function () { this._request = request; this._auth = null; this._challenged = false; - this._staled = false; - this._config2 = config2; // Define the undefined handlers. + this._staled = false; // Define the undefined handlers. for (var handler in EventHandlers) { if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) { @@ -21658,7 +21668,7 @@ module.exports = /*#__PURE__*/function () { * Authenticate once. _challenged_ flag used to avoid infinite authentications. */ - if ((status_code === 401 || status_code === 407) && (this._config2 !== null || this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { + if ((status_code === 401 || status_code === 407) && (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. if (response.status_code === 401) { challenge = response.parseHeader('www-authenticate'); @@ -21679,12 +21689,11 @@ module.exports = /*#__PURE__*/function () { if (!this._challenged || !this._staled && challenge.stale === true) { if (!this._auth) { - var cnf = this._config2 ? this._config2 : this._ua.configuration; this._auth = new DigestAuthentication({ - username: cnf.authorization_user, - password: cnf.password, - realm: cnf.realm, - ha1: cnf.ha1 + username: this._ua.configuration.authorization_user, + password: this._ua.configuration.password, + realm: this._ua.configuration.realm, + ha1: this._ua.configuration.ha1 }); } // Verify that the challenge is really valid. @@ -21695,16 +21704,11 @@ module.exports = /*#__PURE__*/function () { return; } - this._challenged = true; // Update ha1 and realm in the UA or in alternative config. + this._challenged = true; // Update ha1 and realm in the UA. - if (!this._config2) { - this._ua.set('realm', this._auth.get('realm')); + this._ua.set('realm', this._auth.get('realm')); - this._ua.set('ha1', this._auth.get('ha1')); - } else { - this._config2.realm = this._auth.get('realm'); - this._config2.ha1 = this._auth.get('ha1'); - } + this._ua.set('ha1', this._auth.get('ha1')); if (challenge.stale) { this._staled = true; @@ -22693,13 +22697,17 @@ var Utils = require('./Utils'); var Grammar = require('./Grammar'); +var SIPMessage = require('./SIPMessage'); + +var RequestSender = require('./RequestSender'); + var debug = require('debug')('JsSIP:Subscriber'); var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); debugerror.log = console.warn.bind(console); /** - * Termination code + * Termination codes. */ var C = { @@ -22712,7 +22720,7 @@ var C = { RECEIVE_BAD_NOTIFY: 6 }; /** - * It's implementation of RFC 6665 Subscriber + * RFC 6665 Subscriber implementation. */ module.exports = /*#__PURE__*/function (_EventEmitter) { @@ -22721,110 +22729,105 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(Subscriber); /** - * -param {Object} ua reference to JsSIP.UA - * -param {String} target - * -param {Object} options - * -param {String} eventName Event header value. May end with optional ;id=xxx - * -param {String} accept Accept header value - * -param {Number} expires Expires header value. Optional. Default is 900 - * -param {String} contentType Content-Type header value - * -param {String} allowEvents Allow-Events header value. Optional. - * -param {Object} params Will have priority over ua.configuration. Optional. + * @param {UA} ua - reference to JsSIP.UA + * @param {string} target + * @param {string} eventName - Event header value. May end with optional ;id=xxx + * @param {string} accept - Accept header value. + * + * @param {SubscriberOption} options - optional parameters. + * @param {number} expires - Expires header value. Default is 900. + * @param {string} contentType - Content-Type header value. Used for SUBSCRIBE with body + * @param {string} allowEvents - Allow-Events header value. + * @param {RequestParams} params - Will have priority over ua.configuration. * If set please define: to_uri, to_display_name, from_uri, from_display_name - * -param {Array} headers Optional. Additional SIP headers. - * -param {Object} credential. Will have priority over ua.configuration. Optional. + * @param {Array} extraHeaders - Additional SIP headers. */ - function Subscriber(ua, target, _ref) { + function Subscriber(ua, target, eventName, accept, _ref) { var _this; - var eventName = _ref.eventName, - accept = _ref.accept, - expires = _ref.expires, + var expires = _ref.expires, contentType = _ref.contentType, allowEvents = _ref.allowEvents, params = _ref.params, - headers = _ref.headers, - credential = _ref.credential; + extraHeaders = _ref.extraHeaders; _classCallCheck(this, Subscriber); debug('new'); - _this = _super.call(this); - _this._ua = ua; + _this = _super.call(this); // Check that arguments are defined if (!target) { throw new TypeError('target is undefined'); } - _this._target = target; - if (!eventName) { throw new TypeError('eventName is undefined'); } - var parsed = Grammar.parse(eventName, 'Event'); - - if (parsed === -1) { - throw new TypeError('eventName - wrong format'); - } - - _this._event_name = parsed.event; - _this._event_id = parsed.params && parsed.params.id; - if (!accept) { throw new TypeError('accept is undefined'); } + _this._ua = ua; + _this._target = target; _this._accept = accept; if (expires !== 0 && !expires) { expires = 900; } - _this._expires = expires; - _this._allow_events = allowEvents; // used to subscribe with body + _this._expires = expires; // Used to subscribe with body. _this._content_type = contentType; - _this._is_first_notify_request = true; + _this._is_first_notify_request = true; // Set subscriber dialog parameters. + _this._params = Utils.cloneObject(params); if (!_this._params.from_uri) { _this._params.from_uri = _this._ua.configuration.uri; - } // set SUBSCRIBE dialog parameters - + } _this._params.from_tag = Utils.newTag(); _this._params.to_tag = null; - _this._params.call_id = Utils.createRandomToken(20); // Create cseq if not defined custom cseq + _this._params.call_id = Utils.createRandomToken(20); // Create cseq if not defined custom cseq. if (_this._params.cseq === undefined) { _this._params.cseq = Math.floor(Math.random() * 10000 + 1); - } // Optional, used if credential is different from REGISTER/INVITE - + } // Subscriber state: init, notify_wait, pending, active, terminated. - _this._credential = credential; // Subscriber state: init, notify_wait, pending, active, terminated - _this._state = 'init'; // Dialog id + _this._state = 'init'; // Dialog id. - _this._id = null; // To refresh subscription + _this._id = null; // To refresh subscription. _this._expires_timer = null; - _this._expires_timestamp = null; // To prvent duplicate un-SUBSCRIBE sending. + _this._expires_timestamp = null; // To prevent duplicate un-subscribe sending. + + _this._send_unsubscribe = false; // To prevent duplicate emit terminated event. + + _this._is_terminated = false; // After send un-subscribe wait final NOTIFY limited time. + + _this._unsubscribe_timeout_timer = null; // Custom session empty object for high level use. + + _this.data = {}; + var parsed = Grammar.parse(eventName, 'Event'); - _this._send_unsubscribe = false; // After send un-subscribe wait final NOTIFY limited time. + if (parsed === -1) { + throw new TypeError('eventName - wrong format'); + } - _this._unsubscribe_timeout_timer = null; - var event_value = _this._event_name; + var eventValue = parsed.event; + var eventId = parsed.params && parsed.params.id; - if (_this._event_id) { - event_value += ";id=".concat(_this._event_id); + if (eventId) { + eventValue += ";id=".concat(_this.eventId); } - _this._headers = Utils.cloneArray(headers); - _this._headers = _this._headers.concat(["Event: ".concat(event_value), "Expires: ".concat(_this._expires), "Accept: ".concat(_this._accept)]); + _this._headers = Utils.cloneArray(extraHeaders); + _this._headers = _this._headers.concat(["Event: ".concat(eventValue), "Expires: ".concat(_this._expires), "Accept: ".concat(_this._accept)]); - if (!_this._headers.find(function (h) { - return h.startsWith('Contact'); + if (!_this._headers.find(function (header) { + return header.startsWith('Contact'); })) { var contact = "Contact: "); contact += ";+sip.instance=\"\""); @@ -22832,13 +22835,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._headers.push(contact); } - if (_this._allow_events) { - _this._headers.push("Allow-Events: ".concat(_this._allow_events)); + if (allowEvents) { + _this._headers.push("Allow-Events: ".concat(allowEvents)); } - _this._is_terminated = false; // Custom session empty object for high level use. - - _this.data = {}; return _this; } /** @@ -22870,7 +22870,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "onReceiveResponse", value: function onReceiveResponse(response) { if (response.status_code >= 200 && response.status_code < 300) { - // add dialog to stack dialogs table + // Add dialog to stack dialogs table. if (this._params.to_tag === null) { this._params.to_tag = response.to_tag; this._id = "".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag); @@ -22883,13 +22883,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (route_set.length > 0) { this._params.route_set = route_set; } - } // check expires value + } // Check expires value. var expires_value = response.getHeader('expires'); if (expires_value !== 0 && !expires_value) { - debugerror('response without Expires header'); // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header + debugerror('response without Expires header'); // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header. // Use workaround expires value. expires_value = '900'; @@ -22907,7 +22907,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } /** - * Dialog callback + * Dialog callback. */ }, { @@ -22917,7 +22917,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { debugerror('received non-NOTIFY request'); request.reply(405); return; - } // RFC 6665 8.2.1. Check if event header matches + } // RFC 6665 8.2.1. Check if event header matches. var event_header = request.parseHeader('Event'); @@ -22941,7 +22941,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); return; - } // Process Subscription-State header + } // Process Subscription-State header. var subs_state = request.parseHeader('subscription-state'); @@ -22970,7 +22970,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (subs_state.expires !== undefined) { var expires = subs_state.expires; var expires_timestamp = new Date().getTime() + expires * 1000; - var max_time_deviation = 2000; // expiration time is shorter and the difference is not too small + var max_time_deviation = 2000; // Expiration time is shorter and the difference is not too small. if (this._expires_timestamp - expires_timestamp > max_time_deviation) { debug('update sending re-SUBSCRIBE time'); @@ -22985,9 +22985,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this.emit('active'); } - var body = request.body; // Check if the NOTIFY is final + var body = request.body; // Check if the NOTIFY is final. - var is_final = new_state === 'terminated'; // notify event fired for NOTIFY with body + var is_final = new_state === 'terminated'; // Notify event fired for NOTIFY with body. if (body) { var content_type = request.getHeader('content-type'); @@ -23011,8 +23011,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { */ /** - * Send the initial (non-fetch) and subsequent SUBSCRIBE - * -param {String} body. Optional. + * Send the initial (non-fetch) and subsequent SUBSCRIBE. + * @param {string} body - subscribe request body. */ }, { @@ -23038,30 +23038,31 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._send(body, headers); } /** - * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0) - * -param {String} body. Optional. + * terminate. + * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0). + * @param {string} body - Un-subscribe request body */ }, { - key: "unsubscribe", - value: function unsubscribe() { + key: "terminate", + value: function terminate() { var _this2 = this; var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('unsubscribe()'); // Prevent duplication unsubscribe. + debug('terminate()'); // Prevent duplication un-subscribe sending. if (this._send_unsubscribe) { debugerror('unsubscribe has already been sent'); return; } - this._send_unsubscribe = true; // Set header Expires: 0 + this._send_unsubscribe = true; // Set header Expires: 0. var headers = this._headers.map(function (s) { return s.startsWith('Expires') ? 'Expires: 0' : s; }); - this._send(body, headers); // Waiting for the final notify for a while + this._send(body, headers); // Waiting for the final notify for a while. var final_notify_timeout = 30000; @@ -23070,7 +23071,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, final_notify_timeout); } /** - * Get dialog state + * Get dialog state. */ }, { @@ -23079,7 +23080,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return this._state; } /** - * Get dialog id + * Get dialog id. */ }, { @@ -23097,13 +23098,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; - // to prevent duplicate emit terminated + // To prevent duplicate emit terminated event. if (this._is_terminated) { return; } this._is_terminated = true; - this._state = 'terminated'; // clear timers + this._state = 'terminated'; // Clear timers. clearTimeout(this._expires_timer); clearTimeout(this._unsubscribe_timeout_timer); @@ -23120,9 +23121,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_send", value: function _send(body, headers) { - this._params.cseq++; + this._params.cseq++; // Create & send request. - this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this._target, this._params, headers, body, this, this._credential); + var request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); + var requestSender = new RequestSender(this._ua, request, this); + requestSender.send(); } }, { key: "_scheduleSubscribe", @@ -23152,7 +23155,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return Subscriber; }(EventEmitter); -},{"./Constants":2,"./Grammar":7,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ "use strict"; var T1 = 500, @@ -24388,8 +24391,6 @@ var Parser = require('./Parser'); var SIPMessage = require('./SIPMessage'); -var RequestSender = require('./RequestSender'); - var sanityCheck = require('./sanityCheck'); var config = require('./Config'); @@ -24621,37 +24622,25 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { message.send(target, body, options); return message; } - /** - * Arbitrary client transaction - */ - - }, { - key: "sendRequest", - value: function sendRequest(method, target, params, headers, body, handlers, credential) { - debug('sendRequest()'); - var request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), this, params, headers, body); - var requestSender = new RequestSender(this, request, handlers, credential); - requestSender.send(); - } /** - * Create subscriber + * Create subscriber instance */ }, { - key: "subscriber", - value: function subscriber(target, options) { - debug('subscriber()'); - return new Subscriber(this, target, options); + key: "subscribe", + value: function subscribe(target, eventName, accept, options) { + debug('subscribe()'); + return new Subscriber(this, target, eventName, accept, options); } /** - * Create notifier + * Create notifier instance */ }, { - key: "notifier", - value: function notifier(options) { - debug('notifier()'); - return new Notifier(this, options); + key: "notify", + value: function notify(subscribe, contentType, options) { + debug('notify()'); + return new Notifier(this, subscribe, contentType, options); } /** * Terminate ongoing sessions. @@ -25406,7 +25395,7 @@ function onTransportData(data) { } } } -},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"debug":32,"events":31}],27:[function(require,module,exports){ +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"debug":32,"events":31}],27:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } diff --git a/dist/jssip.min.js b/dist/jssip.min.js index cabe7bc66..2f4bdf9aa 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?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,a,u;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=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=we())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=a),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=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),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,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(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,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),n._headers=h.cloneArray(i),n._headers.push("Event: ".concat(n._event_name)),n._headers.push("Contact: ".concat(n._contact)),n._allow_events&&n._headers.push("Allow-Events: ".concat(n._allow_events)),n._target=r.from.uri.user,r.to_tag=h.newTag(),n._params={from:r.to,from_tag:r.to_tag,to:r.from,to_tag:r.from_tag,call_id:r.call_id,cseq:Math.floor(1e4*Math.random()+1)},n._expires>0&&(n._id="".concat(n._params.call_id).concat(n._params.from_tag).concat(n._params.to_tag),f("add dialog id=",n._id),n._ua.newDialog(l(n)),n._setExpiresTimer()),n._is_terminated=!1,n._terminated_reason=null,n._terminated_retry_after=null,n.data={},n}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&f("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"Contact: ".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),f('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(_.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){f("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){f("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"sendNotify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("sendNotify()"),this._is_final_notify_sent)d("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++,this._ua.sendRequest(c.NOTIFY,this._target,this._params,r,e,this,this._credential)}}},{key:"sendFinalNotify",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;f("sendFinalNotify()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.sendNotify(e),this._is_final_notify_sent=!0,this._dialogTerminated(_.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(f("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===_.SUBSCRIPTION_EXPIRED;f('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.sendNotify(),e._dialogTerminated(_.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=w.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=p.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=w.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,f.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===w.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,f.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==w.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==w.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),this._status=w.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var I,O=s(o.getVideoTracks());try{for(O.s();!(I=O.n()).done;){var N=I.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};A('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,f.causes.WEBRTC_ERROR),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",u).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===w.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=w.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==w.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===w.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case w.STATUS_NULL:case w.STATUS_INVITE_SENT:case w.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===w.STATUS_NULL||this._status===w.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===w.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=w.STATUS_CANCELED,this._failed("local",null,f.causes.CANCELED);break;case w.STATUS_WAITING_FOR_ANSWER:case w.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case w.STATUS_WAITING_FOR_ACK:case w.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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===w.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==w.STATUS_CONFIRMED&&this._status!==w.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("hold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("unhold()"),this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:f.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;A("refer()");var r=e;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.CANCEL)this._status!==w.STATUS_WAITING_FOR_ANSWER&&this._status!==w.STATUS_ANSWERED||(this._status=w.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,f.causes.CANCELED));else switch(e.method){case f.ACK:if(this._status!==w.STATUS_WAITING_FOR_ACK)return;if(this._status=w.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===w.STATUS_CONFIRMED||this._status===w.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.causes.BYE)):this._status===w.STATUS_INVITE_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===w.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.INFO:if(this._status===w.STATUS_1XX_RECEIVED||this._status===w.STATUS_WAITING_FOR_ANSWER||this._status===w.STATUS_ANSWERED||this._status===w.STATUS_WAITING_FOR_ACK||this._status===w.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===w.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===w.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===w.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==w.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==w.STATUS_TERMINATED){if(this._status=w.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===w.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===w.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,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 A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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=w.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;A("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=p.cloneArray(t.extraHeaders);if(this._status!==w.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return A("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==w.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){R(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;A("_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!==I.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===w.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===w.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===w.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==w.STATUS_WAITING_FOR_ACK&&this._status!==w.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===w.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,f.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===w.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=w.STATUS_INVITE_SENT,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==w.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===w.STATUS_INVITE_SENT||this._status===w.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=w.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){A("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=w.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};A('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){R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=w.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===w.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==w.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=w.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==I.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){A("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!==I.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==I.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==w.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;for(var o 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,this._config2=i,a)Object.prototype.hasOwnProperty.call(a,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=a[o]));t.status!==t.C.STATUS_USER_CLOSED||this._method===s.BYE&&this._method===s.ACK||this._eventHandlers.onTransportError()}var t,n,u;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._config2&&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){var s=this._config2?this._config2:this._ua.configuration;this._auth=new i({username:s.authorization_user,password:s.password,realm:s.realm,ha1:s.ha1})}if(!this._auth.authenticate(this._request,t))return void this._eventHandlers.onReceiveResponse(e);this._challenged=!0,this._config2?(this._config2.realm=this._auth.get("realm"),this._config2.ha1=this._auth.get("ha1")):(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),u&&r(t,u),e}()},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,debug:32}],20:[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 Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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 a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(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 u(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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),r._headers.push(y)}return r._allow_events&&r._headers.push("Allow-Events: ".concat(r._allow_events)),r._is_terminated=!1,r.data={},r}return t=p,r=[{key:"C",get:function(){return _}}],(n=[{key:"C",get:function(){return _}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(_.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(_.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),f("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(d("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(_.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(_.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return d("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return d("missed Event header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return d("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return d("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(_.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(f("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(f('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var p=e.getHeader("content-type");f('emit "notify"'),this.emit("notify",h,e,c,p)}if(h){var m=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(_.RECEIVE_FINAL_NOTIFY,m,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;f("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"unsubscribe",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(f("unsubscribe()"),this._send_unsubscribe)d("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(_.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(f("removed dialog id=",this.id),this._ua.destroyDialog(this)),f('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++,this._ua.sendRequest(u.SUBSCRIBE,this._target,this._params,t,e,this,this._credential)}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,f("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Grammar":7,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R("- ".concat(i,": NOT SHOWN"));break;default:R("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),O}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./RequestSender":19,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Et()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Et()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");g+=';+sip.instance=""'),i._headers.push(g)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(_('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.d.ts b/lib/Notifier.d.ts index 9216c9ccc..6a4e67e6e 100644 --- a/lib/Notifier.d.ts +++ b/lib/Notifier.d.ts @@ -15,8 +15,8 @@ declare enum NotifierTerminatedCode { export class Notifier extends EventEmitter { start(): void; setActiveState(): void; - sendNotify(body?: string): void; - sendFinalNotify(body?: string, reason?: string): void; + notify(body?: string): void; + terminate(body?: string, reason?: string): void; get state(): string; get id(): string; static get C(): typeof NotifierTerminatedCode; diff --git a/lib/Notifier.js b/lib/Notifier.js index d60f37ef4..d5f83a183 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -1,6 +1,8 @@ const EventEmitter = require('events').EventEmitter; const JsSIP_C = require('./Constants'); const Utils = require('./Utils'); +const SIPMessage = require('./SIPMessage'); +const RequestSender = require('./RequestSender'); const debug = require('debug')('JsSIP:Notifier'); const debugerror = require('debug')('JsSIP:ERROR:Notifier'); @@ -38,22 +40,30 @@ module.exports = class Notifier extends EventEmitter } /** - * -param {Object} ua JsSIP UA - * -param {Object} options - * -param {IncomingRequest} subscribe - * -param {String} contentType Content-Type header value - * -param {Array} headers Optional. Additional SIP headers. - * -param {String} allowEvents Allow-Events header value. Optional. - * -param {Object} credential. Will have priority over ua.configuration. Optional. - * -param {Boolean} pending Set initial dialog state as "pending". Optional. + * @param {UA} ua - JsSIP User Agent instance. + * @param {IncomingRequest} subscribe - Subscribe request. + * @param {string} contentType - Content-Type header value. + * @param {NotifierOptions} options - Optional parameters. + * @param {Array} extraHeaders - Additional SIP headers. + * @param {string} allowEvents - Allow-Events header value. + * @param {boolean} pending - Set initial dialog state as "pending". */ - constructor(ua, { subscribe, contentType, headers, allowEvents, - credential, pending }) + constructor(ua, subscribe, contentType, { extraHeaders, allowEvents, pending }) { debug('new'); super(); + if (!subscribe) + { + throw new TypeError('subscribe is undefined'); + } + + if (!contentType) + { + throw new TypeError('contentType is undefined'); + } + this._ua = ua; this._initial_subscribe = subscribe; this._expires_timestamp = null; @@ -64,27 +74,38 @@ module.exports = class Notifier extends EventEmitter this._is_final_notify_sent = false; this._is_first_notify_response = true; + // To prevent duplicate emit 'terminated'. + this._is_terminated = false; + + // Optional. Used to build terminated Subscription-State. + this._terminated_reason = null; + this._terminated_retry_after = null; + + // Custom session empty object for high level use. + this.data = {}; + // Dialog id. this._id = null; - this._allow_events = allowEvents; - this._event_name = subscribe.getHeader('event'); - - if (!contentType) - { - throw new TypeError('contentType is undefined'); - } + + const eventName = subscribe.getHeader('event'); this._content_type = contentType; this._expires = parseInt(subscribe.getHeader('expires')); - this._credential = credential; - this._contact = ``; - this._headers = Utils.cloneArray(headers); - this._headers.push(`Event: ${this._event_name}`); - this._headers.push(`Contact: ${this._contact}`); + this._headers = Utils.cloneArray(extraHeaders); + this._headers.push(`Event: ${eventName}`); + + // Use contact from extraHeaders or create it. + this._contact = this._headers.find((header) => header.startsWith('Contact')); + if (!this._contact) + { + this._contact = `Contact: `; + + this._headers.push(this._contact); + } - if (this._allow_events) + if (allowEvents) { - this._headers.push(`Allow-Events: ${this._allow_events}`); + this._headers.push(`Allow-Events: ${allowEvents}`); } this._target = subscribe.from.uri.user; @@ -112,16 +133,6 @@ module.exports = class Notifier extends EventEmitter // Set expires timer and time-stamp. this._setExpiresTimer(); } - - // To prevent duplicate emit 'terminated'. - this._is_terminated = false; - - // Optional. Used to build terminated Subscription-State. - this._terminated_reason = null; - this._terminated_retry_after = null; - - // Custom session empty object for high level use. - this.data = {}; } /** @@ -182,17 +193,17 @@ module.exports = class Notifier extends EventEmitter return; } - let h = request.getHeader('expires'); + let expiresValue = request.getHeader('expires'); - if (h === undefined || h === null) + if (expiresValue === undefined || expiresValue === null) { // Missed header Expires. RFC 6665 3.1.1. Set default expires value. - h = '900'; - debug(`Missed expires header. Set by default ${h}`); + expiresValue = '900'; + debug(`Missed expires header. Set by default ${expiresValue}`); } - this._expires = parseInt(h); - request.reply(200, null, [ `Expires: ${this._expires}`, `Contact: ${this._contact}` ]); + this._expires = parseInt(expiresValue); + request.reply(200, null, [ `Expires: ${this._expires}`, `${this._contact}` ]); const body = request.body; const content_type = request.getHeader('content-type'); @@ -241,11 +252,11 @@ module.exports = class Notifier extends EventEmitter /** * Send the initial and subsequent NOTIFY request. - * -param {String} body. Optional. + * @param {string} body - notify request body. */ - sendNotify(body = null) + notify(body = null) { - debug('sendNotify()'); + debug('notify()'); // Prevent send notify after final notify. if (this._is_final_notify_sent) @@ -290,26 +301,31 @@ module.exports = class Notifier extends EventEmitter } this._params.cseq++; - this._ua.sendRequest(JsSIP_C.NOTIFY, this._target, this._params, headers, body, - this, this._credential); + + // Create & send request. + const request = new SIPMessage.OutgoingRequest(JsSIP_C.NOTIFY, + this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); + const requestSender = new RequestSender(this._ua, request, this); + + requestSender.send(); } /** - * Send the final NOTIFY request + * Terminate. (Send the final NOTIFY request). * - * -param {String} body Optional. - * -param {String} reason Optional. To build Subscription-State header. - * -param {Number} retryAfter Optional. To build Subscription-State header. + * @param {string} body - Notify message body. + * @param {string} reason - Set Subscription-State reason parameter. + * @param {number} retryAfter - Set Subscription-State retry-after parameter. */ - sendFinalNotify(body = null, reason = null, retryAfter = null) + terminate(body = null, reason = null, retryAfter = null) { - debug('sendFinalNotify()'); + debug('terminate()'); this._state = 'terminated'; this._terminated_reason = reason; this._terminated_retry_after = retryAfter; - this.sendNotify(body); + this.notify(body); this._is_final_notify_sent = true; this._dialogTerminated(C.SEND_FINAL_NOTIFY); @@ -371,7 +387,7 @@ module.exports = class Notifier extends EventEmitter this._terminated_reason = 'timeout'; this._is_final_notify_sent = true; - this.sendNotify(); + this.notify(); this._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this._expires * 1000); } diff --git a/lib/RequestSender.js b/lib/RequestSender.js index aee9e25bf..d33f9f61b 100644 --- a/lib/RequestSender.js +++ b/lib/RequestSender.js @@ -13,7 +13,7 @@ const EventHandlers = { module.exports = class RequestSender { - constructor(ua, request, eventHandlers, config2=null) + constructor(ua, request, eventHandlers) { this._ua = ua; this._eventHandlers = eventHandlers; @@ -22,8 +22,7 @@ module.exports = class RequestSender this._auth = null; this._challenged = false; this._staled = false; - this._config2 = config2; - + // Define the undefined handlers. for (const handler in EventHandlers) { @@ -93,8 +92,7 @@ module.exports = class RequestSender * Authenticate once. _challenged_ flag used to avoid infinite authentications. */ if ((status_code === 401 || status_code === 407) && - (this._config2 !== null || this._ua.configuration.password !== null - || this._ua.configuration.ha1 !== null)) + (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) { // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header. @@ -122,13 +120,11 @@ module.exports = class RequestSender { if (!this._auth) { - const cnf = this._config2 ? this._config2 : this._ua.configuration; - this._auth = new DigestAuthentication({ - username : cnf.authorization_user, - password : cnf.password, - realm : cnf.realm, - ha1 : cnf.ha1 + username : this._ua.configuration.authorization_user, + password : this._ua.configuration.password, + realm : this._ua.configuration.realm, + ha1 : this._ua.configuration.ha1 }); } @@ -141,17 +137,10 @@ module.exports = class RequestSender } this._challenged = true; - // Update ha1 and realm in the UA or in alternative config. - if (!this._config2) - { - this._ua.set('realm', this._auth.get('realm')); - this._ua.set('ha1', this._auth.get('ha1')); - } - else - { - this._config2.realm = this._auth.get('realm'); - this._config2.ha1 = this._auth.get('ha1'); - } + // Update ha1 and realm in the UA. + this._ua.set('realm', this._auth.get('realm')); + this._ua.set('ha1', this._auth.get('ha1')); + if (challenge.stale) { this._staled = true; diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts index 94b91e7c9..d63e10491 100644 --- a/lib/Subscriber.d.ts +++ b/lib/Subscriber.d.ts @@ -14,7 +14,7 @@ declare enum SubscriberTerminatedCode { export class Subscriber extends EventEmitter { subscribe(body?: string): void; - unsubscribe(body?: string): void; + terminate(body?: string): void; get state(): string; get id(): string; static get C(): typeof SubscriberTerminatedCode; diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 00706f41a..e1c5a1c7d 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -2,6 +2,8 @@ const EventEmitter = require('events').EventEmitter; const JsSIP_C = require('./Constants'); const Utils = require('./Utils'); const Grammar = require('./Grammar'); +const SIPMessage = require('./SIPMessage'); +const RequestSender = require('./RequestSender'); const debug = require('debug')('JsSIP:Subscriber'); const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); @@ -21,7 +23,7 @@ const C = { }; /** - * It's implementation of RFC 6665 Subscriber. + * RFC 6665 Subscriber implementation. */ module.exports = class Subscriber extends EventEmitter { @@ -39,70 +41,59 @@ module.exports = class Subscriber extends EventEmitter } /** - * -param {Object} ua reference to JsSIP.UA - * -param {String} target - * -param {Object} options - * -param {String} eventName Event header value. May end with optional ;id=xxx - * -param {String} accept Accept header value. - * -param {Number} expires Expires header value. Optional. Default is 900. - * -param {String} contentType Content-Type header value. - * -param {String} allowEvents Allow-Events header value. Optional. - * -param {Object} params Will have priority over ua.configuration. Optional. + * @param {UA} ua - reference to JsSIP.UA + * @param {string} target + * @param {string} eventName - Event header value. May end with optional ;id=xxx + * @param {string} accept - Accept header value. + * + * @param {SubscriberOption} options - optional parameters. + * @param {number} expires - Expires header value. Default is 900. + * @param {string} contentType - Content-Type header value. Used for SUBSCRIBE with body + * @param {string} allowEvents - Allow-Events header value. + * @param {RequestParams} params - Will have priority over ua.configuration. * If set please define: to_uri, to_display_name, from_uri, from_display_name - * -param {Array} headers Optional. Additional SIP headers. - * -param {Object} credential. Will have priority over ua.configuration. Optional. + * @param {Array} extraHeaders - Additional SIP headers. */ - constructor(ua, target, { eventName, accept, expires, contentType, - allowEvents, params, headers, credential }) + constructor(ua, target, eventName, accept, { expires, contentType, + allowEvents, params, extraHeaders }) { debug('new'); super(); - this._ua = ua; - + // Check that arguments are defined if (!target) { throw new TypeError('target is undefined'); } - this._target = target; - if (!eventName) { throw new TypeError('eventName is undefined'); } - const parsed = Grammar.parse(eventName, 'Event'); - - if (parsed === -1) - { - throw new TypeError('eventName - wrong format'); - } - - this._event_name = parsed.event; - this._event_id = parsed.params && parsed.params.id; - if (!accept) { throw new TypeError('accept is undefined'); } + this._ua = ua; + this._target = target; this._accept = accept; - + if (expires !== 0 && !expires) { expires = 900; } this._expires = expires; - this._allow_events = allowEvents; // Used to subscribe with body. this._content_type = contentType; this._is_first_notify_request = true; + // Set subscriber dialog parameters. this._params = Utils.cloneObject(params); if (!this._params.from_uri) @@ -110,7 +101,6 @@ module.exports = class Subscriber extends EventEmitter this._params.from_uri = this._ua.configuration.uri; } - // Set SUBSCRIBE dialog parameters. this._params.from_tag = Utils.newTag(); this._params.to_tag = null; this._params.call_id = Utils.createRandomToken(20); @@ -121,9 +111,6 @@ module.exports = class Subscriber extends EventEmitter this._params.cseq = Math.floor((Math.random() * 10000) + 1); } - // Optional, used if credential is different from REGISTER/INVITE. - this._credential = credential; - // Subscriber state: init, notify_wait, pending, active, terminated. this._state = 'init'; @@ -134,27 +121,41 @@ module.exports = class Subscriber extends EventEmitter this._expires_timer = null; this._expires_timestamp = null; - // To prvent duplicate un-SUBSCRIBE sending. + // To prevent duplicate un-subscribe sending. this._send_unsubscribe = false; + // To prevent duplicate emit terminated event. + this._is_terminated = false; + // After send un-subscribe wait final NOTIFY limited time. this._unsubscribe_timeout_timer = null; - - let event_value = this._event_name; - if (this._event_id) + // Custom session empty object for high level use. + this.data = {}; + + const parsed = Grammar.parse(eventName, 'Event'); + + if (parsed === -1) { - event_value += `;id=${this._event_id}`; + throw new TypeError('eventName - wrong format'); + } + + let eventValue = parsed.event; + const eventId = parsed.params && parsed.params.id; + + if (eventId) + { + eventValue += `;id=${this.eventId}`; } - this._headers = Utils.cloneArray(headers); + this._headers = Utils.cloneArray(extraHeaders); this._headers = this._headers.concat([ - `Event: ${event_value}`, + `Event: ${eventValue}`, `Expires: ${this._expires}`, `Accept: ${this._accept}` ]); - if (!this._headers.find((h) => h.startsWith('Contact'))) + if (!this._headers.find((header) => header.startsWith('Contact'))) { let contact = `Contact: `; @@ -162,15 +163,10 @@ module.exports = class Subscriber extends EventEmitter this._headers.push(contact); } - if (this._allow_events) + if (allowEvents) { - this._headers.push(`Allow-Events: ${this._allow_events}`); + this._headers.push(`Allow-Events: ${allowEvents}`); } - - this._is_terminated = false; - - // Custom session empty object for high level use. - this.data = {}; } /** @@ -361,7 +357,7 @@ module.exports = class Subscriber extends EventEmitter /** * Send the initial (non-fetch) and subsequent SUBSCRIBE. - * -param {String} body. Optional. + * @param {string} body - subscribe request body. */ subscribe(body = null) { @@ -386,14 +382,15 @@ module.exports = class Subscriber extends EventEmitter } /** + * terminate. * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0). - * -param {String} body. Optional. + * @param {string} body - Un-subscribe request body */ - unsubscribe(body = null) + terminate(body = null) { - debug('unsubscribe()'); + debug('terminate()'); - // Prevent duplication unsubscribe. + // Prevent duplication un-subscribe sending. if (this._send_unsubscribe) { debugerror('unsubscribe has already been sent'); @@ -466,8 +463,13 @@ module.exports = class Subscriber extends EventEmitter _send(body, headers) { this._params.cseq++; - this._ua.sendRequest(JsSIP_C.SUBSCRIBE, this._target, this._params, headers, - body, this, this._credential); + + // Create & send request. + const request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, + this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); + const requestSender = new RequestSender(this._ua, request, this); + + requestSender.send(); } _scheduleSubscribe(expires) diff --git a/lib/UA.d.ts b/lib/UA.d.ts index ac35622d0..e74bcdb4a 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -134,11 +134,6 @@ export interface UAContact { toString(options?: UAContactOptions): string } -export interface Credential { - authorization_user: string; - password: string; -} - export interface RequestParams { from_uri: URI; from_display_name?: string; @@ -158,23 +153,17 @@ export interface SubscriberParams { } export interface SubscriberOptions { - eventName: string; - accept: string; expires?: number; contentType?: string; allowEvents?: string; params?: SubscriberParams; - headers?: string[]; - credential?: Credential; + extraHeaders?: string[]; } export interface NotifierOptions { - subscribe: IncomingRequest; - contentType: string; allowEvents?: string; - headers?: string[]; + extraHeaders?: string[]; pending?: boolean; - credential?: Credential; } declare enum UAStatus { @@ -213,11 +202,9 @@ export class UA extends EventEmitter { sendMessage(target: string | URI, body: string, options?: SendMessageOptions): Message; - sendRequest(method: string, target: string, params: RequestParams, headers?: string[], body?: string, handlers?: any, credential?: Credential): void; - - subscriber(target: string, options: SubscriberOptions): Subscriber; + subscribe(target: string, eventName: string, accept: string, options?: SubscriberOptions): Subscriber; - notifier(options: NotifierOptions): Notifier; + notifier( subscribe: IncomingRequest, contentType: string, options?: NotifierOptions): Notifier; terminateSessions(options?: TerminateOptions): void; diff --git a/lib/UA.js b/lib/UA.js index 5e0aafdcb..82585d13d 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -12,7 +12,6 @@ const Exceptions = require('./Exceptions'); const URI = require('./URI'); const Parser = require('./Parser'); const SIPMessage = require('./SIPMessage'); -const RequestSender = require('./RequestSender'); const sanityCheck = require('./sanityCheck'); const config = require('./Config'); const debug = require('debug')('JsSIP:UA'); @@ -260,37 +259,24 @@ module.exports = class UA extends EventEmitter return message; } - /** - * Arbitrary client transaction - */ - sendRequest(method, target, params, headers, body, handlers, credential) - { - debug('sendRequest()'); - const request = new SIPMessage.OutgoingRequest(method, this.normalizeTarget(target), - this, params, headers, body); - const requestSender = new RequestSender(this, request, handlers, credential); - - requestSender.send(); - } - /** - * Create subscriber + * Create subscriber instance */ - subscriber(target, options) + subscribe(target, eventName, accept, options) { - debug('subscriber()'); + debug('subscribe()'); - return new Subscriber(this, target, options); + return new Subscriber(this, target, eventName, accept, options); } /** - * Create notifier + * Create notifier instance */ - notifier(options) + notify(subscribe, contentType, options) { - debug('notifier()'); + debug('notify()'); - return new Notifier(this, options); + return new Notifier(this, subscribe, contentType, options); } /** From 3b124231fdfc98f254b24216f30e4226235f1725 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 1 Jun 2021 21:57:50 +0300 Subject: [PATCH 39/70] fixed: Subscriber check matching Notify event --- dist/jssip.js | 9 +++++---- dist/jssip.min.js | 2 +- lib/Subscriber.js | 10 ++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index a16a3fd29..daaf35b3a 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22816,11 +22816,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { throw new TypeError('eventName - wrong format'); } - var eventValue = parsed.event; - var eventId = parsed.params && parsed.params.id; + _this._event_name = parsed.event; + _this._event_id = parsed.params && parsed.params.id; + var eventValue = _this._event_name; - if (eventId) { - eventValue += ";id=".concat(_this.eventId); + if (_this._event_id) { + eventValue += ";id=".concat(_this._event_id); } _this._headers = Utils.cloneArray(extraHeaders); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 2f4bdf9aa..d1091c1cb 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Et()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Et()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");g+=';+sip.instance=""'),i._headers.push(g)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(_('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Et()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Et()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");g+=';+sip.instance=""'),i._headers.push(g)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(_('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index e1c5a1c7d..3a056bd69 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -140,12 +140,14 @@ module.exports = class Subscriber extends EventEmitter throw new TypeError('eventName - wrong format'); } - let eventValue = parsed.event; - const eventId = parsed.params && parsed.params.id; + this._event_name = parsed.event; + this._event_id = parsed.params && parsed.params.id; - if (eventId) + let eventValue = this._event_name; + + if (this._event_id) { - eventValue += `;id=${this.eventId}`; + eventValue += `;id=${this._event_id}`; } this._headers = Utils.cloneArray(extraHeaders); From 699b4634e0a1f6918174bb3afee025ae6145a65f Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 5 Jun 2021 22:58:54 +0300 Subject: [PATCH 40/70] subscriber/notifer state is number --- dist/jssip.js | 89 +++++++++++++++++++++++++++++++++++++---------- dist/jssip.min.js | 2 +- lib/Notifier.js | 33 +++++++++++++----- lib/Subscriber.js | 41 ++++++++++++++++------ 4 files changed, 128 insertions(+), 37 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index daaf35b3a..394d67737 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16628,13 +16628,18 @@ debugerror.log = console.warn.bind(console); */ var C = { + // Termination codes. NOTIFY_RESPONSE_TIMEOUT: 0, NOTIFY_TRANSPORT_ERROR: 1, NOTIFY_NON_OK_RESPONSE: 2, NOTIFY_FAILED_AUTHENTICATION: 3, SEND_FINAL_NOTIFY: 4, RECEIVE_UNSUBSCRIBE: 5, - SUBSCRIPTION_EXPIRED: 6 + SUBSCRIPTION_EXPIRED: 6, + // Notifer states + STATE_PENDING: 0, + STATE_ACTIVE: 1, + STATE_TERMINATED: 2 }; /** * RFC 6665 Notifier implementation. @@ -16679,7 +16684,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._expires_timestamp = null; _this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait. - _this._state = pending ? 'pending' : 'active'; + _this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; _this._is_final_notify_sent = false; _this._is_first_notify_response = true; // To prevent duplicate emit 'terminated'. @@ -16843,8 +16848,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function setActiveState() { debug('setActiveState()'); - if (this._state === 'pending') { - this._state = 'active'; + if (this._state === C.STATE_PENDING) { + this._state = C.STATE_ACTIVE; } } /** @@ -16863,9 +16868,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - var subs_state = this._state; + var subs_state = this._stateNumberToString(this._state); - if (this._state !== 'terminated') { + if (this._state !== C.STATE_TERMINATED) { var expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); if (expires < 0) { @@ -16912,7 +16917,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; debug('terminate()'); - this._state = 'terminated'; + this._state = C.STATE_TERMINATED; this._terminated_reason = reason; this._terminated_retry_after = retryAfter; this.notify(body); @@ -16950,7 +16955,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } this._is_terminated = true; - this._state = 'terminated'; + this._state = C.STATE_TERMINATED; clearTimeout(this._expires_timer); if (this._id) { @@ -16983,6 +16988,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this2._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this._expires * 1000); } + }, { + key: "_stateNumberToString", + value: function _stateNumberToString(state) { + switch (state) { + case C.STATE_PENDING: + return 'pending'; + + case C.STATE_ACTIVE: + return 'active'; + + case C.STATE_TERMINATED: + return 'terminated'; + + default: + throw new TypeError('wrong state value'); + } + } }], [{ key: "C", get: @@ -22711,13 +22733,20 @@ debugerror.log = console.warn.bind(console); */ var C = { + // Termination codes. SUBSCRIBE_RESPONSE_TIMEOUT: 0, SUBSCRIBE_TRANSPORT_ERROR: 1, SUBSCRIBE_NON_OK_RESPONSE: 2, SUBSCRIBE_FAILED_AUTHENTICATION: 3, UNSUBSCRIBE_TIMEOUT: 4, RECEIVE_FINAL_NOTIFY: 5, - RECEIVE_BAD_NOTIFY: 6 + RECEIVE_BAD_NOTIFY: 6, + // Subscriber states. + STATE_PENDING: 0, + STATE_ACTIVE: 1, + STATE_TERMINATED: 2, + STATE_INIT: 3, + STATE_NOTIFY_WAIT: 4 }; /** * RFC 6665 Subscriber implementation. @@ -22793,10 +22822,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (_this._params.cseq === undefined) { _this._params.cseq = Math.floor(Math.random() * 10000 + 1); - } // Subscriber state: init, notify_wait, pending, active, terminated. + } // Subscriber state. - _this._state = 'init'; // Dialog id. + _this._state = C.STATE_INIT; // Dialog id. _this._id = null; // To refresh subscription. @@ -22962,10 +22991,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._is_first_notify_request = false; // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? } - var new_state = subs_state.state.toLowerCase(); + var new_state = this._stateStringToNumber(subs_state.state); + var prev_state = this._state; - if (prev_state !== 'terminated' && new_state !== 'terminated') { + if (prev_state !== C.STATE_TERMINATED && new_state !== C.STATE_TERMINATED) { this._state = new_state; if (subs_state.expires !== undefined) { @@ -22981,14 +23011,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } - if (prev_state !== 'active' && new_state === 'active') { + if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { debug('emit "active"'); this.emit('active'); } var body = request.body; // Check if the NOTIFY is final. - var is_final = new_state === 'terminated'; // Notify event fired for NOTIFY with body. + var is_final = new_state === C.STATE_TERMINATED; // Notify event fired for NOTIFY with body. if (body) { var content_type = request.getHeader('content-type'); @@ -23022,8 +23052,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; debug('subscribe()'); - if (this._state === 'init') { - this._state = 'notify_wait'; + if (this._state === C.STATE_INIT) { + this._state = C.STATE_NOTIFY_WAIT; } var headers = this._headers.slice(); @@ -23105,7 +23135,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } this._is_terminated = true; - this._state = 'terminated'; // Clear timers. + this._state = C.STATE_TERMINATED; // Clear timers. clearTimeout(this._expires_timer); clearTimeout(this._unsubscribe_timeout_timer); @@ -23143,6 +23173,29 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._send(null, _this3._headers); }, timeout); } + }, { + key: "_stateStringToNumber", + value: function _stateStringToNumber(strState) { + switch (strState) { + case 'pending': + return C.STATE_PENDING; + + case 'active': + return C.STATE_ACTIVE; + + case 'terminated': + return C.STATE_TERMINATED; + + case 'init': + return C.STATE_INIT; + + case 'notify_wait': + return C.STATE_NOTIFY_WAIT; + + default: + throw new TypeError('wrong state value'); + } + } }], [{ key: "C", get: diff --git a/dist/jssip.min.js b/dist/jssip.min.js index d1091c1cb..b54df9626 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:C,escaped:E,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&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:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ce,ttl_param:Ee,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,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:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=C()),e}function C(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&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&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ce(){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&&u('"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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=He())&&(r=Be()),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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=E()),e}function Ve(){var e;return null===(e=S())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Ct(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Et(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Et()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);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,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&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&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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 un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=Cn())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function 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,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Cn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=G())&&null!==(n=bn())?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=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Et()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),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&&u('"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 Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),"pending"===this._state&&(this._state="active")}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._state;if("terminated"!==this._state){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state="terminated",this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var C,E=s(o.getAudioTracks());try{for(E.s();!(C=E.n()).done;){var b=C.value;o.removeTrack(b)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 E(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new C(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),C=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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,S);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:C,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");g+=';+sip.instance=""'),i._headers.push(g)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=s.state.toLowerCase(),o=this._state;if("terminated"!==o&&"terminated"!==i&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}"active"!==o&&"active"===i&&(_('emit "active"'),this.emit("active"));var c=e.body,h="terminated"===i;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),"init"===this._state&&(this._state="notify_wait");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state="terminated",clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:A,SWS:b,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:Ae,lr_param:be,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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&&u('":"')),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 I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=A();null!==s;)r.push(s),s=A();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=A();null!==s;)r.push(s),s=A();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),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 D(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"="')),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&&u('"("')),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,l;return s=i,l=i,null!==(e=b())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),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&&u('"<"')),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&&u('","')),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 B(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),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())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),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 W(){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 Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=A()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=A())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"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&&u('"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,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(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],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function At(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function bt(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=A()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=A()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=A()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=bn())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&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 Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),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,a;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&&(a=e,e=void(jn.port=parseInt(a.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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=A());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=A());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;b("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new A("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new A("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;b("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var A=E.value;o.removeTrack(A)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};b('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};b("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(b("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(b("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(b("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};b("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(b('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(b("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};b("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};b("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(b("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:f.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(b("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:f.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;b("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:f.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;b("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 C(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 b("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(b("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};b('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){b("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){b("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||(b("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(b("_isReadyToReOffer() | session not established yet"),!1):(b("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(b("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(b("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(b("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),b('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(b("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 b('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};b('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(b(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(b(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;b("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=p.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 b("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){R(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;b("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=p.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 b("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){R(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;b("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};b('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(b("receiveRefer()"),!e.refer_to)return b("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return b("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);b('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(b("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;b("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){b("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,b('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(b("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void b(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){b("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};b('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};b('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};b('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};b('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),R('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]:{};b("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};b('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};b('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){b("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){b("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!==w.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){b("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){b("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(b("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){b("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){b("session connecting"),b('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){b("session progress"),b('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){b("session accepted"),this._start_time=new Date,b('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){b("session confirmed"),this._is_confirmed=!0,b('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){b("session ended"),this._end_time=new Date,this._close(),b('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){b("session failed"),b('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),b('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){b("session onhold"),this._setLocalMediaStatus(),b('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){b("session onunhold"),this._setLocalMediaStatus(),b('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;b("session onmute"),this._setLocalMediaStatus(),b('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;b("session onunmute"),this._setLocalMediaStatus(),b('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("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){a("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()):(a("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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==m.STATE_TERMINATED&&i!==m.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==m.STATE_ACTIVE&&i===m.STATE_ACTIVE&&(_('emit "active"'),this.emit("active"));var c=e.body,h=i===m.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),this._state===m.STATE_INIT&&(this._state=m.STATE_NOTIFY_WAIT);var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return m.STATE_PENDING;case"active":return m.STATE_ACTIVE;case"terminated":return m.STATE_TERMINATED;case"init":return m.STATE_INIT;case"notify_wait":return m.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),A=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),b=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 b("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":b("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":b("- ".concat(i,": NOT SHOWN"));break;default:b("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (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.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index d5f83a183..225a16d2d 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -12,13 +12,19 @@ debugerror.log = console.warn.bind(console); * Termination codes. */ const C = { + // Termination codes. NOTIFY_RESPONSE_TIMEOUT : 0, NOTIFY_TRANSPORT_ERROR : 1, NOTIFY_NON_OK_RESPONSE : 2, NOTIFY_FAILED_AUTHENTICATION : 3, SEND_FINAL_NOTIFY : 4, RECEIVE_UNSUBSCRIBE : 5, - SUBSCRIPTION_EXPIRED : 6 + SUBSCRIPTION_EXPIRED : 6, + + // Notifer states + STATE_PENDING : 0, + STATE_ACTIVE : 1, + STATE_TERMINATED : 2 }; /** @@ -70,7 +76,7 @@ module.exports = class Notifier extends EventEmitter this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait. - this._state = pending ? 'pending' : 'active'; + this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; this._is_final_notify_sent = false; this._is_first_notify_response = true; @@ -244,9 +250,9 @@ module.exports = class Notifier extends EventEmitter { debug('setActiveState()'); - if (this._state === 'pending') + if (this._state === C.STATE_PENDING) { - this._state = 'active'; + this._state = C.STATE_ACTIVE; } } @@ -266,9 +272,9 @@ module.exports = class Notifier extends EventEmitter return; } - let subs_state = this._state; + let subs_state = this._stateNumberToString(this._state); - if (this._state !== 'terminated') + if (this._state !== C.STATE_TERMINATED) { let expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); @@ -321,7 +327,7 @@ module.exports = class Notifier extends EventEmitter { debug('terminate()'); - this._state = 'terminated'; + this._state = C.STATE_TERMINATED; this._terminated_reason = reason; this._terminated_retry_after = retryAfter; @@ -358,7 +364,7 @@ module.exports = class Notifier extends EventEmitter } this._is_terminated = true; - this._state = 'terminated'; + this._state = C.STATE_TERMINATED; clearTimeout(this._expires_timer); if (this._id) @@ -391,4 +397,15 @@ module.exports = class Notifier extends EventEmitter this._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this._expires * 1000); } + + _stateNumberToString(state) + { + switch (state) + { + case C.STATE_PENDING: return 'pending'; + case C.STATE_ACTIVE: return 'active'; + case C.STATE_TERMINATED: return 'terminated'; + default: throw new TypeError('wrong state value'); + } + } }; \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 3a056bd69..e8ea4e545 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -13,13 +13,21 @@ debugerror.log = console.warn.bind(console); * Termination codes. */ const C = { + // Termination codes. SUBSCRIBE_RESPONSE_TIMEOUT : 0, SUBSCRIBE_TRANSPORT_ERROR : 1, SUBSCRIBE_NON_OK_RESPONSE : 2, SUBSCRIBE_FAILED_AUTHENTICATION : 3, UNSUBSCRIBE_TIMEOUT : 4, RECEIVE_FINAL_NOTIFY : 5, - RECEIVE_BAD_NOTIFY : 6 + RECEIVE_BAD_NOTIFY : 6, + + // Subscriber states. + STATE_PENDING : 0, + STATE_ACTIVE : 1, + STATE_TERMINATED : 2, + STATE_INIT : 3, + STATE_NOTIFY_WAIT : 4 }; /** @@ -111,8 +119,8 @@ module.exports = class Subscriber extends EventEmitter this._params.cseq = Math.floor((Math.random() * 10000) + 1); } - // Subscriber state: init, notify_wait, pending, active, terminated. - this._state = 'init'; + // Subscriber state. + this._state = C.STATE_INIT; // Dialog id. this._id = null; @@ -296,10 +304,10 @@ module.exports = class Subscriber extends EventEmitter // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? } - const new_state = subs_state.state.toLowerCase(); + const new_state = this._stateStringToNumber(subs_state.state); const prev_state = this._state; - if (prev_state !== 'terminated' && new_state !== 'terminated') + if (prev_state !== C.STATE_TERMINATED && new_state !== C.STATE_TERMINATED) { this._state = new_state; @@ -319,7 +327,7 @@ module.exports = class Subscriber extends EventEmitter } } - if (prev_state !== 'active' && new_state === 'active') + if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { debug('emit "active"'); this.emit('active'); @@ -328,7 +336,7 @@ module.exports = class Subscriber extends EventEmitter const body = request.body; // Check if the NOTIFY is final. - const is_final = new_state === 'terminated'; + const is_final = new_state === C.STATE_TERMINATED; // Notify event fired for NOTIFY with body. if (body) @@ -365,9 +373,9 @@ module.exports = class Subscriber extends EventEmitter { debug('subscribe()'); - if (this._state === 'init') + if (this._state === C.STATE_INIT) { - this._state = 'notify_wait'; + this._state = C.STATE_NOTIFY_WAIT; } const headers = this._headers.slice(); @@ -446,7 +454,7 @@ module.exports = class Subscriber extends EventEmitter } this._is_terminated = true; - this._state = 'terminated'; + this._state = C.STATE_TERMINATED; // Clear timers. clearTimeout(this._expires_timer); @@ -490,4 +498,17 @@ module.exports = class Subscriber extends EventEmitter this._send(null, this._headers); }, timeout); } + + _stateStringToNumber(strState) + { + switch (strState) + { + case 'pending': return C.STATE_PENDING; + case 'active': return C.STATE_ACTIVE; + case 'terminated': return C.STATE_TERMINATED; + case 'init': return C.STATE_INIT; + case 'notify_wait': return C.STATE_NOTIFY_WAIT; + default: throw new TypeError('wrong state value'); + } + } }; \ No newline at end of file From 9d47a6d0715a3e0bc27b7e9b37229bc12afbf012 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 8 Jun 2021 10:43:34 +0300 Subject: [PATCH 41/70] added emit newSubscriber --- dist/jssip.js | 5 ++++- dist/jssip.min.js | 2 +- lib/Subscriber.js | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 515f8f823..edb31da2b 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22918,7 +22918,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (route_set.length > 0) { this._params.route_set = route_set; - } + } // Тo wait for a response to the initial subscribe, and then send the next subscribe. + + + this.emit('newSubscriber'); } // Check expires value. diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 7493264c7..31dd82660 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:A,SWS:b,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:Ae,lr_param:be,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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&&u('":"')),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 I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=A();null!==s;)r.push(s),s=A();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=A();null!==s;)r.push(s),s=A();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),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 D(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"="')),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&&u('"("')),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,l;return s=i,l=i,null!==(e=b())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),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&&u('"<"')),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&&u('","')),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 B(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),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())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),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 W(){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 Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=A()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=A())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"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&&u('"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,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(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],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function At(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function bt(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=A()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=A()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=A()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=bn())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&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 Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),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,a;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&&(a=e,e=void(jn.port=parseInt(a.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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=A());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=A());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;b("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new A("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new A("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;b("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var A=E.value;o.removeTrack(A)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};b('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};b("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(b("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(b("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(b("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};b("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(b('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(b("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};b("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};b("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(b("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:f.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(b("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:f.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;b("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:f.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;b("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 C(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 b("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(b("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};b('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){b("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){b("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||(b("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(b("_isReadyToReOffer() | session not established yet"),!1):(b("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(b("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(b("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(b("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),b('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(b("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 b('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};b('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(b(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(b(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;b("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=p.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 b("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){R(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;b("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=p.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 b("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){R(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;b("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};b('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(b("receiveRefer()"),!e.refer_to)return b("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return b("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);b('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(b("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;b("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){b("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,b('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(b("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void b(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){b("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};b('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};b('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};b('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};b('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),R('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]:{};b("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};b('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};b('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){b("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){b("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!==w.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){b("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){b("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(b("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){b("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){b("session connecting"),b('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){b("session progress"),b('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){b("session accepted"),this._start_time=new Date,b('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){b("session confirmed"),this._is_confirmed=!0,b('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){b("session ended"),this._end_time=new Date,this._close(),b('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){b("session failed"),b('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),b('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){b("session onhold"),this._setLocalMediaStatus(),b('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){b("session onunhold"),this._setLocalMediaStatus(),b('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;b("session onmute"),this._setLocalMediaStatus(),b('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;b("session onunmute"),this._setLocalMediaStatus(),b('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==m.STATE_TERMINATED&&i!==m.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==m.STATE_ACTIVE&&i===m.STATE_ACTIVE&&(_('emit "active"'),this.emit("active"));var c=e.body,h=i===m.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),this._state===m.STATE_INIT&&(this._state=m.STATE_NOTIFY_WAIT);var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return m.STATE_PENDING;case"active":return m.STATE_ACTIVE;case"terminated":return m.STATE_TERMINATED;case"init":return m.STATE_INIT;case"notify_wait":return m.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),A=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),b=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 b("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":b("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":b("- ".concat(i,": NOT SHOWN"));break;default:b("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:A,SWS:b,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:Ae,lr_param:be,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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&&u('":"')),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 I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=A();null!==s;)r.push(s),s=A();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=A();null!==s;)r.push(s),s=A();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),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 D(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"="')),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&&u('"("')),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,l;return s=i,l=i,null!==(e=b())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),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&&u('"<"')),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&&u('","')),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 B(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),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())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),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 W(){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 Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=A()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=A())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"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&&u('"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,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(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],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function At(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function bt(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=A()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=A()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=A()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=bn())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&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 Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),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,a;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&&(a=e,e=void(jn.port=parseInt(a.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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=A());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=A());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;b("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new A("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new A("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;b("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var A=E.value;o.removeTrack(A)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};b('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};b("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(b("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(b("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(b("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};b("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(b('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(b("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};b("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};b("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(b("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:f.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(b("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:f.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;b("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:f.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;b("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 C(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 b("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(b("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};b('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){b("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){b("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||(b("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(b("_isReadyToReOffer() | session not established yet"),!1):(b("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(b("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(b("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(b("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),b('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(b("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 b('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};b('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(b(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(b(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;b("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=p.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 b("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){R(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;b("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=p.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 b("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){R(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;b("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};b('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(b("receiveRefer()"),!e.refer_to)return b("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return b("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);b('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(b("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;b("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){b("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,b('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(b("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void b(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){b("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};b('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};b('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};b('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};b('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),R('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]:{};b("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};b('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};b('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){b("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){b("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!==w.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){b("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){b("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(b("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){b("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){b("session connecting"),b('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){b("session progress"),b('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){b("session accepted"),this._start_time=new Date,b('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){b("session confirmed"),this._is_confirmed=!0,b('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){b("session ended"),this._end_time=new Date,this._close(),b('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){b("session failed"),b('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),b('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){b("session onhold"),this._setLocalMediaStatus(),b('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){b("session onunhold"),this._setLocalMediaStatus(),b('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;b("session onmute"),this._setLocalMediaStatus(),b('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;b("session onunmute"),this._setLocalMediaStatus(),b('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t),this.emit("newSubscriber")}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==m.STATE_TERMINATED&&i!==m.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==m.STATE_ACTIVE&&i===m.STATE_ACTIVE&&(_('emit "active"'),this.emit("active"));var c=e.body,h=i===m.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),this._state===m.STATE_INIT&&(this._state=m.STATE_NOTIFY_WAIT);var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return m.STATE_PENDING;case"active":return m.STATE_ACTIVE;case"terminated":return m.STATE_TERMINATED;case"init":return m.STATE_INIT;case"notify_wait":return m.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),A=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),b=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 b("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":b("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":b("- ".concat(i,": NOT SHOWN"));break;default:b("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index e8ea4e545..cac47faab 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -216,6 +216,9 @@ module.exports = class Subscriber extends EventEmitter { this._params.route_set = route_set; } + + // Тo wait for a response to the initial subscribe, and then send the next subscribe. + this.emit('newSubscriber'); } // Check expires value. From c82707a61ac13689e9a3f29d3898c070926a8a5e Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 8 Jun 2021 11:01:02 +0300 Subject: [PATCH 42/70] removed non ascii comment --- dist/jssip.js | 2 +- lib/Subscriber.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index edb31da2b..3a20771ee 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22918,7 +22918,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (route_set.length > 0) { this._params.route_set = route_set; - } // Тo wait for a response to the initial subscribe, and then send the next subscribe. + } // To wait for a response to the initial subscribe this.emit('newSubscriber'); diff --git a/lib/Subscriber.js b/lib/Subscriber.js index cac47faab..97b573930 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -217,7 +217,7 @@ module.exports = class Subscriber extends EventEmitter this._params.route_set = route_set; } - // Тo wait for a response to the initial subscribe, and then send the next subscribe. + // To wait for a response to the initial subscribe this.emit('newSubscriber'); } From be3c82c2d19212dc1d2f79c82012a9570cb2fd95 Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 9 Jun 2021 13:37:20 +0300 Subject: [PATCH 43/70] subscriber: event pending --- dist/jssip.js | 12 ++++++++++-- dist/jssip.min.js | 2 +- lib/Subscriber.js | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 3a20771ee..38daa7f69 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22921,7 +22921,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } // To wait for a response to the initial subscribe - this.emit('newSubscriber'); + debug('emit "initialSubscribeOK"'); + this.emit('initialSubscribeOK'); } // Check expires value. @@ -23020,7 +23021,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } - if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { + if (prev_state !== C.STATE_PENDING && new_state === C.STATE_PENDING) { + debug('emit "pending"'); + this.emit('pending'); + } else if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { debug('emit "active"'); this.emit('active'); } @@ -23063,6 +23067,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (this._state === C.STATE_INIT) { this._state = C.STATE_NOTIFY_WAIT; + } else if (this._params.to_tag === null) { + // Although some notifiers accept this, + // it will be right to wait the event 'initialSubscribeOK' or 'active' + debugerror('sending subsequent subscribe before OK response to initial subscribe'); } var headers = this._headers.slice(); diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 31dd82660..5915e3cba 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:A,SWS:b,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:Ae,lr_param:be,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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&&u('":"')),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 I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=A();null!==s;)r.push(s),s=A();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=A();null!==s;)r.push(s),s=A();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),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 D(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"="')),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&&u('"("')),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,l;return s=i,l=i,null!==(e=b())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),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&&u('"<"')),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&&u('","')),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 B(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),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())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),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 W(){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 Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=A()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=A())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"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&&u('"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,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(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],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function At(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function bt(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=A()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=A()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=A()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=bn())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&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 Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),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,a;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&&(a=e,e=void(jn.port=parseInt(a.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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=A());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=A());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;b("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new A("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new A("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;b("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var A=E.value;o.removeTrack(A)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};b('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};b("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(b("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(b("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(b("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};b("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(b('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(b("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};b("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};b("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(b("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:f.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(b("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:f.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;b("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:f.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;b("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 C(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 b("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(b("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};b('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){b("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){b("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||(b("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(b("_isReadyToReOffer() | session not established yet"),!1):(b("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(b("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(b("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(b("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),b('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(b("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 b('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};b('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(b(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(b(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;b("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=p.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 b("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){R(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;b("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=p.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 b("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){R(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;b("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};b('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(b("receiveRefer()"),!e.refer_to)return b("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return b("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);b('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(b("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;b("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){b("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,b('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(b("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void b(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){b("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};b('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};b('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};b('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};b('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),R('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]:{};b("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};b('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};b('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){b("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){b("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!==w.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){b("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){b("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(b("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){b("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){b("session connecting"),b('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){b("session progress"),b('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){b("session accepted"),this._start_time=new Date,b('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){b("session confirmed"),this._is_confirmed=!0,b('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){b("session ended"),this._end_time=new Date,this._close(),b('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){b("session failed"),b('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),b('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){b("session onhold"),this._setLocalMediaStatus(),b('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){b("session onunhold"),this._setLocalMediaStatus(),b('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;b("session onmute"),this._setLocalMediaStatus(),b('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;b("session onunmute"),this._setLocalMediaStatus(),b('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t),this.emit("newSubscriber")}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==m.STATE_TERMINATED&&i!==m.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==m.STATE_ACTIVE&&i===m.STATE_ACTIVE&&(_('emit "active"'),this.emit("active"));var c=e.body,h=i===m.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),this._state===m.STATE_INIT&&(this._state=m.STATE_NOTIFY_WAIT);var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return m.STATE_PENDING;case"active":return m.STATE_ACTIVE;case"terminated":return m.STATE_TERMINATED;case"init":return m.STATE_INIT;case"notify_wait":return m.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),A=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),b=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 b("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":b("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":b("- ".concat(i,": NOT SHOWN"));break;default:b("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t),_('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==m.STATE_TERMINATED&&i!==m.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==m.STATE_PENDING&&i===m.STATE_PENDING?(_('emit "pending"'),this.emit("pending")):o!==m.STATE_ACTIVE&&i===m.STATE_ACTIVE&&(_('emit "active"'),this.emit("active"));var c=e.body,h=i===m.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),this._state===m.STATE_INIT?this._state=m.STATE_NOTIFY_WAIT:null===this._params.to_tag&&p("sending subsequent subscribe before OK response to initial subscribe");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return m.STATE_PENDING;case"active":return m.STATE_ACTIVE;case"terminated":return m.STATE_TERMINATED;case"init":return m.STATE_INIT;case"notify_wait":return m.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 97b573930..8204e967d 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -218,7 +218,8 @@ module.exports = class Subscriber extends EventEmitter } // To wait for a response to the initial subscribe - this.emit('newSubscriber'); + debug('emit "initialSubscribeOK"'); + this.emit('initialSubscribeOK'); } // Check expires value. @@ -330,7 +331,12 @@ module.exports = class Subscriber extends EventEmitter } } - if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) + if (prev_state !== C.STATE_PENDING && new_state === C.STATE_PENDING) + { + debug('emit "pending"'); + this.emit('pending'); + } + else if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { debug('emit "active"'); this.emit('active'); @@ -380,6 +386,13 @@ module.exports = class Subscriber extends EventEmitter { this._state = C.STATE_NOTIFY_WAIT; } + else if (this._params.to_tag === null) + { + // Although some notifiers accept this, + // it will be right to wait the event 'initialSubscribeOK' or 'active' + debugerror('sending subsequent subscribe before OK response to initial subscribe'); + } + const headers = this._headers.slice(); if (body) From 6347ede75481626e91d91f08daa4c46248023f5a Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 24 Jun 2021 17:33:52 +0300 Subject: [PATCH 44/70] using Dialog in subscriber --- dist/jssip.js | 211 ++++++++++++++++++++++------------------- dist/jssip.min.js | 2 +- lib/Subscriber.js | 234 +++++++++++++++++++++++++--------------------- 3 files changed, 242 insertions(+), 205 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 38daa7f69..5a5d1b67d 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -22729,6 +22729,8 @@ var SIPMessage = require('./SIPMessage'); var RequestSender = require('./RequestSender'); +var Dialog = require('./Dialog'); + var debug = require('debug')('JsSIP:Subscriber'); var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); @@ -22813,8 +22815,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._expires = expires; // Used to subscribe with body. - _this._content_type = contentType; - _this._is_first_notify_request = true; // Set subscriber dialog parameters. + _this._content_type = contentType; // Set initial SUBSCRIBE parameters. _this._params = Utils.cloneObject(params); @@ -22831,9 +22832,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } // Subscriber state. - _this._state = C.STATE_INIT; // Dialog id. - - _this._id = null; // To refresh subscription. + _this._state = C.STATE_INIT; + _this._dialog = null; + _this._request = null; // To refresh subscription. _this._expires_timer = null; _this._expires_timestamp = null; // To prevent duplicate un-subscribe sending. @@ -22877,21 +22878,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this; } - /** - * SUBSCRIBE transactions callbacks - */ - _createClass(Subscriber, [{ key: "C", get: function get() { return C; } - }, { - key: "onAuthenticated", - value: function onAuthenticated() { - this._params.cseq++; - } }, { key: "onRequestTimeout", value: function onRequestTimeout() { @@ -22902,50 +22894,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function onTransportError() { this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); } - }, { - key: "onReceiveResponse", - value: function onReceiveResponse(response) { - if (response.status_code >= 200 && response.status_code < 300) { - // Add dialog to stack dialogs table. - if (this._params.to_tag === null) { - this._params.to_tag = response.to_tag; - this._id = "".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag); - debug('added dialog id=', this._id); - - this._ua.newDialog(this); - - var route_set = response.getHeaders('record-route').reverse(); - - if (route_set.length > 0) { - this._params.route_set = route_set; - } // To wait for a response to the initial subscribe - - - debug('emit "initialSubscribeOK"'); - this.emit('initialSubscribeOK'); - } // Check expires value. - - - var expires_value = response.getHeader('expires'); - - if (expires_value !== 0 && !expires_value) { - debugerror('response without Expires header'); // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header. - // Use workaround expires value. - - expires_value = '900'; - } - - var expires = parseInt(expires_value); - - if (expires > 0) { - this._scheduleSubscribe(expires); - } - } else if (response.status_code === 401 || response.status_code === 407) { - this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); - } else if (response.status_code >= 300) { - this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); - } - } /** * Dialog callback. */ @@ -22997,10 +22945,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(200); - if (this._is_first_notify_request) { - this._is_first_notify_request = false; // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? - } - var new_state = this._stateStringToNumber(subs_state.state); var prev_state = this._state; @@ -23067,23 +23011,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (this._state === C.STATE_INIT) { this._state = C.STATE_NOTIFY_WAIT; - } else if (this._params.to_tag === null) { - // Although some notifiers accept this, - // it will be right to wait the event 'initialSubscribeOK' or 'active' - debugerror('sending subsequent subscribe before OK response to initial subscribe'); - } - - var headers = this._headers.slice(); - - if (body) { - if (!this._content_type) { - throw new TypeError('content_type is undefined'); - } - headers.push("Content-Type: ".concat(this._content_type)); + this._sendInitialSubscribe(body); + } else { + this._sendSubsequentSubscribe(body, this._headers); } - - this._send(body, headers); } /** * terminate. @@ -23110,7 +23042,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return s.startsWith('Expires') ? 'Expires: 0' : s; }); - this._send(body, headers); // Waiting for the final notify for a while. + this._sendSubsequentSubscribe(body, headers); // Waiting for the final notify for a while. var final_notify_timeout = 30000; @@ -23134,12 +23066,110 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "id", get: function get() { - return this._id; + return this._dialog ? this._dialog.id : null; } /** * Private API. */ + }, { + key: "_sendInitialSubscribe", + value: function _sendInitialSubscribe(body) { + var _this3 = this; + + var headers = this._headers.slice(); + + if (body) { + if (!this._content_type) { + throw new TypeError('content_type is undefined'); + } + + headers.push("Content-Type: ".concat(this._content_type)); + } + + this._request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); + var request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout: function onRequestTimeout() { + _this3.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this3.onTransportError(); + }, + onAuthenticated: function onAuthenticated(request) { + _this3._request = request; + }, + onReceiveResponse: function onReceiveResponse(response) { + _this3._receiveSubscribeResponse(response); + } + }); + request_sender.send(); + } + }, { + key: "_receiveSubscribeResponse", + value: function _receiveSubscribeResponse(response) { + if (response.status_code >= 200 && response.status_code < 300) { + // Create dialog + if (this._dialog === null) { + var dialog = new Dialog(this, response, 'UAC'); + + if (dialog.error) { + // OK response without Contact + debug(dialog.error); + + this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); + + return; + } + + this._dialog = dialog; // After the event dialog created. + + debug('emit "initialSubscribeOK"'); + this.emit('initialSubscribeOK'); + } // Check expires value. + + + var expires_value = response.getHeader('expires'); + + if (expires_value !== 0 && !expires_value) { + debugerror('response without Expires header'); // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header. + // Use workaround expires value. + + expires_value = '900'; + } + + var expires = parseInt(expires_value); + + if (expires > 0) { + this._scheduleSubscribe(expires); + } + } else if (response.status_code === 401 || response.status_code === 407) { + this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); + } else if (response.status_code >= 300) { + this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); + } + } + }, { + key: "_sendSubsequentSubscribe", + value: function _sendSubsequentSubscribe(body, headers) { + if (!this._dialog) { + debugerror('sending subsequent subscribe before OK response to initial subscribe'); + throw new Error('not received final response to initial SUBSCRIBE'); + } + + if (body) { + if (!this._content_type) { + throw new TypeError('content_type is undefined'); + } + + headers = headers.slice(); + headers.push("Content-Type: ".concat(this._content_type)); + } + + this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { + body: body, + extraHeaders: headers + }); + } }, { key: "_dialogTerminated", value: function _dialogTerminated(terminationCode) { @@ -23157,37 +23187,26 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { clearTimeout(this._expires_timer); clearTimeout(this._unsubscribe_timeout_timer); - if (this._id) { - debug('removed dialog id=', this.id); - - this._ua.destroyDialog(this); + if (this._dialog) { + this._dialog.terminate(); } debug("emit \"terminated\" code=".concat(terminationCode)); this.emit('terminated', terminationCode, reason, retryAfter); } - }, { - key: "_send", - value: function _send(body, headers) { - this._params.cseq++; // Create & send request. - - var request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); - var requestSender = new RequestSender(this._ua, request, this); - requestSender.send(); - } }, { key: "_scheduleSubscribe", value: function _scheduleSubscribe(expires) { - var _this3 = this; + var _this4 = this; var timeout = expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; this._expires_timestamp = new Date().getTime() + expires * 1000; debug("next SUBSCRIBE will be sent in ".concat(Math.floor(timeout / 1000), " sec")); clearTimeout(this._expires_timer); this._expires_timer = setTimeout(function () { - _this3._expires_timer = null; + _this4._expires_timer = null; - _this3._send(null, _this3._headers); + _this4._sendSubsequentSubscribe(null, _this4._headers); }, timeout); } }, { @@ -23226,7 +23245,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return Subscriber; }(EventEmitter); -},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ +},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ "use strict"; var T1 = 500, diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 5915e3cba..c47850912 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._params.to_tag){this._params.to_tag=e.to_tag,this._id="".concat(this._params.call_id).concat(this._params.from_tag).concat(this._params.to_tag),_("added dialog id=",this._id),this._ua.newDialog(this);var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t),_('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(p("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return p("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return p("missed Event header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return p("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return p("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(m.RECEIVE_BAD_NOTIFY);e.reply(200),this._is_first_notify_request&&(this._is_first_notify_request=!1);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==m.STATE_TERMINATED&&i!==m.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(_("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==m.STATE_PENDING&&i===m.STATE_PENDING?(_('emit "pending"'),this.emit("pending")):o!==m.STATE_ACTIVE&&i===m.STATE_ACTIVE&&(_('emit "active"'),this.emit("active"));var c=e.body,h=i===m.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");_('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,v=void 0;s.params&&void 0!==s.params["retry-after"]&&(v=parseInt(s.params["retry-after"])),this._dialogTerminated(m.RECEIVE_FINAL_NOTIFY,d,v)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;_("subscribe()"),this._state===m.STATE_INIT?this._state=m.STATE_NOTIFY_WAIT:null===this._params.to_tag&&p("sending subsequent subscribe before OK response to initial subscribe");var t=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");t.push("Content-Type: ".concat(this._content_type))}this._send(e,t)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("terminate()"),this._send_unsubscribe)p("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._send(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(m.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._id&&(_("removed dialog id=",this.id),this._ua.destroyDialog(this)),_('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_send",value:function(e,t){this._params.cseq++;var n=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,n,this).send()}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,_("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._send(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return m.STATE_PENDING;case"active":return m.STATE_ACTIVE;case"terminated":return m.STATE_TERMINATED;case"init":return m.STATE_INIT;case"notify_wait":return m.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._sendSubsequentSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e){var t=this,n=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");n.push("Content-Type: ".concat(this._content_type))}this._request=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,n,e),new d(this._ua,this._request,{onRequestTimeout:function(){t.onRequestTimeout()},onTransportError:function(){t.onTransportError()},onAuthenticated:function(e){t._request=e},onReceiveResponse:function(e){t._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return p(t.error),void this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE);this._dialog=t,p('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&this._dialog.terminate(),p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 8204e967d..b7b00e19d 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -4,6 +4,7 @@ const Utils = require('./Utils'); const Grammar = require('./Grammar'); const SIPMessage = require('./SIPMessage'); const RequestSender = require('./RequestSender'); +const Dialog = require('./Dialog'); const debug = require('debug')('JsSIP:Subscriber'); const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); @@ -99,9 +100,7 @@ module.exports = class Subscriber extends EventEmitter // Used to subscribe with body. this._content_type = contentType; - this._is_first_notify_request = true; - - // Set subscriber dialog parameters. + // Set initial SUBSCRIBE parameters. this._params = Utils.cloneObject(params); if (!this._params.from_uri) @@ -122,8 +121,8 @@ module.exports = class Subscriber extends EventEmitter // Subscriber state. this._state = C.STATE_INIT; - // Dialog id. - this._id = null; + this._dialog = null; + this._request = null; // To refresh subscription. this._expires_timer = null; @@ -179,14 +178,6 @@ module.exports = class Subscriber extends EventEmitter } } - /** - * SUBSCRIBE transactions callbacks - */ - onAuthenticated() - { - this._params.cseq++; - } - onRequestTimeout() { this._dialogTerminated(C.SUBSCRIBE_RESPONSE_TIMEOUT); @@ -197,60 +188,6 @@ module.exports = class Subscriber extends EventEmitter this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); } - onReceiveResponse(response) - { - if (response.status_code >= 200 && response.status_code < 300) - { - // Add dialog to stack dialogs table. - if (this._params.to_tag === null) - { - this._params.to_tag = response.to_tag; - this._id = `${this._params.call_id}${this._params.from_tag}${this._params.to_tag}`; - - debug('added dialog id=', this._id); - this._ua.newDialog(this); - - const route_set = response.getHeaders('record-route').reverse(); - - if (route_set.length > 0) - { - this._params.route_set = route_set; - } - - // To wait for a response to the initial subscribe - debug('emit "initialSubscribeOK"'); - this.emit('initialSubscribeOK'); - } - - // Check expires value. - let expires_value = response.getHeader('expires'); - - if (expires_value !== 0 && !expires_value) - { - debugerror('response without Expires header'); - - // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header. - // Use workaround expires value. - expires_value = '900'; - } - - const expires = parseInt(expires_value); - - if (expires > 0) - { - this._scheduleSubscribe(expires); - } - } - else if (response.status_code === 401 || response.status_code === 407) - { - this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); - } - else if (response.status_code >= 300) - { - this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); - } - } - /** * Dialog callback. */ @@ -302,12 +239,6 @@ module.exports = class Subscriber extends EventEmitter request.reply(200); - if (this._is_first_notify_request) - { - this._is_first_notify_request = false; - // TODO: see RFC 6665 4.4.1. If route_set should be updated here ? - } - const new_state = this._stateStringToNumber(subs_state.state); const prev_state = this._state; @@ -385,26 +316,12 @@ module.exports = class Subscriber extends EventEmitter if (this._state === C.STATE_INIT) { this._state = C.STATE_NOTIFY_WAIT; + this._sendInitialSubscribe(body); } - else if (this._params.to_tag === null) - { - // Although some notifiers accept this, - // it will be right to wait the event 'initialSubscribeOK' or 'active' - debugerror('sending subsequent subscribe before OK response to initial subscribe'); - } - - const headers = this._headers.slice(); - - if (body) + else { - if (!this._content_type) - { - throw new TypeError('content_type is undefined'); - } - headers.push(`Content-Type: ${this._content_type}`); + this._sendSubsequentSubscribe(body, this._headers); } - - this._send(body, headers); } /** @@ -431,7 +348,7 @@ module.exports = class Subscriber extends EventEmitter return s.startsWith('Expires') ? 'Expires: 0' : s; }); - this._send(body, headers); + this._sendSubsequentSubscribe(body, headers); // Waiting for the final notify for a while. const final_notify_timeout = 30000; @@ -455,12 +372,126 @@ module.exports = class Subscriber extends EventEmitter */ get id() { - return this._id; + return this._dialog ? this._dialog.id : null; } /** * Private API. */ + _sendInitialSubscribe(body) + { + const headers = this._headers.slice(); + + if (body) + { + if (!this._content_type) + { + throw new TypeError('content_type is undefined'); + } + headers.push(`Content-Type: ${this._content_type}`); + } + + this._request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, + this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); + + const request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout : () => + { + this.onRequestTimeout(); + }, + onTransportError : () => + { + this.onTransportError(); + }, + onAuthenticated : (request) => + { + this._request = request; + }, + onReceiveResponse : (response) => + { + this._receiveSubscribeResponse(response); + } + }); + + request_sender.send(); + } + + _receiveSubscribeResponse(response) + { + if (response.status_code >= 200 && response.status_code < 300) + { + // Create dialog + if (this._dialog === null) + { + const dialog = new Dialog(this, response, 'UAC'); + + if (dialog.error) + { + // OK response without Contact + debug(dialog.error); + this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); + + return; + } + + this._dialog = dialog; + + // After the event dialog created. + debug('emit "initialSubscribeOK"'); + this.emit('initialSubscribeOK'); + } + + // Check expires value. + let expires_value = response.getHeader('expires'); + + if (expires_value !== 0 && !expires_value) + { + debugerror('response without Expires header'); + + // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header. + // Use workaround expires value. + expires_value = '900'; + } + + const expires = parseInt(expires_value); + + if (expires > 0) + { + this._scheduleSubscribe(expires); + } + } + else if (response.status_code === 401 || response.status_code === 407) + { + this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); + } + else if (response.status_code >= 300) + { + this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); + } + } + + _sendSubsequentSubscribe(body, headers) + { + if (!this._dialog) + { + debugerror('sending subsequent subscribe before OK response to initial subscribe'); + throw new Error('not received final response to initial SUBSCRIBE'); + } + + if (body) + { + if (!this._content_type) + { + throw new TypeError('content_type is undefined'); + } + + headers = headers.slice(); + headers.push(`Content-Type: ${this._content_type}`); + } + + this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { body, extraHeaders: headers }); + } + _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) { // To prevent duplicate emit terminated event. @@ -476,28 +507,15 @@ module.exports = class Subscriber extends EventEmitter clearTimeout(this._expires_timer); clearTimeout(this._unsubscribe_timeout_timer); - if (this._id) + if (this._dialog) { - debug('removed dialog id=', this.id); - this._ua.destroyDialog(this); + this._dialog.terminate(); } debug(`emit "terminated" code=${terminationCode}`); this.emit('terminated', terminationCode, reason, retryAfter); } - _send(body, headers) - { - this._params.cseq++; - - // Create & send request. - const request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, - this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); - const requestSender = new RequestSender(this._ua, request, this); - - requestSender.send(); - } - _scheduleSubscribe(expires) { const timeout = expires >= 140 ? (expires * 1000 / 2) @@ -511,7 +529,7 @@ module.exports = class Subscriber extends EventEmitter this._expires_timer = setTimeout(() => { this._expires_timer = null; - this._send(null, this._headers); + this._sendSubsequentSubscribe(null, this._headers); }, timeout); } From f234314270418e41054f73a0e46254ebff46c918 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 24 Jun 2021 18:09:50 +0300 Subject: [PATCH 45/70] subscriber dialog.sendRequest added event handlers --- dist/jssip.js | 25 ++++++++++++++++++++----- dist/jssip.min.js | 2 +- lib/Notifier.js | 1 + lib/Subscriber.js | 21 +++++++++++++++++++-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 5a5d1b67d..6e6fc691b 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16618,6 +16618,8 @@ var SIPMessage = require('./SIPMessage'); var RequestSender = require('./RequestSender'); +var Dialog = require('./Dialog'); + var debug = require('debug')('JsSIP:Notifier'); var debugerror = require('debug')('JsSIP:ERROR:Notifier'); @@ -17018,7 +17020,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return Notifier; }(EventEmitter); -},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ +},{"./Constants":2,"./Dialog":3,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } @@ -23151,6 +23153,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_sendSubsequentSubscribe", value: function _sendSubsequentSubscribe(body, headers) { + var _this4 = this; + if (!this._dialog) { debugerror('sending subsequent subscribe before OK response to initial subscribe'); throw new Error('not received final response to initial SUBSCRIBE'); @@ -23167,7 +23171,18 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { body: body, - extraHeaders: headers + extraHeaders: headers, + eventHandlers: { + onRequestTimeout: function onRequestTimeout() { + _this4.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this4.onTransportError(); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this4._receiveSubscribeResponse(response); + } + } }); } }, { @@ -23197,16 +23212,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_scheduleSubscribe", value: function _scheduleSubscribe(expires) { - var _this4 = this; + var _this5 = this; var timeout = expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; this._expires_timestamp = new Date().getTime() + expires * 1000; debug("next SUBSCRIBE will be sent in ".concat(Math.floor(timeout / 1000), " sec")); clearTimeout(this._expires_timer); this._expires_timer = setTimeout(function () { - _this4._expires_timer = null; + _this5._expires_timer = null; - _this4._sendSubsequentSubscribe(null, _this4._headers); + _this5._sendSubsequentSubscribe(null, _this5._headers); }, timeout); } }, { diff --git a/dist/jssip.min.js b/dist/jssip.min.js index c47850912..a8875afa5 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._sendSubsequentSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e){var t=this,n=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");n.push("Content-Type: ".concat(this._content_type))}this._request=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,n,e),new d(this._ua,this._request,{onRequestTimeout:function(){t.onRequestTimeout()},onTransportError:function(){t.onTransportError()},onAuthenticated:function(e){t._request=e},onReceiveResponse:function(e){t._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return p(t.error),void this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE);this._dialog=t,p('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&this._dialog.terminate(),p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Dialog":3,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._sendSubsequentSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e){var t=this,n=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");n.push("Content-Type: ".concat(this._content_type))}this._request=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,n,e),new d(this._ua,this._request,{onRequestTimeout:function(){t.onRequestTimeout()},onTransportError:function(){t.onTransportError()},onAuthenticated:function(e){t._request=e},onReceiveResponse:function(e){t._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return p(t.error),void this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE);this._dialog=t,p('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onReceiveResponse:function(e){n._receiveSubscribeResponse(e)}}})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&this._dialog.terminate(),p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 225a16d2d..36fce5171 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -3,6 +3,7 @@ const JsSIP_C = require('./Constants'); const Utils = require('./Utils'); const SIPMessage = require('./SIPMessage'); const RequestSender = require('./RequestSender'); +const Dialog = require('./Dialog'); const debug = require('debug')('JsSIP:Notifier'); const debugerror = require('debug')('JsSIP:ERROR:Notifier'); diff --git a/lib/Subscriber.js b/lib/Subscriber.js index b7b00e19d..01f5e43cf 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -484,12 +484,29 @@ module.exports = class Subscriber extends EventEmitter { throw new TypeError('content_type is undefined'); } - + headers = headers.slice(); headers.push(`Content-Type: ${this._content_type}`); } - this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { body, extraHeaders: headers }); + this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { + body, + extraHeaders : headers, + eventHandlers : { + onRequestTimeout : () => + { + this.onRequestTimeout(); + }, + onTransportError : () => + { + this.onTransportError(); + }, + onReceiveResponse : (response) => + { + this._receiveSubscribeResponse(response); + } + } + }); } _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) From 4a551ee91ef0b802ea1287e4076025903a15edf5 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 24 Jun 2021 18:31:26 +0300 Subject: [PATCH 46/70] fixed: sendRequest handler names --- dist/jssip.js | 8 +++++++- dist/jssip.min.js | 2 +- lib/Subscriber.js | 12 ++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 6e6fc691b..f334d50ab 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -23179,7 +23179,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { onTransportError: function onTransportError() { _this4.onTransportError(); }, - onReceiveResponse: function onReceiveResponse(response) { + onSuccessResponse: function onSuccessResponse(response) { + _this4._receiveSubscribeResponse(response); + }, + onErrorResponse: function onErrorResponse(response) { + _this4._receiveSubscribeResponse(response); + }, + onDialogError: function onDialogError(response) { _this4._receiveSubscribeResponse(response); } } diff --git a/dist/jssip.min.js b/dist/jssip.min.js index a8875afa5..539882fc9 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Dialog":3,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._sendSubsequentSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e){var t=this,n=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");n.push("Content-Type: ".concat(this._content_type))}this._request=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,n,e),new d(this._ua,this._request,{onRequestTimeout:function(){t.onRequestTimeout()},onTransportError:function(){t.onTransportError()},onAuthenticated:function(e){t._request=e},onReceiveResponse:function(e){t._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return p(t.error),void this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE);this._dialog=t,p('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onReceiveResponse:function(e){n._receiveSubscribeResponse(e)}}})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&this._dialog.terminate(),p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Dialog":3,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._sendSubsequentSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e){var t=this,n=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");n.push("Content-Type: ".concat(this._content_type))}this._request=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,n,e),new d(this._ua,this._request,{onRequestTimeout:function(){t.onRequestTimeout()},onTransportError:function(){t.onTransportError()},onAuthenticated:function(e){t._request=e},onReceiveResponse:function(e){t._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return p(t.error),void this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE);this._dialog=t,p('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onSuccessResponse:function(e){n._receiveSubscribeResponse(e)},onErrorResponse:function(e){n._receiveSubscribeResponse(e)},onDialogError:function(e){n._receiveSubscribeResponse(e)}}})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&this._dialog.terminate(),p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 01f5e43cf..ab11ef892 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -501,10 +501,18 @@ module.exports = class Subscriber extends EventEmitter { this.onTransportError(); }, - onReceiveResponse : (response) => + onSuccessResponse : (response) => { this._receiveSubscribeResponse(response); - } + }, + onErrorResponse : (response) => + { + this._receiveSubscribeResponse(response); + }, + onDialogError : (response) => + { + this._receiveSubscribeResponse(response); + } } }); } From 7c1171b8b28124d3e151a99e5178952445c91a30 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 24 Jun 2021 20:28:50 +0300 Subject: [PATCH 47/70] use dialog in notifier --- dist/jssip.js | 146 +++++++++++++++++++--------------------------- dist/jssip.min.js | 2 +- lib/Notifier.js | 126 ++++++++++++++++----------------------- lib/Subscriber.js | 18 ++++-- 4 files changed, 124 insertions(+), 168 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index f334d50ab..5301e253d 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -16614,10 +16614,6 @@ var JsSIP_C = require('./Constants'); var Utils = require('./Utils'); -var SIPMessage = require('./SIPMessage'); - -var RequestSender = require('./RequestSender'); - var Dialog = require('./Dialog'); var debug = require('debug')('JsSIP:Notifier'); @@ -16687,17 +16683,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait. _this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; - _this._is_final_notify_sent = false; - _this._is_first_notify_response = true; // To prevent duplicate emit 'terminated'. + _this._is_final_notify_sent = false; // To prevent duplicate emit 'terminated'. _this._is_terminated = false; // Optional. Used to build terminated Subscription-State. _this._terminated_reason = null; _this._terminated_retry_after = null; // Custom session empty object for high level use. - _this.data = {}; // Dialog id. - - _this._id = null; + _this.data = {}; + _this._dialog = null; var eventName = subscribe.getHeader('event'); _this._content_type = contentType; _this._expires = parseInt(subscribe.getHeader('expires')); @@ -16721,32 +16715,28 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _this._target = subscribe.from.uri.user; - subscribe.to_tag = Utils.newTag(); // NOTIFY request params set according received SUBSCRIBE. + subscribe.to_tag = Utils.newTag(); // Create dialog for normal and fetch SUBSCRIBE - _this._params = { - from: subscribe.to, - from_tag: subscribe.to_tag, - to: subscribe.from, - to_tag: subscribe.from_tag, - call_id: subscribe.call_id, - cseq: Math.floor(Math.random() * 10000 + 1) - }; // For non-fetch subscribe add dialog. + var dialog = new Dialog(_assertThisInitialized(_this), subscribe, 'UAS'); - if (_this._expires > 0) { - // Dialog id. - _this._id = "".concat(_this._params.call_id).concat(_this._params.from_tag).concat(_this._params.to_tag); - debug('add dialog id=', _this._id); - - _this._ua.newDialog(_assertThisInitialized(_this)); // Set expires timer and time-stamp. + if (dialog.error) { + debugerror(dialog.error); + throw new Error('SUBSCRIBE missed Contact'); + } + _this._dialog = dialog; + if (_this._expires > 0) { + // Set expires timer and time-stamp. _this._setExpiresTimer(); } return _this; } /** - * NOTIFY transactions callbacks. + * Dialog callback. + * Called also for initial subscribe. + * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). */ @@ -16755,45 +16745,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { get: function get() { return C; } - }, { - key: "onAuthenticated", - value: function onAuthenticated() { - this._params.cseq++; - } - }, { - key: "onRequestTimeout", - value: function onRequestTimeout() { - this._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); - } - }, { - key: "onTransportError", - value: function onTransportError() { - this._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); - } - }, { - key: "onReceiveResponse", - value: function onReceiveResponse(response) { - if (response.status_code >= 200 && response.status_code < 300) { - if (this._is_first_notify_response) { - this._is_first_notify_response = false; - var route_set = response.getHeaders('record-route').reverse(); - - if (route_set.length > 0) { - this._params.route_set = route_set; - } - } - } else if (response.status_code === 401 || response.status_code === 407) { - this._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); - } else if (response.status_code >= 300) { - this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); - } - } - /** - * Dialog callback. - * Called also for initial subscribe. - * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). - */ - }, { key: "receiveRequest", value: function receiveRequest(request) { @@ -16862,6 +16813,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "notify", value: function notify() { + var _this2 = this; + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; debug('notify()'); // Prevent send notify after final notify. @@ -16898,11 +16851,32 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { headers.push("Content-Type: ".concat(this._content_type)); } - this._params.cseq++; // Create & send request. + if (!this._dialog) { + throw new Error('no dialog'); + } - var request = new SIPMessage.OutgoingRequest(JsSIP_C.NOTIFY, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); - var requestSender = new RequestSender(this._ua, request, this); - requestSender.send(); + this._dialog.sendRequest(JsSIP_C.NOTIFY, { + body: body, + extraHeaders: headers, + eventHandlers: { + onRequestTimeout: function onRequestTimeout() { + _this2._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); + }, + onTransportError: function onTransportError() { + _this2._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); + }, + onErrorResponse: function onErrorResponse(response) { + if (response.status_code === 401 || response.status_code === 407) { + _this2._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); + } else { + _this2._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); + } + }, + onDialogError: function onDialogError() { + _this2._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); + } + } + }); } /** * Terminate. (Send the final NOTIFY request). @@ -16943,7 +16917,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "id", get: function get() { - return this._id; + return this._dialog ? this._dialog.id : null; } /** * Private API @@ -16960,10 +16934,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._state = C.STATE_TERMINATED; clearTimeout(this._expires_timer); - if (this._id) { - debug('remove dialog id=', this._id); - - this._ua.destroyDialog(this); + if (this._dialog) { + this._dialog.terminate(); } var send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; @@ -16973,21 +16945,21 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_setExpiresTimer", value: function _setExpiresTimer() { - var _this2 = this; + var _this3 = this; this._expires_timestamp = new Date().getTime() + this._expires * 1000; clearTimeout(this._expires_timer); this._expires_timer = setTimeout(function () { - if (_this2._is_final_notify_sent) { + if (_this3._is_final_notify_sent) { return; } - _this2._terminated_reason = 'timeout'; - _this2._is_final_notify_sent = true; + _this3._terminated_reason = 'timeout'; + _this3._is_final_notify_sent = true; - _this2.notify(); + _this3.notify(); - _this2._dialogTerminated(C.SUBSCRIPTION_EXPIRED); + _this3._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this._expires * 1000); } }, { @@ -17020,7 +16992,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return Notifier; }(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ +},{"./Constants":2,"./Dialog":3,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } @@ -23014,7 +22986,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (this._state === C.STATE_INIT) { this._state = C.STATE_NOTIFY_WAIT; - this._sendInitialSubscribe(body); + this._sendInitialSubscribe(body, this._headers); } else { this._sendSubsequentSubscribe(body, this._headers); } @@ -23044,7 +23016,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return s.startsWith('Expires') ? 'Expires: 0' : s; }); - this._sendSubsequentSubscribe(body, headers); // Waiting for the final notify for a while. + if (!this._dialog) { + // Fetch-SUBSCRIBE is the first and last one. + this._sendInitialSubscribe(body, headers); + } else { + this._sendSubsequentSubscribe(body, headers); + } // Waiting for the final notify for a while. var final_notify_timeout = 30000; @@ -23076,16 +23053,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_sendInitialSubscribe", - value: function _sendInitialSubscribe(body) { + value: function _sendInitialSubscribe(body, headers) { var _this3 = this; - var headers = this._headers.slice(); - if (body) { if (!this._content_type) { throw new TypeError('content_type is undefined'); } + headers = headers.slice(); headers.push("Content-Type: ".concat(this._content_type)); } diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 539882fc9..43acec3c2 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag(),s._params={from:t.to,from_tag:t.to_tag,to:t.from,to_tag:t.from_tag,call_id:t.call_id,cseq:Math.floor(1e4*Math.random()+1)},s._expires>0&&(s._id="".concat(s._params.call_id).concat(s._params.from_tag).concat(s._params.to_tag),_("add dialog id=",s._id),s._ua.newDialog(l(s)),s._setExpiresTimer()),s}return t=v,r=[{key:"C",get:function(){return m}}],(n=[{key:"C",get:function(){return m}},{key:"onAuthenticated",value:function(){this._params.cseq++}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(m.NOTIFY_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(m.NOTIFY_TRANSPORT_ERROR)}},{key:"onReceiveResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(this._is_first_notify_response){this._is_first_notify_response=!1;var t=e.getHeaders("record-route").reverse();t.length>0&&(this._params.route_set=t)}}else 401===e.status_code||407===e.status_code?this._dialogTerminated(m.NOTIFY_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(m.NOTIFY_NON_OK_RESPONSE)}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&_("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),_('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(m.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){_("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){_("setActiveState()"),this._state===m.STATE_PENDING&&(this._state=m.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(_("notify()"),this._is_final_notify_sent)p("final notify has sent");else{var t=this._stateNumberToString(this._state);if(this._state!==m.STATE_TERMINATED){var n=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);n<0&&(n=0),t+=";expires=".concat(n)}else this._terminated_reason&&(t+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(t+=";retry-after=".concat(this._terminated_retry_after));var r=this._headers.slice();r.push("Subscription-State: ".concat(t)),e&&r.push("Content-Type: ".concat(this._content_type)),this._params.cseq++;var s=new f.OutgoingRequest(c.NOTIFY,this._ua.normalizeTarget(this._target),this._ua,this._params,r,e);new d(this._ua,s,this).send()}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;_("terminate()"),this._state=m.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(m.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._id}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=m.STATE_TERMINATED,clearTimeout(this._expires_timer),this._id&&(_("remove dialog id=",this._id),this._ua.destroyDialog(this));var t=e===m.SUBSCRIPTION_EXPIRED;_('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(m.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case m.STATE_PENDING:return"pending";case m.STATE_ACTIVE:return"active";case m.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),v}()},{"./Constants":2,"./Dialog":3,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._sendSubsequentSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e){var t=this,n=this._headers.slice();if(e){if(!this._content_type)throw new TypeError("content_type is undefined");n.push("Content-Type: ".concat(this._content_type))}this._request=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,n,e),new d(this._ua,this._request,{onRequestTimeout:function(){t.onRequestTimeout()},onTransportError:function(){t.onTransportError()},onAuthenticated:function(e){t._request=e},onReceiveResponse:function(e){t._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return p(t.error),void this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE);this._dialog=t,p('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onSuccessResponse:function(e){n._receiveSubscribeResponse(e)},onErrorResponse:function(e){n._receiveSubscribeResponse(e)},onDialogError:function(e){n._receiveSubscribeResponse(e)}}})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&this._dialog.terminate(),p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag();var v=new f(l(s),t,"UAS");if(v.error)throw _(v.error),new Error("SUBSCRIBE missed Contact");return s._dialog=v,s._expires>0&&s._setExpiresTimer(),s}return t=m,r=[{key:"C",get:function(){return p}}],(n=[{key:"C",get:function(){return p}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&d("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),d('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(p.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){d("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){d("setActiveState()"),this._state===p.STATE_PENDING&&(this._state=p.STATE_ACTIVE)}},{key:"notify",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(d("notify()"),this._is_final_notify_sent)_("final notify has sent");else{var n=this._stateNumberToString(this._state);if(this._state!==p.STATE_TERMINATED){var r=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);r<0&&(r=0),n+=";expires=".concat(r)}else this._terminated_reason&&(n+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(n+=";retry-after=".concat(this._terminated_retry_after));var s=this._headers.slice();if(s.push("Subscription-State: ".concat(n)),t&&s.push("Content-Type: ".concat(this._content_type)),!this._dialog)throw new Error("no dialog");this._dialog.sendRequest(c.NOTIFY,{body:t,extraHeaders:s,eventHandlers:{onRequestTimeout:function(){e._dialogTerminated(p.NOTIFY_RESPONSE_TIMEOUT)},onTransportError:function(){e._dialogTerminated(p.NOTIFY_TRANSPORT_ERROR)},onErrorResponse:function(t){401===t.status_code||407===t.status_code?e._dialogTerminated(p.NOTIFY_FAILED_AUTHENTICATION):e._dialogTerminated(p.NOTIFY_NON_OK_RESPONSE)},onDialogError:function(){e._dialogTerminated(p.NOTIFY_NON_OK_RESPONSE)}}})}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;d("terminate()"),this._state=p.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(p.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=p.STATE_TERMINATED,clearTimeout(this._expires_timer),this._dialog&&this._dialog.terminate();var t=e===p.SUBSCRIPTION_EXPIRED;d('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(p.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case p.STATE_PENDING:return"pending";case p.STATE_ACTIVE:return"active";case p.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),m}()},{"./Constants":2,"./Dialog":3,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e,this._headers)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._dialog?this._sendSubsequentSubscribe(t,n):this._sendInitialSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e,t){var n=this;if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._request=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e),new d(this._ua,this._request,{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onAuthenticated:function(e){n._request=e},onReceiveResponse:function(e){n._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return p(t.error),void this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE);this._dialog=t,p('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onSuccessResponse:function(e){n._receiveSubscribeResponse(e)},onErrorResponse:function(e){n._receiveSubscribeResponse(e)},onDialogError:function(e){n._receiveSubscribeResponse(e)}}})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&this._dialog.terminate(),p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index 36fce5171..e74bd0df5 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -1,8 +1,6 @@ const EventEmitter = require('events').EventEmitter; const JsSIP_C = require('./Constants'); const Utils = require('./Utils'); -const SIPMessage = require('./SIPMessage'); -const RequestSender = require('./RequestSender'); const Dialog = require('./Dialog'); const debug = require('debug')('JsSIP:Notifier'); const debugerror = require('debug')('JsSIP:ERROR:Notifier'); @@ -79,7 +77,6 @@ module.exports = class Notifier extends EventEmitter // Notifier state: pending, active, terminated. Not used: init, resp_wait. this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; this._is_final_notify_sent = false; - this._is_first_notify_response = true; // To prevent duplicate emit 'terminated'. this._is_terminated = false; @@ -91,8 +88,7 @@ module.exports = class Notifier extends EventEmitter // Custom session empty object for high level use. this.data = {}; - // Dialog id. - this._id = null; + this._dialog = null; const eventName = subscribe.getHeader('event'); @@ -118,71 +114,22 @@ module.exports = class Notifier extends EventEmitter this._target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); - // NOTIFY request params set according received SUBSCRIBE. - this._params = { - from : subscribe.to, - from_tag : subscribe.to_tag, - to : subscribe.from, - to_tag : subscribe.from_tag, - call_id : subscribe.call_id, - cseq : Math.floor((Math.random() * 10000) + 1) - }; - - // For non-fetch subscribe add dialog. - if (this._expires > 0) - { - // Dialog id. - this._id = `${this._params.call_id}${this._params.from_tag}${this._params.to_tag}`; - - debug('add dialog id=', this._id); - this._ua.newDialog(this); - - // Set expires timer and time-stamp. - this._setExpiresTimer(); - } - } - - /** - * NOTIFY transactions callbacks. - */ - onAuthenticated() - { - this._params.cseq++; - } - - onRequestTimeout() - { - this._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); - } + // Create dialog for normal and fetch SUBSCRIBE + const dialog = new Dialog(this, subscribe, 'UAS'); - onTransportError() - { - this._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); - } - - onReceiveResponse(response) - { - if (response.status_code >= 200 && response.status_code < 300) + if (dialog.error) { - if (this._is_first_notify_response) - { - this._is_first_notify_response = false; - - const route_set = response.getHeaders('record-route').reverse(); + debugerror(dialog.error); - if (route_set.length > 0) - { - this._params.route_set = route_set; - } - } - } - else if (response.status_code === 401 || response.status_code === 407) - { - this._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); + throw new Error('SUBSCRIBE missed Contact'); } - else if (response.status_code >= 300) + + this._dialog = dialog; + + if (this._expires > 0) { - this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); + // Set expires timer and time-stamp. + this._setExpiresTimer(); } } @@ -306,15 +253,41 @@ module.exports = class Notifier extends EventEmitter { headers.push(`Content-Type: ${this._content_type}`); } + + if (!this._dialog) + { + throw new Error('no dialog'); + } - this._params.cseq++; - - // Create & send request. - const request = new SIPMessage.OutgoingRequest(JsSIP_C.NOTIFY, - this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); - const requestSender = new RequestSender(this._ua, request, this); - - requestSender.send(); + this._dialog.sendRequest(JsSIP_C.NOTIFY, { + body, + extraHeaders : headers, + eventHandlers : { + onRequestTimeout : () => + { + this._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); + }, + onTransportError : () => + { + this._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); + }, + onErrorResponse : (response) => + { + if (response.status_code === 401 || response.status_code === 407) + { + this._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); + } + else + { + this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); + } + }, + onDialogError : () => + { + this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); + } + } + }); } /** @@ -351,7 +324,7 @@ module.exports = class Notifier extends EventEmitter */ get id() { - return this._id; + return this._dialog ? this._dialog.id : null; } /** @@ -368,10 +341,9 @@ module.exports = class Notifier extends EventEmitter this._state = C.STATE_TERMINATED; clearTimeout(this._expires_timer); - if (this._id) + if (this._dialog) { - debug('remove dialog id=', this._id); - this._ua.destroyDialog(this); + this._dialog.terminate(); } const send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; diff --git a/lib/Subscriber.js b/lib/Subscriber.js index ab11ef892..26c2f2e3b 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -316,7 +316,7 @@ module.exports = class Subscriber extends EventEmitter if (this._state === C.STATE_INIT) { this._state = C.STATE_NOTIFY_WAIT; - this._sendInitialSubscribe(body); + this._sendInitialSubscribe(body, this._headers); } else { @@ -348,7 +348,15 @@ module.exports = class Subscriber extends EventEmitter return s.startsWith('Expires') ? 'Expires: 0' : s; }); - this._sendSubsequentSubscribe(body, headers); + if (!this._dialog) + { + // Fetch-SUBSCRIBE is the first and last one. + this._sendInitialSubscribe(body, headers); + } + else + { + this._sendSubsequentSubscribe(body, headers); + } // Waiting for the final notify for a while. const final_notify_timeout = 30000; @@ -378,16 +386,16 @@ module.exports = class Subscriber extends EventEmitter /** * Private API. */ - _sendInitialSubscribe(body) + _sendInitialSubscribe(body, headers) { - const headers = this._headers.slice(); - if (body) { if (!this._content_type) { throw new TypeError('content_type is undefined'); } + + headers = headers.slice(); headers.push(`Content-Type: ${this._content_type}`); } From 7559919e71656d4600e8ba3e2da717be1ac96c79 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 24 Jun 2021 20:41:24 +0300 Subject: [PATCH 48/70] updated jssip.js and jssip.min.js to make push request looks better --- dist/jssip.js | 2841 +++++++++++++++------------------------------ dist/jssip.min.js | 4 +- 2 files changed, 942 insertions(+), 1903 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 5301e253d..d2cb750d2 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -1,5 +1,5 @@ /* - * JsSIP v3.7.6 + * JsSIP v3.7.11 * the Javascript SIP library * Copyright: 2012-2021 * Homepage: https://jssip.net @@ -9,7 +9,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -294,7 +294,7 @@ exports.load = function (dst, src) { } } }; -},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],2:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":26,"./Utils":27}],2:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -462,7 +462,7 @@ module.exports = { 604: 'Does Not Exist Anywhere', 606: 'Not Acceptable' }, - ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE', + 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, @@ -470,7 +470,7 @@ module.exports = { CONNECTION_RECOVERY_MAX_INTERVAL: 30, CONNECTION_RECOVERY_MIN_INTERVAL: 2 }; -},{"../package.json":40}],3:[function(require,module,exports){ +},{"../package.json":39}],3:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -479,6 +479,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var SIPMessage = require('./SIPMessage'); var JsSIP_C = require('./Constants'); @@ -489,8 +491,7 @@ var Dialog_RequestSender = require('./Dialog/RequestSender'); var Utils = require('./Utils'); -var debug = require('debug')('JsSIP:Dialog'); - +var logger = new Logger('Dialog'); var C = { // Dialog states. STATUS_EARLY: 1, @@ -498,6 +499,14 @@ var C = { }; // RFC 3261 12.1. module.exports = /*#__PURE__*/function () { + _createClass(Dialog, null, [{ + key: "C", + // Expose C object. + get: function get() { + return C; + } + }]); + function Dialog(owner, message, type) { var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; @@ -557,45 +566,14 @@ module.exports = /*#__PURE__*/function () { this._ua.newDialog(this); - debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); + logger.debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); } _createClass(Dialog, [{ - key: "id", - get: function get() { - return this._id; - } - }, { - key: "local_seqnum", - get: function get() { - return this._local_seqnum; - }, - set: function set(num) { - this._local_seqnum = num; - } - }, { - key: "owner", - get: function get() { - return this._owner; - } - }, { - key: "uac_pending_reply", - get: function get() { - return this._uac_pending_reply; - }, - set: function set(pending) { - this._uac_pending_reply = pending; - } - }, { - key: "uas_pending_reply", - get: function get() { - return this._uas_pending_reply; - } - }, { key: "update", value: function update(message, type) { this._state = C.STATUS_CONFIRMED; - debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); + logger.debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); if (type === 'UAC') { // RFC 3261 13.2.2.4. @@ -605,7 +583,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "terminate", value: function terminate() { - debug("dialog ".concat(this._id.toString(), " deleted")); + logger.debug("dialog ".concat(this._id.toString(), " deleted")); this._ua.destroyDialog(this); } @@ -736,17 +714,42 @@ module.exports = /*#__PURE__*/function () { return true; } - }], [{ - key: "C", - get: // Expose C object. - function get() { - return C; + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "local_seqnum", + get: function get() { + return this._local_seqnum; + }, + set: function set(num) { + this._local_seqnum = num; + } + }, { + key: "owner", + get: function get() { + return this._owner; + } + }, { + key: "uac_pending_reply", + get: function get() { + return this._uac_pending_reply; + }, + set: function set(pending) { + this._uac_pending_reply = pending; + } + }, { + key: "uas_pending_reply", + get: function get() { + return this._uas_pending_reply; } }]); return Dialog; }(); -},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,"debug":32}],4:[function(require,module,exports){ +},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":20,"./Transactions":23,"./Utils":27}],4:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -795,11 +798,6 @@ module.exports = /*#__PURE__*/function () { } _createClass(DialogRequestSender, [{ - key: "request", - get: function get() { - return this._request; - } - }, { key: "send", value: function send() { var _this = this; @@ -865,11 +863,16 @@ module.exports = /*#__PURE__*/function () { this._eventHandlers.onErrorResponse(response); } } + }, { + key: "request", + get: function get() { + return this._request; + } }]); return DialogRequestSender; }(); -},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(require,module,exports){ +},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":23}],5:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -878,13 +881,11 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Utils = require('./Utils'); - -var debug = require('debug')('JsSIP:DigestAuthentication'); +var Logger = require('./Logger'); -var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); +var Utils = require('./Utils'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('DigestAuthentication'); module.exports = /*#__PURE__*/function () { function DigestAuthentication(credentials) { @@ -917,7 +918,7 @@ module.exports = /*#__PURE__*/function () { return this._ha1; default: - debugerror('get() | cannot get "%s" parameter', parameter); + logger.warn('get() | cannot get "%s" parameter', parameter); return undefined; } } @@ -944,7 +945,7 @@ module.exports = /*#__PURE__*/function () { if (this._algorithm) { if (this._algorithm !== 'MD5') { - debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); + logger.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); return false; } } else { @@ -952,12 +953,12 @@ module.exports = /*#__PURE__*/function () { } if (!this._nonce) { - debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); + logger.warn('authenticate() | challenge without Digest nonce, authentication aborted'); return false; } if (!this._realm) { - debugerror('authenticate() | challenge without Digest realm, authentication aborted'); + logger.warn('authenticate() | challenge without Digest realm, authentication aborted'); return false; } // If no plain SIP password is provided. @@ -965,13 +966,13 @@ module.exports = /*#__PURE__*/function () { if (!this._credentials.password) { // If ha1 is not provided we cannot authenticate. if (!this._credentials.ha1) { - debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); + logger.warn('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); return false; } // If the realm does not match the stored realm we cannot authenticate. if (this._credentials.realm !== this._realm) { - debugerror('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); + logger.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm); return false; } } // 'qop' can contain a list of values (Array). Let's choose just one. @@ -984,7 +985,7 @@ module.exports = /*#__PURE__*/function () { this._qop = 'auth'; } else { // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. - debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); + logger.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); return false; } } else { @@ -1021,26 +1022,26 @@ module.exports = /*#__PURE__*/function () { // HA2 = MD5(A2) = MD5(method:digestURI). a2 = "".concat(this._method, ":").concat(this._uri); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + logger.debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2)); } else if (this._qop === 'auth-int') { // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)). a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : '')); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + logger.debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2)); } else if (this._qop === null) { // HA2 = MD5(A2) = MD5(method:digestURI). a2 = "".concat(this._method, ":").concat(this._uri); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). + logger.debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2)); } - debug('authenticate() | response generated'); + logger.debug('authenticate() | response generated'); return true; } /** @@ -1079,7 +1080,7 @@ module.exports = /*#__PURE__*/function () { return DigestAuthentication; }(); -},{"./Utils":28,"debug":32}],6:[function(require,module,exports){ +},{"./Logger":9,"./Utils":27}],6:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -1098,7 +1099,7 @@ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } @@ -16096,7 +16097,7 @@ module.exports = function () { result.SyntaxError.prototype = Error.prototype; return result; }(); -},{"./NameAddrHeader":10,"./URI":27}],8:[function(require,module,exports){ +},{"./NameAddrHeader":11,"./URI":26}],8:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -16145,7 +16146,61 @@ module.exports = { } }; -},{"../package.json":40,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":26,"./URI":27,"./Utils":28,"./WebSocketInterface":29,"debug":32}],9:[function(require,module,exports){ +},{"../package.json":39,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":11,"./UA":25,"./URI":26,"./Utils":27,"./WebSocketInterface":28,"debug":31}],9:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var debug = require('debug'); + +var APP_NAME = 'JsSIP'; + +module.exports = /*#__PURE__*/function () { + function Logger(prefix) { + _classCallCheck(this, Logger); + + if (prefix) { + this._debug = debug["default"]("".concat(APP_NAME, ":").concat(prefix)); + this._warn = debug["default"]("".concat(APP_NAME, ":WARN:").concat(prefix)); + this._error = debug["default"]("".concat(APP_NAME, ":ERROR:").concat(prefix)); + } else { + this._debug = debug["default"](APP_NAME); + this._warn = debug["default"]("".concat(APP_NAME, ":WARN")); + this._error = debug["default"]("".concat(APP_NAME, ":ERROR")); + } + /* eslint-disable no-console */ + + + this._debug.log = console.info.bind(console); + this._warn.log = console.warn.bind(console); + this._error.log = console.error.bind(console); + /* eslint-enable no-console */ + } + + _createClass(Logger, [{ + key: "debug", + get: function get() { + return this._debug; + } + }, { + key: "warn", + get: function get() { + return this._warn; + } + }, { + key: "error", + get: function get() { + return this._error; + } + }]); + + return Logger; +}(); +},{"debug":31}],10:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -16166,12 +16221,14 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); @@ -16182,7 +16239,7 @@ var RequestSender = require('./RequestSender'); var Exceptions = require('./Exceptions'); -var debug = require('debug')('JsSIP:Message'); +var logger = new Logger('Message'); module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(Message, _EventEmitter); @@ -16209,21 +16266,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Message, [{ - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { key: "send", value: function send(target, body) { var _this2 = this; @@ -16423,11 +16465,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_failed", value: function _failed(originator, response, cause) { - debug('MESSAGE failed'); + logger.debug('MESSAGE failed'); this._close(); - debug('emit "failed"'); + logger.debug('emit "failed"'); this.emit('failed', { originator: originator, response: response || null, @@ -16437,21 +16479,36 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_succeeded", value: function _succeeded(originator, response) { - debug('MESSAGE succeeded'); + logger.debug('MESSAGE succeeded'); this._close(); - debug('emit "succeeded"'); + logger.debug('emit "succeeded"'); this.emit('succeeded', { originator: originator, response: response }); } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } }]); return Message; }(EventEmitter); -},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],10:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27,"events":30}],11:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -16465,6 +16522,24 @@ var URI = require('./URI'); var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { + _createClass(NameAddrHeader, null, [{ + key: "parse", + + /** + * Parse the given string and returns a NameAddrHeader instance or undefined if + * it is an invalid NameAddrHeader. + */ + value: function parse(name_addr_header) { + name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); + + if (name_addr_header !== -1) { + return name_addr_header; + } else { + return undefined; + } + } + }]); + function NameAddrHeader(uri, display_name, parameters) { _classCallCheck(this, NameAddrHeader); @@ -16486,19 +16561,6 @@ module.exports = /*#__PURE__*/function () { } _createClass(NameAddrHeader, [{ - key: "uri", - get: function get() { - return this._uri; - } - }, { - key: "display_name", - get: function get() { - return this._display_name; - }, - set: function set(value) { - this._display_name = value === 0 ? '0' : value; - } - }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -16563,506 +16625,94 @@ module.exports = /*#__PURE__*/function () { return body; } - }], [{ - key: "parse", - value: - /** - * Parse the given string and returns a NameAddrHeader instance or undefined if - * it is an invalid NameAddrHeader. - */ - function parse(name_addr_header) { - name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); - - if (name_addr_header !== -1) { - return name_addr_header; - } else { - return undefined; - } + }, { + key: "uri", + get: function get() { + return this._uri; + } + }, { + key: "display_name", + get: function get() { + return this._display_name; + }, + set: function set(value) { + this._display_name = value === 0 ? '0' : value; } }]); return NameAddrHeader; }(); -},{"./Grammar":7,"./URI":27}],11:[function(require,module,exports){ +},{"./Grammar":7,"./URI":26}],12:[function(require,module,exports){ "use strict"; -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } +var Grammar = require('./Grammar'); -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +var SIPMessage = require('./SIPMessage'); -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } +var logger = new Logger('Parser'); +/** + * Parse SIP Message + */ -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } +exports.parseMessage = function (data, ua) { + var message; + var bodyStart; + var headerEnd = data.indexOf('\r\n'); -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + if (headerEnd === -1) { + logger.warn('parseMessage() | no CRLF found, not a SIP message'); + return; + } // Parse first line. Check if it is a Request or a Reply. -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + var firstLine = data.substring(0, headerEnd); + var parsed = Grammar.parse(firstLine, 'Request_Response'); -var EventEmitter = require('events').EventEmitter; + if (parsed === -1) { + logger.warn("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); + return; + } else if (!parsed.status_code) { + message = new SIPMessage.IncomingRequest(ua); + message.method = parsed.method; + message.ruri = parsed.uri; + } else { + message = new SIPMessage.IncomingResponse(); + message.status_code = parsed.status_code; + message.reason_phrase = parsed.reason_phrase; + } -var JsSIP_C = require('./Constants'); + message.data = data; + var headerStart = headerEnd + 2; + /* Loop over every line in data. Detect the end of each header and parse + * it or simply add to the headers collection. + */ -var Utils = require('./Utils'); + while (true) { + headerEnd = getHeader(data, headerStart); // The SIP message has normally finished. -var Dialog = require('./Dialog'); + if (headerEnd === -2) { + bodyStart = headerStart + 2; + break; + } // Data.indexOf returned -1 due to a malformed message. + else if (headerEnd === -1) { + logger.warn('parseMessage() | malformed message'); + return; + } -var debug = require('debug')('JsSIP:Notifier'); + parsed = parseHeader(message, data, headerStart, headerEnd); -var debugerror = require('debug')('JsSIP:ERROR:Notifier'); - -debugerror.log = console.warn.bind(console); -/** - * Termination codes. - */ - -var C = { - // Termination codes. - NOTIFY_RESPONSE_TIMEOUT: 0, - NOTIFY_TRANSPORT_ERROR: 1, - NOTIFY_NON_OK_RESPONSE: 2, - NOTIFY_FAILED_AUTHENTICATION: 3, - SEND_FINAL_NOTIFY: 4, - RECEIVE_UNSUBSCRIBE: 5, - SUBSCRIPTION_EXPIRED: 6, - // Notifer states - STATE_PENDING: 0, - STATE_ACTIVE: 1, - STATE_TERMINATED: 2 -}; -/** - * RFC 6665 Notifier implementation. - */ - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(Notifier, _EventEmitter); - - var _super = _createSuper(Notifier); - - /** - * @param {UA} ua - JsSIP User Agent instance. - * @param {IncomingRequest} subscribe - Subscribe request. - * @param {string} contentType - Content-Type header value. - * @param {NotifierOptions} options - Optional parameters. - * @param {Array} extraHeaders - Additional SIP headers. - * @param {string} allowEvents - Allow-Events header value. - * @param {boolean} pending - Set initial dialog state as "pending". - */ - function Notifier(ua, subscribe, contentType, _ref) { - var _this; - - var extraHeaders = _ref.extraHeaders, - allowEvents = _ref.allowEvents, - pending = _ref.pending; - - _classCallCheck(this, Notifier); - - debug('new'); - _this = _super.call(this); - - if (!subscribe) { - throw new TypeError('subscribe is undefined'); - } - - if (!contentType) { - throw new TypeError('contentType is undefined'); - } - - _this._ua = ua; - _this._initial_subscribe = subscribe; - _this._expires_timestamp = null; - _this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait. - - _this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; - _this._is_final_notify_sent = false; // To prevent duplicate emit 'terminated'. - - _this._is_terminated = false; // Optional. Used to build terminated Subscription-State. - - _this._terminated_reason = null; - _this._terminated_retry_after = null; // Custom session empty object for high level use. - - _this.data = {}; - _this._dialog = null; - var eventName = subscribe.getHeader('event'); - _this._content_type = contentType; - _this._expires = parseInt(subscribe.getHeader('expires')); - _this._headers = Utils.cloneArray(extraHeaders); - - _this._headers.push("Event: ".concat(eventName)); // Use contact from extraHeaders or create it. - - - _this._contact = _this._headers.find(function (header) { - return header.startsWith('Contact'); - }); - - if (!_this._contact) { - _this._contact = "Contact: "); - - _this._headers.push(_this._contact); - } - - if (allowEvents) { - _this._headers.push("Allow-Events: ".concat(allowEvents)); - } - - _this._target = subscribe.from.uri.user; - subscribe.to_tag = Utils.newTag(); // Create dialog for normal and fetch SUBSCRIBE - - var dialog = new Dialog(_assertThisInitialized(_this), subscribe, 'UAS'); - - if (dialog.error) { - debugerror(dialog.error); - throw new Error('SUBSCRIBE missed Contact'); - } - - _this._dialog = dialog; - - if (_this._expires > 0) { - // Set expires timer and time-stamp. - _this._setExpiresTimer(); - } - - return _this; - } - /** - * Dialog callback. - * Called also for initial subscribe. - * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). - */ - - - _createClass(Notifier, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - if (request.method !== JsSIP_C.SUBSCRIBE) { - request.reply(405); - return; - } - - var expiresValue = request.getHeader('expires'); - - if (expiresValue === undefined || expiresValue === null) { - // Missed header Expires. RFC 6665 3.1.1. Set default expires value. - expiresValue = '900'; - debug("Missed expires header. Set by default ".concat(expiresValue)); - } - - this._expires = parseInt(expiresValue); - request.reply(200, null, ["Expires: ".concat(this._expires), "".concat(this._contact)]); - var body = request.body; - var content_type = request.getHeader('content-type'); - var is_unsubscribe = this._expires === 0; - - if (!is_unsubscribe) { - this._setExpiresTimer(); - } - - debug('emit "subscribe"'); - this.emit('subscribe', is_unsubscribe, request, body, content_type); - - if (is_unsubscribe) { - this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); - } - } - /** - * User API - */ - - /** - * Should be called after creating the Notifier instance and setting the event handlers. - */ - - }, { - key: "start", - value: function start() { - debug('start()'); - this.receiveRequest(this._initial_subscribe); - } - /** - * Switch pending dialog state to active. - */ - - }, { - key: "setActiveState", - value: function setActiveState() { - debug('setActiveState()'); - - if (this._state === C.STATE_PENDING) { - this._state = C.STATE_ACTIVE; - } - } - /** - * Send the initial and subsequent NOTIFY request. - * @param {string} body - notify request body. - */ - - }, { - key: "notify", - value: function notify() { - var _this2 = this; - - var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('notify()'); // Prevent send notify after final notify. - - if (this._is_final_notify_sent) { - debugerror('final notify has sent'); - return; - } - - var subs_state = this._stateNumberToString(this._state); - - if (this._state !== C.STATE_TERMINATED) { - var expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); - - if (expires < 0) { - expires = 0; - } - - subs_state += ";expires=".concat(expires); - } else { - if (this._terminated_reason) { - subs_state += ";reason=".concat(this._terminated_reason); - } - - if (this._terminated_retry_after !== null) { - subs_state += ";retry-after=".concat(this._terminated_retry_after); - } - } - - var headers = this._headers.slice(); - - headers.push("Subscription-State: ".concat(subs_state)); - - if (body) { - headers.push("Content-Type: ".concat(this._content_type)); - } - - if (!this._dialog) { - throw new Error('no dialog'); - } - - this._dialog.sendRequest(JsSIP_C.NOTIFY, { - body: body, - extraHeaders: headers, - eventHandlers: { - onRequestTimeout: function onRequestTimeout() { - _this2._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); - }, - onTransportError: function onTransportError() { - _this2._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); - }, - onErrorResponse: function onErrorResponse(response) { - if (response.status_code === 401 || response.status_code === 407) { - _this2._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); - } else { - _this2._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); - } - }, - onDialogError: function onDialogError() { - _this2._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); - } - } - }); - } - /** - * Terminate. (Send the final NOTIFY request). - * - * @param {string} body - Notify message body. - * @param {string} reason - Set Subscription-State reason parameter. - * @param {number} retryAfter - Set Subscription-State retry-after parameter. - */ - - }, { - key: "terminate", - value: function terminate() { - var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - debug('terminate()'); - this._state = C.STATE_TERMINATED; - this._terminated_reason = reason; - this._terminated_retry_after = retryAfter; - this.notify(body); - this._is_final_notify_sent = true; - - this._dialogTerminated(C.SEND_FINAL_NOTIFY); - } - /** - * Get dialog state. - */ - - }, { - key: "state", - get: function get() { - return this._state; - } - /** - * Get dialog id. - */ - - }, { - key: "id", - get: function get() { - return this._dialog ? this._dialog.id : null; - } - /** - * Private API - */ - - }, { - key: "_dialogTerminated", - value: function _dialogTerminated(termination_code) { - if (this._is_terminated) { - return; - } - - this._is_terminated = true; - this._state = C.STATE_TERMINATED; - clearTimeout(this._expires_timer); - - if (this._dialog) { - this._dialog.terminate(); - } - - var send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; - debug("emit \"terminated\" code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); - this.emit('terminated', termination_code, send_final_notify); - } - }, { - key: "_setExpiresTimer", - value: function _setExpiresTimer() { - var _this3 = this; - - this._expires_timestamp = new Date().getTime() + this._expires * 1000; - clearTimeout(this._expires_timer); - this._expires_timer = setTimeout(function () { - if (_this3._is_final_notify_sent) { - return; - } - - _this3._terminated_reason = 'timeout'; - _this3._is_final_notify_sent = true; - - _this3.notify(); - - _this3._dialogTerminated(C.SUBSCRIPTION_EXPIRED); - }, this._expires * 1000); - } - }, { - key: "_stateNumberToString", - value: function _stateNumberToString(state) { - switch (state) { - case C.STATE_PENDING: - return 'pending'; - - case C.STATE_ACTIVE: - return 'active'; - - case C.STATE_TERMINATED: - return 'terminated'; - - default: - throw new TypeError('wrong state value'); - } - } - }], [{ - key: "C", - get: - /** - * Expose C object. - */ - function get() { - return C; - } - }]); - - return Notifier; -}(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ -"use strict"; - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -var Grammar = require('./Grammar'); - -var SIPMessage = require('./SIPMessage'); - -var debugerror = require('debug')('JsSIP:ERROR:Parser'); - -debugerror.log = console.warn.bind(console); -/** - * Parse SIP Message - */ - -exports.parseMessage = function (data, ua) { - var message; - var bodyStart; - var headerEnd = data.indexOf('\r\n'); - - if (headerEnd === -1) { - debugerror('parseMessage() | no CRLF found, not a SIP message'); - return; - } // Parse first line. Check if it is a Request or a Reply. - - - var firstLine = data.substring(0, headerEnd); - var parsed = Grammar.parse(firstLine, 'Request_Response'); - - if (parsed === -1) { - debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); - return; - } else if (!parsed.status_code) { - message = new SIPMessage.IncomingRequest(ua); - message.method = parsed.method; - message.ruri = parsed.uri; - } else { - message = new SIPMessage.IncomingResponse(); - message.status_code = parsed.status_code; - message.reason_phrase = parsed.reason_phrase; - } - - message.data = data; - var headerStart = headerEnd + 2; - /* Loop over every line in data. Detect the end of each header and parse - * it or simply add to the headers collection. - */ - - while (true) { - headerEnd = getHeader(data, headerStart); // The SIP message has normally finished. - - if (headerEnd === -2) { - bodyStart = headerStart + 2; - break; - } // Data.indexOf returned -1 due to a malformed message. - else if (headerEnd === -1) { - debugerror('parseMessage() | malformed message'); - return; - } - - parsed = parseHeader(message, data, headerStart, headerEnd); - - if (parsed !== true) { - debugerror('parseMessage() |', parsed.error); - return; - } + if (parsed !== true) { + logger.warn('parseMessage() |', parsed.error); + return; + } headerStart = headerEnd + 2; } @@ -17324,12 +16974,12 @@ function parseHeader(message, data, headerStart, headerEnd) { return true; } } -},{"./Grammar":7,"./SIPMessage":20,"debug":32}],13:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9,"./SIPMessage":20}],13:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -17351,7 +17001,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -17360,6 +17010,8 @@ var EventEmitter = require('events').EventEmitter; var sdp_transform = require('sdp-transform'); +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Exceptions = require('./Exceptions'); @@ -17386,11 +17038,7 @@ var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); var URI = require('./URI'); -var debug = require('debug')('JsSIP:RTCSession'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('RTCSession'); var C = { // RTCSession states. STATUS_NULL: 0, @@ -17415,12 +17063,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(RTCSession); + _createClass(RTCSession, null, [{ + key: "C", + + /** + * Expose C object. + */ + get: function get() { + return C; + } + }]); + function RTCSession(ua) { var _this; _classCallCheck(this, RTCSession); - debug('new'); + logger.debug('new'); _this = _super.call(this); _this._id = null; _this._ua = ua; @@ -17494,70 +17153,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _createClass(RTCSession, [{ - key: "C", - get: function get() { - return C; - } // Expose session failed/ended causes as a property of the RTCSession instance. - - }, { - key: "causes", - get: function get() { - return JsSIP_C.causes; - } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "connection", - get: function get() { - return this._connection; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "start_time", - get: function get() { - return this._start_time; - } - }, { - key: "end_time", - get: function get() { - return this._end_time; - } - }, { - key: "data", - get: function get() { - return this._data; - }, - set: function set(_data) { - this._data = _data; - } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { key: "isInProgress", value: function isInProgress() { switch (this._status) { @@ -17618,7 +17213,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function connect(target) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var initCallback = arguments.length > 2 ? arguments[2] : undefined; - debug('connect()'); + logger.debug('connect()'); var originalTarget = target; var eventHandlers = Utils.cloneObject(options.eventHandlers); var extraHeaders = Utils.cloneArray(options.extraHeaders); @@ -17731,7 +17326,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function init_incoming(request, initCallback) { var _this2 = this; - debug('init_incoming()'); + logger.debug('init_incoming()'); var expires; var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type. @@ -17822,7 +17417,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this3 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('answer()'); + logger.debug('answer()'); var request = this._request; var extraHeaders = Utils.cloneArray(options.extraHeaders); var mediaConstraints = Utils.cloneObject(options.mediaConstraints); @@ -17987,7 +17582,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - debugerror('emit "getusermediafailed" [error:%o]', error); + logger.warn('emit "getusermediafailed" [error:%o]', error); _this3.emit('getusermediafailed', error); @@ -18018,7 +17613,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this3.emit('sdp', e); @@ -18033,7 +17628,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this3.emit('peerconnection:setremotedescriptionfailed', error); @@ -18084,7 +17679,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror(error); + logger.warn(error); }); } /** @@ -18097,7 +17692,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this4 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('terminate()'); + logger.debug('terminate()'); var cause = options.cause || JsSIP_C.causes.BYE; var extraHeaders = Utils.cloneArray(options.extraHeaders); var body = options.body; @@ -18114,7 +17709,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_NULL: case C.STATUS_INVITE_SENT: case C.STATUS_1XX_RECEIVED: - debug('canceling session'); + logger.debug('canceling session'); if (status_code && (status_code < 200 || status_code >= 700)) { throw new TypeError("Invalid status_code: ".concat(status_code)); @@ -18140,7 +17735,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_WAITING_FOR_ANSWER: case C.STATUS_ANSWERED: - debug('rejecting session'); + logger.debug('rejecting session'); status_code = status_code || 480; if (status_code < 300 || status_code >= 700) { @@ -18155,7 +17750,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_WAITING_FOR_ACK: case C.STATUS_CONFIRMED: - debug('terminating session'); + logger.debug('terminating session'); reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; if (status_code && (status_code < 200 || status_code >= 700)) { @@ -18221,7 +17816,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendDTMF", value: function sendDTMF(tones) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendDTMF() | tones: %s', tones); + logger.debug('sendDTMF() | tones: %s', tones); var position = 0; var duration = options.duration || null; var interToneGap = options.interToneGap || null; @@ -18232,7 +17827,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } // Check Session Status. - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_1XX_RECEIVED) { throw new Exceptions.InvalidStateError(this._status); } // Check Transport type. @@ -18257,10 +17852,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } else if (!duration) { duration = RTCSession_DTMF.C.DEFAULT_DURATION; } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { - debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); + logger.debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); duration = RTCSession_DTMF.C.MIN_DURATION; } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { - debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); + logger.debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); duration = RTCSession_DTMF.C.MAX_DURATION; } else { duration = Math.abs(duration); @@ -18273,7 +17868,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } else if (!interToneGap) { interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP; } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { - debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); + logger.debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; } else { interToneGap = Math.abs(interToneGap); @@ -18340,9 +17935,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendInfo", value: function sendInfo(contentType, body) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - debug('sendInfo()'); // Check Session Status. + logger.debug('sendInfo()'); // Check Session Status. - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_1XX_RECEIVED) { throw new Exceptions.InvalidStateError(this._status); } @@ -18360,7 +17955,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { audio: true, video: false }; - debug('mute()'); + logger.debug('mute()'); var audioMuted = false, videoMuted = false; @@ -18396,7 +17991,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { audio: true, video: true }; - debug('unmute()'); + logger.debug('unmute()'); var audioUnMuted = false, videoUnMuted = false; @@ -18436,7 +18031,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('hold()'); + logger.debug('hold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { return false; @@ -18491,7 +18086,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('unhold()'); + logger.debug('unhold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { return false; @@ -18546,7 +18141,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('renegotiate()'); + logger.debug('renegotiate()'); var rtcOfferConstraints = options.rtcOfferConstraints || null; if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -18600,7 +18195,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function refer(target, options) { var _this9 = this; - debug('refer()'); + logger.debug('refer()'); var originalTarget = target; if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -18638,7 +18233,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "sendRequest", value: function sendRequest(method, options) { - debug('sendRequest()'); + logger.debug('sendRequest()'); return this._dialog.sendRequest(method, options); } /** @@ -18650,7 +18245,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function receiveRequest(request) { var _this10 = this; - debug('receiveRequest()'); + logger.debug('receiveRequest()'); if (request.method === JsSIP_C.CANCEL) { /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL @@ -18698,7 +18293,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -18716,7 +18311,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { status_code: 488 }); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this10.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -18812,7 +18407,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onTransportError", value: function onTransportError() { - debugerror('onTransportError()'); + logger.warn('onTransportError()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18825,7 +18420,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onRequestTimeout", value: function onRequestTimeout() { - debugerror('onRequestTimeout()'); + logger.warn('onRequestTimeout()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18838,7 +18433,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onDialogError", value: function onDialogError() { - debugerror('onDialogError()'); + logger.warn('onDialogError()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18852,14 +18447,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "newDTMF", value: function newDTMF(data) { - debug('newDTMF()'); + logger.debug('newDTMF()'); this.emit('newDTMF', data); } // Called from Info handler. }, { key: "newInfo", value: function newInfo(data) { - debug('newInfo()'); + logger.debug('newInfo()'); this.emit('newInfo', data); } /** @@ -18870,19 +18465,19 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "_isReadyToReOffer", value: function _isReadyToReOffer() { if (!this._rtcReady) { - debug('_isReadyToReOffer() | internal WebRTC status not ready'); + logger.debug('_isReadyToReOffer() | internal WebRTC status not ready'); return false; } // No established yet. if (!this._dialog) { - debug('_isReadyToReOffer() | session not established yet'); + logger.debug('_isReadyToReOffer() | session not established yet'); return false; } // Another INVITE transaction is in progress. if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { - debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); + logger.debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); return false; } @@ -18891,10 +18486,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_close", value: function _close() { - debug('close()'); // Close local MediaStream if it was not given by the user. + logger.debug('close()'); // Close local MediaStream if it was not given by the user. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { - debug('close() | closing local MediaStream'); + logger.debug('close() | closing local MediaStream'); Utils.closeMediaStream(this._localMediaStream); } @@ -18908,7 +18503,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { try { this._connection.close(); } catch (error) { - debugerror('close() | error closing the RTCPeerConnection: %o', error); + logger.warn('close() | error closing the RTCPeerConnection: %o', error); } } // Terminate signaling. // Clear SIP timers. @@ -18995,7 +18590,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._timers.ackTimer = setTimeout(function () { if (_this11._status === C.STATUS_WAITING_FOR_ACK) { - debug('no ACK received, terminating the session'); + logger.debug('no ACK received, terminating the session'); clearTimeout(_this11._timers.invite2xxTimer); _this11.sendRequest(JsSIP_C.BYE); @@ -19023,7 +18618,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }); - debug('emit "peerconnection"'); + logger.debug('emit "peerconnection"'); this.emit('peerconnection', { peerconnection: this._connection }); @@ -19033,7 +18628,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _createLocalDescription(type, constraints) { var _this13 = this; - debug('createLocalDescription()'); + logger.debug('createLocalDescription()'); if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\"")); var connection = this._connection; this._rtcReady = false; @@ -19041,7 +18636,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { .then(function () { if (type === 'offer') { return connection.createOffer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createofferfailed" [error:%o]', error); _this13.emit('peerconnection:createofferfailed', error); @@ -19049,7 +18644,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } else { return connection.createAnswer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createanswerfailed" [error:%o]', error); _this13.emit('peerconnection:createanswerfailed', error); @@ -19060,7 +18655,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { .then(function (desc) { return connection.setLocalDescription(desc)["catch"](function (error) { _this13._rtcReady = true; - debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); _this13.emit('peerconnection:setlocaldescriptionfailed', error); @@ -19075,7 +18670,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: type, sdp: connection.localDescription.sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this13.emit('sdp', e); @@ -19098,7 +18693,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: type, sdp: connection.localDescription.sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this13.emit('sdp', e); @@ -19144,7 +18739,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created. if (early_dialog.error) { - debug(early_dialog.error); + logger.debug(early_dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); @@ -19170,7 +18765,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var dialog = new Dialog(this, message, type); if (dialog.error) { - debug(dialog.error); + logger.debug(dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); @@ -19190,7 +18785,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveReinvite(request) { var _this14 = this; - debug('receiveReinvite()'); + logger.debug('receiveReinvite()'); var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; var data = { request: request, @@ -19247,7 +18842,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); + logger.debug('invalid Content-Type'); request.reply(415); return; } @@ -19260,7 +18855,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sendAnswer.call(_this14, desc); })["catch"](function (error) { - debugerror(error); + logger.warn(error); }); function sendAnswer(desc) { @@ -19296,7 +18891,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveUpdate(request) { var _this16 = this; - debug('receiveUpdate()'); + logger.debug('receiveUpdate()'); var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; var data = { request: request, @@ -19336,7 +18931,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); + logger.debug('invalid Content-Type'); request.reply(415); return; } @@ -19349,7 +18944,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sendAnswer.call(_this16, desc); })["catch"](function (error) { - debugerror(error); + logger.warn(error); }); function sendAnswer(desc) { @@ -19369,7 +18964,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _processInDialogSdpOffer(request) { var _this17 = this; - debug('_processInDialogSdpOffer()'); + logger.debug('_processInDialogSdpOffer()'); var sdp = request.parseSDP(); var hold = false; @@ -19405,7 +19000,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var offer = new RTCSessionDescription({ type: 'offer', @@ -19419,7 +19014,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this17._connection.setRemoteDescription(offer)["catch"](function (error) { request.reply(488); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this17.emit('peerconnection:setremotedescriptionfailed', error); @@ -19447,11 +19042,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) { request.reply(500); - debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); throw error; }); })["catch"](function (error) { - debugerror('_processInDialogSdpOffer() failed [error: %o]', error); + logger.warn('_processInDialogSdpOffer() failed [error: %o]', error); }); return this._connectionPromiseQueue; } @@ -19464,16 +19059,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveRefer(request) { var _this18 = this; - debug('receiveRefer()'); + logger.debug('receiveRefer()'); if (!request.refer_to) { - debug('no Refer-To header field present in REFER'); + logger.debug('no Refer-To header field present in REFER'); request.reply(400); return; } if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { - debug('Refer-To header field points to a non-SIP URI scheme'); + logger.debug('Refer-To header field points to a non-SIP URI scheme'); request.reply(416); return; } // Reply before the transaction timer expires. @@ -19481,7 +19076,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(202); var notifier = new RTCSession_ReferNotifier(this, request.cseq); - debug('emit "refer"'); // Emit 'refer'. + logger.debug('emit "refer"'); // Emit 'refer'. this.emit('refer', { request: request, @@ -19541,7 +19136,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_receiveNotify", value: function _receiveNotify(request) { - debug('receiveNotify()'); + logger.debug('receiveNotify()'); if (!request.event) { request.reply(400); @@ -19588,7 +19183,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveReplaces(request) { var _this20 = this; - debug('receiveReplaces()'); + logger.debug('receiveReplaces()'); function _accept2(initCallback) { var _this19 = this; @@ -19606,7 +19201,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } function _reject2() { - debug('Replaced INVITE rejected by the user'); + logger.debug('Replaced INVITE rejected by the user'); request.reply(486); } // Emit 'replace'. @@ -19662,7 +19257,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - debugerror('emit "getusermediafailed" [error:%o]', error); + logger.warn('emit "getusermediafailed" [error:%o]', error); _this21.emit('getusermediafailed', error); @@ -19697,7 +19292,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this21._request.body = desc; _this21._status = C.STATUS_INVITE_SENT; - debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. + logger.debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. _this21.emit('sending', { request: _this21._request @@ -19709,7 +19304,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror(error); + logger.warn(error); }); } /** @@ -19724,7 +19319,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); if (!(sender && sender.dtmf)) { - debugerror('sendDTMF() | no local audio track to send DTMF with'); + logger.warn('sendDTMF() | no local audio track to send DTMF with'); return; } @@ -19739,7 +19334,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveInviteResponse(response) { var _this22 = this; - debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. + logger.debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. if (this._dialog && response.status_code >= 200 && response.status_code <= 299) { /* @@ -19754,7 +19349,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var dialog = new Dialog(this, response, 'UAC'); if (dialog.error !== undefined) { - debug(dialog.error); + logger.debug(dialog.error); return; } @@ -19788,7 +19383,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { { // Do nothing with 1xx responses without To tag. if (!response.to_tag) { - debug('1xx response received without to tag'); + logger.debug('1xx response received without to tag'); break; } // Create Early Dialog if 1XX comes with contact. @@ -19813,7 +19408,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -19824,7 +19419,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }).then(function () { return _this22._progress('remote', response); })["catch"](function (error) { - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this22.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19853,7 +19448,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', _e); var _answer = new RTCSessionDescription({ @@ -19888,7 +19483,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this22.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19914,7 +19509,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this23 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendReinvite()'); + logger.debug('sendReinvite()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; @@ -19935,7 +19530,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this23.emit('sdp', e); @@ -19998,7 +19593,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -20012,7 +19607,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } })["catch"](function (error) { onFailed.call(_this24); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this24.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -20034,7 +19629,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this25 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendUpdate()'); + logger.debug('sendUpdate()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; @@ -20057,7 +19652,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this25.emit('sdp', e); @@ -20146,7 +19741,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -20160,7 +19755,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } })["catch"](function (error) { onFailed.call(_this26); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this26.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -20179,7 +19774,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_acceptAndTerminate", value: function _acceptAndTerminate(response, status_code, reason_phrase) { - debug('acceptAndTerminate()'); + logger.debug('acceptAndTerminate()'); var extraHeaders = []; if (status_code) { @@ -20212,7 +19807,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sdp = sdp_transform.parse(sdp); // Local hold. if (this._localHold && !this._remoteHold) { - debug('mangleOffer() | me on hold, mangling offer'); + logger.debug('mangleOffer() | me on hold, mangling offer'); var _iterator5 = _createForOfIteratorHelper(sdp.media), _step5; @@ -20240,7 +19835,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } // Local and remote hold. else if (this._localHold && this._remoteHold) { - debug('mangleOffer() | both on hold, mangling offer'); + logger.debug('mangleOffer() | both on hold, mangling offer'); var _iterator6 = _createForOfIteratorHelper(sdp.media), _step6; @@ -20262,7 +19857,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } // Remote hold. else if (this._remoteHold) { - debug('mangleOffer() | remote on hold, mangling offer'); + logger.debug('mangleOffer() | remote on hold, mangling offer'); var _iterator7 = _createForOfIteratorHelper(sdp.media), _step7; @@ -20384,7 +19979,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debug('runSessionTimer() | sending session refresh request'); + logger.debug('runSessionTimer() | sending session refresh request'); if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { _this27._sendUpdate(); @@ -20399,7 +19994,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror('runSessionTimer() | timer expired, terminating the session'); + logger.warn('runSessionTimer() | timer expired, terminating the session'); _this27.terminate({ cause: JsSIP_C.causes.REQUEST_TIMEOUT, @@ -20454,7 +20049,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_newRTCSession", value: function _newRTCSession(originator, request) { - debug('newRTCSession()'); + logger.debug('newRTCSession()'); this._ua.newRTCSession(this, { originator: originator, @@ -20465,8 +20060,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_connecting", value: function _connecting(request) { - debug('session connecting'); - debug('emit "connecting"'); + logger.debug('session connecting'); + logger.debug('emit "connecting"'); this.emit('connecting', { request: request }); @@ -20474,8 +20069,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_progress", value: function _progress(originator, response) { - debug('session progress'); - debug('emit "progress"'); + logger.debug('session progress'); + logger.debug('emit "progress"'); this.emit('progress', { originator: originator, response: response || null @@ -20484,9 +20079,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_accepted", value: function _accepted(originator, message) { - debug('session accepted'); + logger.debug('session accepted'); this._start_time = new Date(); - debug('emit "accepted"'); + logger.debug('emit "accepted"'); this.emit('accepted', { originator: originator, response: message || null @@ -20495,9 +20090,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_confirmed", value: function _confirmed(originator, ack) { - debug('session confirmed'); + logger.debug('session confirmed'); this._is_confirmed = true; - debug('emit "confirmed"'); + logger.debug('emit "confirmed"'); this.emit('confirmed', { originator: originator, ack: ack || null @@ -20506,12 +20101,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_ended", value: function _ended(originator, message, cause) { - debug('session ended'); + logger.debug('session ended'); this._end_time = new Date(); this._close(); - debug('emit "ended"'); + logger.debug('emit "ended"'); this.emit('ended', { originator: originator, message: message || null, @@ -20521,9 +20116,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_failed", value: function _failed(originator, message, cause) { - debug('session failed'); // Emit private '_failed' event first. + logger.debug('session failed'); // Emit private '_failed' event first. - debug('emit "_failed"'); + logger.debug('emit "_failed"'); this.emit('_failed', { originator: originator, message: message || null, @@ -20532,7 +20127,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._close(); - debug('emit "failed"'); + logger.debug('emit "failed"'); this.emit('failed', { originator: originator, message: message || null, @@ -20542,11 +20137,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_onhold", value: function _onhold(originator) { - debug('session onhold'); + logger.debug('session onhold'); this._setLocalMediaStatus(); - debug('emit "hold"'); + logger.debug('emit "hold"'); this.emit('hold', { originator: originator }); @@ -20554,11 +20149,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_onunhold", value: function _onunhold(originator) { - debug('session onunhold'); + logger.debug('session onunhold'); this._setLocalMediaStatus(); - debug('emit "unhold"'); + logger.debug('emit "unhold"'); this.emit('unhold', { originator: originator }); @@ -20568,11 +20163,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _onmute(_ref5) { var audio = _ref5.audio, video = _ref5.video; - debug('session onmute'); + logger.debug('session onmute'); this._setLocalMediaStatus(); - debug('emit "muted"'); + logger.debug('emit "muted"'); this.emit('muted', { audio: audio, video: video @@ -20583,30 +20178,85 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _onunmute(_ref6) { var audio = _ref6.audio, video = _ref6.video; - debug('session onunmute'); + logger.debug('session onunmute'); this._setLocalMediaStatus(); - debug('emit "unmuted"'); + logger.debug('emit "unmuted"'); this.emit('unmuted', { audio: audio, video: video }); } - }], [{ + }, { key: "C", - get: - /** - * Expose C object. - */ - function get() { + get: function get() { return C; + } // Expose session failed/ended causes as a property of the RTCSession instance. + + }, { + key: "causes", + get: function get() { + return JsSIP_C.causes; + } + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "connection", + get: function get() { + return this._connection; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "start_time", + get: function get() { + return this._start_time; + } + }, { + key: "end_time", + get: function get() { + return this._end_time; + } + }, { + key: "data", + get: function get() { + return this._data; + }, + set: function set(_data) { + this._data = _data; + } + }, { + key: "status", + get: function get() { + return this._status; } }]); return RTCSession; }(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,"debug":32,"events":31,"sdp-transform":37}],14:[function(require,module,exports){ +},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./Logger":9,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":22,"./Transactions":23,"./URI":26,"./Utils":27,"events":30,"sdp-transform":36}],14:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20627,23 +20277,21 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('../Logger'); + var JsSIP_C = require('../Constants'); var Exceptions = require('../Exceptions'); var Utils = require('../Utils'); -var debug = require('debug')('JsSIP:RTCSession:DTMF'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('RTCSession:DTMF'); var C = { MIN_DURATION: 70, MAX_DURATION: 6000, @@ -20672,16 +20320,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(DTMF, [{ - key: "tone", - get: function get() { - return this._tone; - } - }, { - key: "duration", - get: function get() { - return this._duration; - } - }, { key: "send", value: function send(tone) { var _this2 = this; @@ -20790,7 +20428,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (!this._tone) { - debug('invalid INFO DTMF received, discarded'); + logger.debug('invalid INFO DTMF received, discarded'); } else { this._session.newDTMF({ originator: 'remote', @@ -20799,6 +20437,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } } + }, { + key: "tone", + get: function get() { + return this._tone; + } + }, { + key: "duration", + get: function get() { + return this._duration; + } }]); return DTMF; @@ -20809,7 +20457,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { module.exports.C = C; -},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],15:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":27,"events":30}],15:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20830,16 +20478,12 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); - -debugerror.log = console.warn.bind(console); - var JsSIP_C = require('../Constants'); var Exceptions = require('../Exceptions'); @@ -20865,16 +20509,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Info, [{ - key: "contentType", - get: function get() { - return this._contentType; - } - }, { - key: "body", - get: function get() { - return this._body; - } - }, { key: "send", value: function send(contentType, body) { var _this2 = this; @@ -20945,11 +20579,21 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request: request }); } + }, { + key: "contentType", + get: function get() { + return this._contentType; + } + }, { + key: "body", + get: function get() { + return this._body; + } }]); return Info; }(EventEmitter); -},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],16:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Utils":27,"events":30}],16:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -20958,10 +20602,11 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var JsSIP_C = require('../Constants'); +var Logger = require('../Logger'); -var debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); +var JsSIP_C = require('../Constants'); +var logger = new Logger('RTCSession:ReferNotifier'); var C = { event_type: 'refer', body_type: 'message/sipfrag;version=2.0', @@ -20983,7 +20628,7 @@ module.exports = /*#__PURE__*/function () { _createClass(ReferNotifier, [{ key: "notify", value: function notify(code, reason) { - debug('notify()'); + logger.debug('notify()'); if (this._active === false) { return; @@ -21014,7 +20659,7 @@ module.exports = /*#__PURE__*/function () { return ReferNotifier; }(); -},{"../Constants":2,"debug":32}],17:[function(require,module,exports){ +},{"../Constants":2,"../Logger":9}],17:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -21035,19 +20680,21 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('../Logger'); + var JsSIP_C = require('../Constants'); var Grammar = require('../Grammar'); var Utils = require('../Utils'); -var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); +var logger = new Logger('RTCSession:ReferSubscriber'); module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(ReferSubscriber, _EventEmitter); @@ -21066,17 +20713,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(ReferSubscriber, [{ - key: "id", - get: function get() { - return this._id; - } - }, { key: "sendRefer", value: function sendRefer(target) { var _this2 = this; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendRefer()'); + logger.debug('sendRefer()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers. @@ -21098,10 +20740,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">"); - extraHeaders.push(referTo); // Referred-By header field. + extraHeaders.push(referTo); // Referred-By header field (if not already present). + + if (!extraHeaders.some(function (header) { + return header.toLowerCase().startsWith('referred-by:'); + })) { + var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); + extraHeaders.push(referredBy); + } - var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); - extraHeaders.push(referredBy); extraHeaders.push("Contact: ".concat(this._session.contact)); var request = this._session.sendRequest(JsSIP_C.REFER, { @@ -21130,7 +20777,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "receiveNotify", value: function receiveNotify(request) { - debug('receiveNotify()'); + logger.debug('receiveNotify()'); if (!request.body) { return; @@ -21139,7 +20786,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var status_line = Grammar.parse(request.body.trim(), 'Status_Line'); if (status_line === -1) { - debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); + logger.debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); return; } @@ -21176,8 +20823,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_requestSucceeded", value: function _requestSucceeded(response) { - debug('REFER succeeded'); - debug('emit "requestSucceeded"'); + logger.debug('REFER succeeded'); + logger.debug('emit "requestSucceeded"'); this.emit('requestSucceeded', { response: response }); @@ -21185,18 +20832,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_requestFailed", value: function _requestFailed(response, cause) { - debug('REFER failed'); - debug('emit "requestFailed"'); + logger.debug('REFER failed'); + logger.debug('emit "requestFailed"'); this.emit('requestFailed', { response: response || null, cause: cause }); } + }, { + key: "id", + get: function get() { + return this._id; + } }]); return ReferSubscriber; }(EventEmitter); -},{"../Constants":2,"../Grammar":7,"../Utils":28,"debug":32,"events":31}],18:[function(require,module,exports){ +},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":27,"events":30}],18:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -21205,6 +20857,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var Utils = require('./Utils'); var JsSIP_C = require('./Constants'); @@ -21213,8 +20867,7 @@ var SIPMessage = require('./SIPMessage'); var RequestSender = require('./RequestSender'); -var debug = require('debug')('JsSIP:Registrator'); - +var logger = new Logger('Registrator'); var MIN_REGISTER_EXPIRES = 10; // In seconds. module.exports = /*#__PURE__*/function () { @@ -21251,11 +20904,6 @@ module.exports = /*#__PURE__*/function () { } _createClass(Registrator, [{ - key: "registered", - get: function get() { - return this._registered; - } - }, { key: "setExtraHeaders", value: function setExtraHeaders(extraHeaders) { if (!Array.isArray(extraHeaders)) { @@ -21291,7 +20939,7 @@ module.exports = /*#__PURE__*/function () { var _this = this; if (this._registering) { - debug('Register request in progress...'); + logger.debug('Register request in progress...'); return; } @@ -21339,7 +20987,7 @@ module.exports = /*#__PURE__*/function () { _this._registering = false; if (!response.hasHeader('Contact')) { - debug('no Contact header in response to REGISTER, response ignored'); + logger.debug('no Contact header in response to REGISTER, response ignored'); break; } @@ -21359,7 +21007,7 @@ module.exports = /*#__PURE__*/function () { } if (!contact) { - debug('no Contact header pointing to us, response ignored'); + logger.debug('no Contact header pointing to us, response ignored'); break; } @@ -21419,7 +21067,7 @@ module.exports = /*#__PURE__*/function () { _this.register(); } else { // This response MUST contain a Min-Expires header field. - debug('423 response received for REGISTER without Min-Expires'); + logger.debug('423 response received for REGISTER without Min-Expires'); _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); } @@ -21447,7 +21095,7 @@ module.exports = /*#__PURE__*/function () { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (!this._registered) { - debug('already unregistered'); + logger.debug('already unregistered'); return; } @@ -21558,11 +21206,16 @@ module.exports = /*#__PURE__*/function () { cause: cause || null }); } + }, { + key: "registered", + get: function get() { + return this._registered; + } }]); return Registrator; }(); -},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32}],19:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27}],19:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -21571,14 +21224,15 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var DigestAuthentication = require('./DigestAuthentication'); var Transactions = require('./Transactions'); -var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers. - +var logger = new Logger('RequestSender'); // Default event handlers. var EventHandlers = { onRequestTimeout: function onRequestTimeout() {}, @@ -21682,7 +21336,7 @@ module.exports = /*#__PURE__*/function () { if (!challenge) { - debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); + logger.debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); this._eventHandlers.onReceiveResponse(response); @@ -21737,7 +21391,7 @@ module.exports = /*#__PURE__*/function () { return RequestSender; }(); -},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,"debug":32}],20:[function(require,module,exports){ +},{"./Constants":2,"./DigestAuthentication":5,"./Logger":9,"./Transactions":23}],20:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -21752,11 +21406,11 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -21770,6 +21424,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d var sdp_transform = require('sdp-transform'); +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Utils = require('./Utils'); @@ -21778,7 +21434,7 @@ var NameAddrHeader = require('./NameAddrHeader'); var Grammar = require('./Grammar'); -var debug = require('debug')('JsSIP:SIPMessage'); +var logger = new Logger('SIPMessage'); /** * -param {String} method request method * -param {String} ruri request uri @@ -21790,7 +21446,6 @@ var debug = require('debug')('JsSIP:SIPMessage'); * -param {String} [body] */ - var OutgoingRequest = /*#__PURE__*/function () { function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) { _classCallCheck(this, OutgoingRequest); @@ -22269,10 +21924,10 @@ var IncomingMessage = /*#__PURE__*/function () { name = Utils.headerize(name); if (!this.headers[name]) { - debug("header \"".concat(name, "\" not present")); + logger.debug("header \"".concat(name, "\" not present")); return; } else if (idx >= this.headers[name].length) { - debug("not so many \"".concat(name, "\" headers present")); + logger.debug("not so many \"".concat(name, "\" headers present")); return; } @@ -22289,7 +21944,7 @@ var IncomingMessage = /*#__PURE__*/function () { if (parsed === -1) { this.headers[name].splice(idx, 1); // delete from headers - debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); + logger.debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); return; } else { header.parsed = parsed; @@ -22503,746 +22158,170 @@ var IncomingRequest = /*#__PURE__*/function (_IncomingMessage) { var length = Utils.str_utf8_length(body); response += 'Content-Type: application/sdp\r\n'; response += "Content-Length: ".concat(length, "\r\n\r\n"); - response += body; - } else { - response += "Content-Length: ".concat(0, "\r\n\r\n"); - } - - this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); - } - /** - * Stateless reply. - * -param {Number} code status code - * -param {String} reason reason phrase - */ - - }, { - key: "reply_sl", - value: function reply_sl() { - var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var vias = this.getHeaders('via'); // Validate code and reason values. - - if (!code || code < 100 || code > 699) { - throw new TypeError("Invalid status_code: ".concat(code)); - } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { - throw new TypeError("Invalid reason_phrase: ".concat(reason)); - } - - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); - - var _iterator11 = _createForOfIteratorHelper(vias), - _step11; - - try { - for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { - var via = _step11.value; - response += "Via: ".concat(via, "\r\n"); - } - } catch (err) { - _iterator11.e(err); - } finally { - _iterator11.f(); - } - - var to = this.getHeader('To'); - - if (!this.to_tag && code > 100) { - to += ";tag=".concat(Utils.newTag()); - } else if (this.to_tag && !this.s('to').hasParam('tag')) { - to += ";tag=".concat(this.to_tag); - } - - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(this.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(this.call_id, "\r\n"); - response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); - response += "Content-Length: ".concat(0, "\r\n\r\n"); - this.transport.send(response); - } - }]); - - return IncomingRequest; -}(IncomingMessage); - -var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { - _inherits(IncomingResponse, _IncomingMessage2); - - var _super3 = _createSuper(IncomingResponse); - - function IncomingResponse() { - var _this3; - - _classCallCheck(this, IncomingResponse); - - _this3 = _super3.call(this); - _this3.headers = {}; - _this3.status_code = null; - _this3.reason_phrase = null; - return _this3; - } - - return IncomingResponse; -}(IncomingMessage); - -module.exports = { - OutgoingRequest: OutgoingRequest, - InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, - IncomingRequest: IncomingRequest, - IncomingResponse: IncomingResponse -}; -},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,"debug":32,"sdp-transform":37}],21:[function(require,module,exports){ -"use strict"; - -var Utils = require('./Utils'); - -var Grammar = require('./Grammar'); - -var debugerror = require('debug')('JsSIP:ERROR:Socket'); - -debugerror.log = console.warn.bind(console); -/** - * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ - * - * interface Socket { - * attribute String via_transport - * attribute String url - * attribute String sip_uri - * - * method connect(); - * method disconnect(); - * method send(data); - * - * attribute EventHandler onconnect - * attribute EventHandler ondisconnect - * attribute EventHandler ondata - * } - * - */ - -exports.isSocket = function (socket) { - // Ignore if an array is given. - if (Array.isArray(socket)) { - return false; - } - - if (typeof socket === 'undefined') { - debugerror('undefined JsSIP.Socket instance'); - return false; - } // Check Properties. - - - try { - if (!Utils.isString(socket.url)) { - debugerror('missing or invalid JsSIP.Socket url property'); - throw new Error(); - } - - if (!Utils.isString(socket.via_transport)) { - debugerror('missing or invalid JsSIP.Socket via_transport property'); - throw new Error(); - } - - if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { - debugerror('missing or invalid JsSIP.Socket sip_uri property'); - throw new Error(); - } - } catch (e) { - return false; - } // Check Methods. - - - try { - ['connect', 'disconnect', 'send'].forEach(function (method) { - if (!Utils.isFunction(socket[method])) { - debugerror("missing or invalid JsSIP.Socket method: ".concat(method)); - throw new Error(); - } - }); - } catch (e) { - return false; - } - - return true; -}; -},{"./Grammar":7,"./Utils":28,"debug":32}],22:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('./Constants'); - -var Utils = require('./Utils'); - -var Grammar = require('./Grammar'); - -var SIPMessage = require('./SIPMessage'); - -var RequestSender = require('./RequestSender'); - -var Dialog = require('./Dialog'); - -var debug = require('debug')('JsSIP:Subscriber'); - -var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); - -debugerror.log = console.warn.bind(console); -/** - * Termination codes. - */ - -var C = { - // Termination codes. - SUBSCRIBE_RESPONSE_TIMEOUT: 0, - SUBSCRIBE_TRANSPORT_ERROR: 1, - SUBSCRIBE_NON_OK_RESPONSE: 2, - SUBSCRIBE_FAILED_AUTHENTICATION: 3, - UNSUBSCRIBE_TIMEOUT: 4, - RECEIVE_FINAL_NOTIFY: 5, - RECEIVE_BAD_NOTIFY: 6, - // Subscriber states. - STATE_PENDING: 0, - STATE_ACTIVE: 1, - STATE_TERMINATED: 2, - STATE_INIT: 3, - STATE_NOTIFY_WAIT: 4 -}; -/** - * RFC 6665 Subscriber implementation. - */ - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(Subscriber, _EventEmitter); - - var _super = _createSuper(Subscriber); - - /** - * @param {UA} ua - reference to JsSIP.UA - * @param {string} target - * @param {string} eventName - Event header value. May end with optional ;id=xxx - * @param {string} accept - Accept header value. - * - * @param {SubscriberOption} options - optional parameters. - * @param {number} expires - Expires header value. Default is 900. - * @param {string} contentType - Content-Type header value. Used for SUBSCRIBE with body - * @param {string} allowEvents - Allow-Events header value. - * @param {RequestParams} params - Will have priority over ua.configuration. - * If set please define: to_uri, to_display_name, from_uri, from_display_name - * @param {Array} extraHeaders - Additional SIP headers. - */ - function Subscriber(ua, target, eventName, accept, _ref) { - var _this; - - var expires = _ref.expires, - contentType = _ref.contentType, - allowEvents = _ref.allowEvents, - params = _ref.params, - extraHeaders = _ref.extraHeaders; - - _classCallCheck(this, Subscriber); - - debug('new'); - _this = _super.call(this); // Check that arguments are defined - - if (!target) { - throw new TypeError('target is undefined'); - } - - if (!eventName) { - throw new TypeError('eventName is undefined'); - } - - if (!accept) { - throw new TypeError('accept is undefined'); - } - - _this._ua = ua; - _this._target = target; - _this._accept = accept; - - if (expires !== 0 && !expires) { - expires = 900; - } - - _this._expires = expires; // Used to subscribe with body. - - _this._content_type = contentType; // Set initial SUBSCRIBE parameters. - - _this._params = Utils.cloneObject(params); - - if (!_this._params.from_uri) { - _this._params.from_uri = _this._ua.configuration.uri; - } - - _this._params.from_tag = Utils.newTag(); - _this._params.to_tag = null; - _this._params.call_id = Utils.createRandomToken(20); // Create cseq if not defined custom cseq. - - if (_this._params.cseq === undefined) { - _this._params.cseq = Math.floor(Math.random() * 10000 + 1); - } // Subscriber state. - - - _this._state = C.STATE_INIT; - _this._dialog = null; - _this._request = null; // To refresh subscription. - - _this._expires_timer = null; - _this._expires_timestamp = null; // To prevent duplicate un-subscribe sending. - - _this._send_unsubscribe = false; // To prevent duplicate emit terminated event. - - _this._is_terminated = false; // After send un-subscribe wait final NOTIFY limited time. - - _this._unsubscribe_timeout_timer = null; // Custom session empty object for high level use. - - _this.data = {}; - var parsed = Grammar.parse(eventName, 'Event'); - - if (parsed === -1) { - throw new TypeError('eventName - wrong format'); - } - - _this._event_name = parsed.event; - _this._event_id = parsed.params && parsed.params.id; - var eventValue = _this._event_name; - - if (_this._event_id) { - eventValue += ";id=".concat(_this._event_id); - } - - _this._headers = Utils.cloneArray(extraHeaders); - _this._headers = _this._headers.concat(["Event: ".concat(eventValue), "Expires: ".concat(_this._expires), "Accept: ".concat(_this._accept)]); - - if (!_this._headers.find(function (header) { - return header.startsWith('Contact'); - })) { - var contact = "Contact: "); - contact += ";+sip.instance=\"\""); - - _this._headers.push(contact); - } - - if (allowEvents) { - _this._headers.push("Allow-Events: ".concat(allowEvents)); - } - - return _this; - } - - _createClass(Subscriber, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "onRequestTimeout", - value: function onRequestTimeout() { - this._dialogTerminated(C.SUBSCRIBE_RESPONSE_TIMEOUT); - } - }, { - key: "onTransportError", - value: function onTransportError() { - this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); - } - /** - * Dialog callback. - */ - - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - if (request.method !== JsSIP_C.NOTIFY) { - debugerror('received non-NOTIFY request'); - request.reply(405); - return; - } // RFC 6665 8.2.1. Check if event header matches. - - - var event_header = request.parseHeader('Event'); - - if (!event_header) { - debugerror('missed Event header'); - request.reply(400); - - this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); - - return; - } - - var event_name = event_header.event; - var event_id = event_header.params && event_header.params.id; - - if (event_name !== this._event_name || event_id !== this._event_id) { - debugerror('Event header does not match SUBSCRIBE'); - request.reply(489); - - this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); - - return; - } // Process Subscription-State header. - - - var subs_state = request.parseHeader('subscription-state'); - - if (!subs_state) { - debugerror('missed Subscription-State header'); - request.reply(400); - - this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); - - return; - } - - request.reply(200); - - var new_state = this._stateStringToNumber(subs_state.state); - - var prev_state = this._state; - - if (prev_state !== C.STATE_TERMINATED && new_state !== C.STATE_TERMINATED) { - this._state = new_state; - - if (subs_state.expires !== undefined) { - var expires = subs_state.expires; - var expires_timestamp = new Date().getTime() + expires * 1000; - var max_time_deviation = 2000; // Expiration time is shorter and the difference is not too small. - - if (this._expires_timestamp - expires_timestamp > max_time_deviation) { - debug('update sending re-SUBSCRIBE time'); - - this._scheduleSubscribe(expires); - } - } - } - - if (prev_state !== C.STATE_PENDING && new_state === C.STATE_PENDING) { - debug('emit "pending"'); - this.emit('pending'); - } else if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { - debug('emit "active"'); - this.emit('active'); - } - - var body = request.body; // Check if the NOTIFY is final. - - var is_final = new_state === C.STATE_TERMINATED; // Notify event fired for NOTIFY with body. - - if (body) { - var content_type = request.getHeader('content-type'); - debug('emit "notify"'); - this.emit('notify', is_final, request, body, content_type); - } - - if (is_final) { - var reason = subs_state.reason; - var retry_after = undefined; - - if (subs_state.params && subs_state.params['retry-after'] !== undefined) { - retry_after = parseInt(subs_state.params['retry-after']); - } - - this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason, retry_after); - } - } - /** - * User API - */ - - /** - * Send the initial (non-fetch) and subsequent SUBSCRIBE. - * @param {string} body - subscribe request body. - */ - - }, { - key: "subscribe", - value: function subscribe() { - var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('subscribe()'); - - if (this._state === C.STATE_INIT) { - this._state = C.STATE_NOTIFY_WAIT; - - this._sendInitialSubscribe(body, this._headers); - } else { - this._sendSubsequentSubscribe(body, this._headers); - } - } - /** - * terminate. - * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0). - * @param {string} body - Un-subscribe request body - */ - - }, { - key: "terminate", - value: function terminate() { - var _this2 = this; - - var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('terminate()'); // Prevent duplication un-subscribe sending. - - if (this._send_unsubscribe) { - debugerror('unsubscribe has already been sent'); - return; - } - - this._send_unsubscribe = true; // Set header Expires: 0. - - var headers = this._headers.map(function (s) { - return s.startsWith('Expires') ? 'Expires: 0' : s; - }); - - if (!this._dialog) { - // Fetch-SUBSCRIBE is the first and last one. - this._sendInitialSubscribe(body, headers); - } else { - this._sendSubsequentSubscribe(body, headers); - } // Waiting for the final notify for a while. - - - var final_notify_timeout = 30000; - this._unsubscribe_timeout_timer = setTimeout(function () { - _this2._dialogTerminated(C.UNSUBSCRIBE_TIMEOUT); - }, final_notify_timeout); - } - /** - * Get dialog state. - */ - - }, { - key: "state", - get: function get() { - return this._state; - } - /** - * Get dialog id. - */ - - }, { - key: "id", - get: function get() { - return this._dialog ? this._dialog.id : null; - } - /** - * Private API. - */ - - }, { - key: "_sendInitialSubscribe", - value: function _sendInitialSubscribe(body, headers) { - var _this3 = this; - - if (body) { - if (!this._content_type) { - throw new TypeError('content_type is undefined'); - } - - headers = headers.slice(); - headers.push("Content-Type: ".concat(this._content_type)); + response += body; + } else { + response += "Content-Length: ".concat(0, "\r\n\r\n"); } - this._request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); - var request_sender = new RequestSender(this._ua, this._request, { - onRequestTimeout: function onRequestTimeout() { - _this3.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this3.onTransportError(); - }, - onAuthenticated: function onAuthenticated(request) { - _this3._request = request; - }, - onReceiveResponse: function onReceiveResponse(response) { - _this3._receiveSubscribeResponse(response); - } - }); - request_sender.send(); + this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); } + /** + * Stateless reply. + * -param {Number} code status code + * -param {String} reason reason phrase + */ + }, { - key: "_receiveSubscribeResponse", - value: function _receiveSubscribeResponse(response) { - if (response.status_code >= 200 && response.status_code < 300) { - // Create dialog - if (this._dialog === null) { - var dialog = new Dialog(this, response, 'UAC'); + key: "reply_sl", + value: function reply_sl() { + var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var vias = this.getHeaders('via'); // Validate code and reason values. - if (dialog.error) { - // OK response without Contact - debug(dialog.error); + if (!code || code < 100 || code > 699) { + throw new TypeError("Invalid status_code: ".concat(code)); + } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { + throw new TypeError("Invalid reason_phrase: ".concat(reason)); + } - this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); - return; - } + var _iterator11 = _createForOfIteratorHelper(vias), + _step11; - this._dialog = dialog; // After the event dialog created. + try { + for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { + var via = _step11.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator11.e(err); + } finally { + _iterator11.f(); + } - debug('emit "initialSubscribeOK"'); - this.emit('initialSubscribeOK'); - } // Check expires value. + var to = this.getHeader('To'); + if (!this.to_tag && code > 100) { + to += ";tag=".concat(Utils.newTag()); + } else if (this.to_tag && !this.s('to').hasParam('tag')) { + to += ";tag=".concat(this.to_tag); + } - var expires_value = response.getHeader('expires'); + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(this.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(this.call_id, "\r\n"); + response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); + response += "Content-Length: ".concat(0, "\r\n\r\n"); + this.transport.send(response); + } + }]); - if (expires_value !== 0 && !expires_value) { - debugerror('response without Expires header'); // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header. - // Use workaround expires value. + return IncomingRequest; +}(IncomingMessage); - expires_value = '900'; - } +var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { + _inherits(IncomingResponse, _IncomingMessage2); - var expires = parseInt(expires_value); + var _super3 = _createSuper(IncomingResponse); - if (expires > 0) { - this._scheduleSubscribe(expires); - } - } else if (response.status_code === 401 || response.status_code === 407) { - this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); - } else if (response.status_code >= 300) { - this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); - } - } - }, { - key: "_sendSubsequentSubscribe", - value: function _sendSubsequentSubscribe(body, headers) { - var _this4 = this; + function IncomingResponse() { + var _this3; - if (!this._dialog) { - debugerror('sending subsequent subscribe before OK response to initial subscribe'); - throw new Error('not received final response to initial SUBSCRIBE'); - } + _classCallCheck(this, IncomingResponse); - if (body) { - if (!this._content_type) { - throw new TypeError('content_type is undefined'); - } + _this3 = _super3.call(this); + _this3.headers = {}; + _this3.status_code = null; + _this3.reason_phrase = null; + return _this3; + } - headers = headers.slice(); - headers.push("Content-Type: ".concat(this._content_type)); - } + return IncomingResponse; +}(IncomingMessage); - this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { - body: body, - extraHeaders: headers, - eventHandlers: { - onRequestTimeout: function onRequestTimeout() { - _this4.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this4.onTransportError(); - }, - onSuccessResponse: function onSuccessResponse(response) { - _this4._receiveSubscribeResponse(response); - }, - onErrorResponse: function onErrorResponse(response) { - _this4._receiveSubscribeResponse(response); - }, - onDialogError: function onDialogError(response) { - _this4._receiveSubscribeResponse(response); - } - } - }); - } - }, { - key: "_dialogTerminated", - value: function _dialogTerminated(terminationCode) { - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; - var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; +module.exports = { + OutgoingRequest: OutgoingRequest, + InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, + IncomingRequest: IncomingRequest, + IncomingResponse: IncomingResponse +}; +},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":27,"sdp-transform":36}],21:[function(require,module,exports){ +"use strict"; - // To prevent duplicate emit terminated event. - if (this._is_terminated) { - return; - } +var Logger = require('./Logger'); - this._is_terminated = true; - this._state = C.STATE_TERMINATED; // Clear timers. +var Utils = require('./Utils'); - clearTimeout(this._expires_timer); - clearTimeout(this._unsubscribe_timeout_timer); +var Grammar = require('./Grammar'); - if (this._dialog) { - this._dialog.terminate(); - } +var logger = new Logger('Socket'); +/** + * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ + * + * interface Socket { + * attribute String via_transport + * attribute String url + * attribute String sip_uri + * + * method connect(); + * method disconnect(); + * method send(data); + * + * attribute EventHandler onconnect + * attribute EventHandler ondisconnect + * attribute EventHandler ondata + * } + * + */ - debug("emit \"terminated\" code=".concat(terminationCode)); - this.emit('terminated', terminationCode, reason, retryAfter); - } - }, { - key: "_scheduleSubscribe", - value: function _scheduleSubscribe(expires) { - var _this5 = this; +exports.isSocket = function (socket) { + // Ignore if an array is given. + if (Array.isArray(socket)) { + return false; + } - var timeout = expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; - this._expires_timestamp = new Date().getTime() + expires * 1000; - debug("next SUBSCRIBE will be sent in ".concat(Math.floor(timeout / 1000), " sec")); - clearTimeout(this._expires_timer); - this._expires_timer = setTimeout(function () { - _this5._expires_timer = null; + if (typeof socket === 'undefined') { + logger.warn('undefined JsSIP.Socket instance'); + return false; + } // Check Properties. - _this5._sendSubsequentSubscribe(null, _this5._headers); - }, timeout); - } - }, { - key: "_stateStringToNumber", - value: function _stateStringToNumber(strState) { - switch (strState) { - case 'pending': - return C.STATE_PENDING; - case 'active': - return C.STATE_ACTIVE; + try { + if (!Utils.isString(socket.url)) { + logger.warn('missing or invalid JsSIP.Socket url property'); + throw new Error('Missing or invalid JsSIP.Socket url property'); + } - case 'terminated': - return C.STATE_TERMINATED; + if (!Utils.isString(socket.via_transport)) { + logger.warn('missing or invalid JsSIP.Socket via_transport property'); + throw new Error('Missing or invalid JsSIP.Socket via_transport property'); + } - case 'init': - return C.STATE_INIT; + if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { + logger.warn('missing or invalid JsSIP.Socket sip_uri property'); + throw new Error('missing or invalid JsSIP.Socket sip_uri property'); + } + } catch (e) { + return false; + } // Check Methods. - case 'notify_wait': - return C.STATE_NOTIFY_WAIT; - default: - throw new TypeError('wrong state value'); + try { + ['connect', 'disconnect', 'send'].forEach(function (method) { + if (!Utils.isFunction(socket[method])) { + logger.warn("missing or invalid JsSIP.Socket method: ".concat(method)); + throw new Error("Missing or invalid JsSIP.Socket method: ".concat(method)); } - } - }], [{ - key: "C", - get: - /** - * Expose C object. - */ - function get() { - return C; - } - }]); + }); + } catch (e) { + return false; + } - return Subscriber; -}(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ + return true; +}; +},{"./Grammar":7,"./Logger":9,"./Utils":27}],22:[function(require,module,exports){ "use strict"; var T1 = 500, @@ -23264,7 +22343,7 @@ module.exports = { PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 }; -},{}],24:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -23285,28 +22364,25 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); var Timers = require('./Timers'); -var debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); - -var debugict = require('debug')('JsSIP:InviteClientTransaction'); - -var debugact = require('debug')('JsSIP:AckClientTransaction'); - -var debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); - -var debugist = require('debug')('JsSIP:InviteServerTransaction'); - +var loggernict = new Logger('NonInviteClientTransaction'); +var loggerict = new Logger('InviteClientTransaction'); +var loggeract = new Logger('AckClientTransaction'); +var loggernist = new Logger('NonInviteServerTransaction'); +var loggerist = new Logger('InviteServerTransaction'); var C = { // Transaction states. STATUS_TRYING: 1, @@ -23351,11 +22427,6 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } _createClass(NonInviteClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -23378,7 +22449,7 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { }, { key: "onTransportError", value: function onTransportError() { - debugnict("transport error occurred, deleting transaction ".concat(this.id)); + loggernict.debug("transport error occurred, deleting transaction ".concat(this.id)); clearTimeout(this.F); clearTimeout(this.K); this.stateChanged(C.STATUS_TERMINATED); @@ -23388,7 +22459,7 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { }, { key: "timer_F", value: function timer_F() { - debugnict("Timer F expired for transaction ".concat(this.id)); + loggernict.debug("Timer F expired for transaction ".concat(this.id)); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); this.eventHandlers.onRequestTimeout(); @@ -23437,6 +22508,11 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } } } + }, { + key: "C", + get: function get() { + return C; + } }]); return NonInviteClientTransaction; @@ -23471,11 +22547,6 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } _createClass(InviteClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -23503,7 +22574,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { clearTimeout(this.M); if (this.state !== C.STATUS_ACCEPTED) { - debugict("transport error occurred, deleting transaction ".concat(this.id)); + loggerict.debug("transport error occurred, deleting transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } @@ -23514,7 +22585,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_M", value: function timer_M() { - debugict("Timer M expired for transaction ".concat(this.id)); + loggerict.debug("Timer M expired for transaction ".concat(this.id)); if (this.state === C.STATUS_ACCEPTED) { clearTimeout(this.B); @@ -23526,7 +22597,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_B", value: function timer_B() { - debugict("Timer B expired for transaction ".concat(this.id)); + loggerict.debug("Timer B expired for transaction ".concat(this.id)); if (this.state === C.STATUS_CALLING) { this.stateChanged(C.STATUS_TERMINATED); @@ -23537,7 +22608,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_D", value: function timer_D() { - debugict("Timer D expired for transaction ".concat(this.id)); + loggerict.debug("Timer D expired for transaction ".concat(this.id)); clearTimeout(this.B); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -23631,6 +22702,11 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } } } + }, { + key: "C", + get: function get() { + return C; + } }]); return InviteClientTransaction; @@ -23660,11 +22736,6 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { } _createClass(AckClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "send", value: function send() { if (!this.transport.send(this.request)) { @@ -23674,9 +22745,14 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { }, { key: "onTransportError", value: function onTransportError() { - debugact("transport error occurred for transaction ".concat(this.id)); + loggeract.debug("transport error occurred for transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } + }, { + key: "C", + get: function get() { + return C; + } }]); return AckClientTransaction; @@ -23706,11 +22782,6 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } _createClass(NonInviteServerTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -23719,7 +22790,7 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { }, { key: "timer_J", value: function timer_J() { - debugnist("Timer J expired for transaction ".concat(this.id)); + loggernist.debug("Timer J expired for transaction ".concat(this.id)); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); } @@ -23728,7 +22799,7 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { value: function onTransportError() { if (!this.transportError) { this.transportError = true; - debugnist("transport error occurred, deleting transaction ".concat(this.id)); + loggernist.debug("transport error occurred, deleting transaction ".concat(this.id)); clearTimeout(this.J); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -23797,6 +22868,11 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } } } + }, { + key: "C", + get: function get() { + return C; + } }]); return NonInviteServerTransaction; @@ -23828,11 +22904,6 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } _createClass(InviteServerTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -23841,10 +22912,10 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { }, { key: "timer_H", value: function timer_H() { - debugist("Timer H expired for transaction ".concat(this.id)); + loggerist.debug("Timer H expired for transaction ".concat(this.id)); if (this.state === C.STATUS_COMPLETED) { - debugist('ACK not received, dialog will be terminated'); + loggerist.debug('ACK not received, dialog will be terminated'); } this.stateChanged(C.STATUS_TERMINATED); @@ -23860,7 +22931,7 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { }, { key: "timer_L", value: function timer_L() { - debugist("Timer L expired for transaction ".concat(this.id)); + loggerist.debug("Timer L expired for transaction ".concat(this.id)); if (this.state === C.STATUS_ACCEPTED) { this.stateChanged(C.STATUS_TERMINATED); @@ -23872,7 +22943,7 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { value: function onTransportError() { if (!this.transportError) { this.transportError = true; - debugist("transport error occurred, deleting transaction ".concat(this.id)); + loggerist.debug("transport error occurred, deleting transaction ".concat(this.id)); if (this.resendProvisionalTimer !== null) { clearInterval(this.resendProvisionalTimer); @@ -23977,6 +23048,11 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } } } + }, { + key: "C", + get: function get() { + return C; + } }]); return InviteServerTransaction; @@ -24093,7 +23169,7 @@ module.exports = { InviteServerTransaction: InviteServerTransaction, checkTransaction: checkTransaction }; -},{"./Constants":2,"./SIPMessage":20,"./Timers":23,"debug":32,"events":31}],25:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Timers":22,"events":30}],24:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -24102,15 +23178,13 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Socket = require('./Socket'); - -var debug = require('debug')('JsSIP:Transport'); +var Logger = require('./Logger'); -var debugerror = require('debug')('JsSIP:ERROR:Transport'); +var Socket = require('./Socket'); var JsSIP_C = require('./Constants'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('Transport'); /** * Constants */ @@ -24144,7 +23218,7 @@ module.exports = /*#__PURE__*/function () { _classCallCheck(this, Transport); - debug('new()'); + logger.debug('new()'); this.status = C.STATUS_DISCONNECTED; // Current socket. this.socket = null; // Socket collection. @@ -24159,7 +23233,7 @@ module.exports = /*#__PURE__*/function () { try { this.textDecoder = new TextDecoder('utf8'); } catch (error) { - debugerror("cannot use TextDecoder: ".concat(error)); + logger.warn("cannot use TextDecoder: ".concat(error)); } if (typeof sockets === 'undefined') { @@ -24190,34 +23264,19 @@ module.exports = /*#__PURE__*/function () { } /** * Instance Methods - */ - - - _createClass(Transport, [{ - key: "via_transport", - get: function get() { - return this.socket.via_transport; - } - }, { - key: "url", - get: function get() { - return this.socket.url; - } - }, { - key: "sip_uri", - get: function get() { - return this.socket.sip_uri; - } - }, { + */ + + + _createClass(Transport, [{ key: "connect", value: function connect() { - debug('connect()'); + logger.debug('connect()'); if (this.isConnected()) { - debug('Transport is already connected'); + logger.debug('Transport is already connected'); return; } else if (this.isConnecting()) { - debug('Transport is connecting'); + logger.debug('Transport is connecting'); return; } @@ -24241,7 +23300,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "disconnect", value: function disconnect() { - debug('close()'); + logger.debug('close()'); this.close_requested = true; this.recover_attempts = 0; this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer. @@ -24267,15 +23326,15 @@ module.exports = /*#__PURE__*/function () { }, { key: "send", value: function send(data) { - debug('send()'); + logger.debug('send()'); if (!this.isConnected()) { - debugerror('unable to send message, transport is not connected'); + logger.warn('unable to send message, transport is not connected'); return false; } var message = data.toString(); - debug("sending message:\n\n".concat(message, "\n")); + logger.debug("sending message:\n\n".concat(message, "\n")); return this.socket.send(message); } }, { @@ -24306,7 +23365,7 @@ module.exports = /*#__PURE__*/function () { k = this.recovery_options.max_interval; } - debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); + logger.debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); this.recovery_timer = setTimeout(function () { if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) { // Get the next available socket with higher weight. @@ -24399,21 +23458,21 @@ module.exports = /*#__PURE__*/function () { value: function _onData(data) { // CRLF Keep Alive response from server. Ignore it. if (data === '\r\n') { - debug('received message with CRLF Keep Alive response'); + logger.debug('received message with CRLF Keep Alive response'); return; } // Binary message. else if (typeof data !== 'string') { try { if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data)); } catch (evt) { - debug('received binary message failed to be converted into string,' + ' message discarded'); + logger.debug('received binary message failed to be converted into string,' + ' message discarded'); return; } - debug("received binary message:\n\n".concat(data, "\n")); + logger.debug("received binary message:\n\n".concat(data, "\n")); } // Text message. else { - debug("received text message:\n\n".concat(data, "\n")); + logger.debug("received text message:\n\n".concat(data, "\n")); } this.ondata({ @@ -24421,11 +23480,26 @@ module.exports = /*#__PURE__*/function () { message: data }); } + }, { + key: "via_transport", + get: function get() { + return this.socket.via_transport; + } + }, { + key: "url", + get: function get() { + return this.socket.url; + } + }, { + key: "sip_uri", + get: function get() { + return this.socket.sip_uri; + } }]); return Transport; }(); -},{"./Constants":2,"./Socket":21,"debug":32}],26:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./Socket":21}],25:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -24446,22 +23520,20 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Registrator = require('./Registrator'); var RTCSession = require('./RTCSession'); -var Subscriber = require('./Subscriber'); - -var Notifier = require('./Notifier'); - var Message = require('./Message'); var Transactions = require('./Transactions'); @@ -24482,11 +23554,7 @@ var sanityCheck = require('./sanityCheck'); var config = require('./Config'); -var debug = require('debug')('JsSIP:UA'); - -var debugerror = require('debug')('JsSIP:ERROR:UA'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('UA'); var C = { // UA status codes. STATUS_INIT: 0, @@ -24510,12 +23578,20 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(UA); + _createClass(UA, null, [{ + key: "C", + // Expose C object. + get: function get() { + return C; + } + }]); + function UA(configuration) { var _this; _classCallCheck(this, UA); - debug('new() [configuration:%o]', configuration); + logger.debug('new() [configuration:%o]', configuration); _this = _super.call(this); _this._cache = { credentials: {} @@ -24559,30 +23635,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(UA, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "configuration", - get: function get() { - return this._configuration; - } - }, { - key: "transport", - get: function get() { - return this._transport; - } // ================= + key: "start", + // ================= // High Level API // ================= @@ -24590,16 +23644,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * Connect to the server if status = STATUS_INIT. * Resume UA after being closed. */ - - }, { - key: "start", value: function start() { - debug('start()'); + logger.debug('start()'); if (this._status === C.STATUS_INIT) { this._transport.connect(); } else if (this._status === C.STATUS_USER_CLOSED) { - debug('restarting UA'); // Disconnect. + logger.debug('restarting UA'); // Disconnect. if (this._closeTimer !== null) { clearTimeout(this._closeTimer); @@ -24613,9 +23664,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._transport.connect(); } else if (this._status === C.STATUS_READY) { - debug('UA is in READY status, not restarted'); + logger.debug('UA is in READY status, not restarted'); } else { - debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); + logger.debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); } // Set dynamic configuration. @@ -24628,7 +23679,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "register", value: function register() { - debug('register()'); + logger.debug('register()'); this._dynConfiguration.register = true; this._registrator.register(); @@ -24640,7 +23691,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "unregister", value: function unregister(options) { - debug('unregister()'); + logger.debug('unregister()'); this._dynConfiguration.register = false; this._registrator.unregister(options); @@ -24685,7 +23736,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "call", value: function call(target, options) { - debug('call()'); + logger.debug('call()'); var session = new RTCSession(this); session.connect(target, options); return session; @@ -24704,31 +23755,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "sendMessage", value: function sendMessage(target, body, options) { - debug('sendMessage()'); + logger.debug('sendMessage()'); var message = new Message(this); message.send(target, body, options); return message; } - /** - * Create subscriber instance - */ - - }, { - key: "subscribe", - value: function subscribe(target, eventName, accept, options) { - debug('subscribe()'); - return new Subscriber(this, target, eventName, accept, options); - } - /** - * Create notifier instance - */ - - }, { - key: "notify", - value: function notify(subscribe, contentType, options) { - debug('notify()'); - return new Notifier(this, subscribe, contentType, options); - } /** * Terminate ongoing sessions. */ @@ -24736,7 +23767,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "terminateSessions", value: function terminateSessions(options) { - debug('terminateSessions()'); + logger.debug('terminateSessions()'); for (var idx in this._sessions) { if (!this._sessions[idx].isEnded()) { @@ -24754,12 +23785,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function stop() { var _this2 = this; - debug('stop()'); // Remove dynamic settings. + logger.debug('stop()'); // Remove dynamic settings. this._dynConfiguration = {}; if (this._status === C.STATUS_USER_CLOSED) { - debug('UA already closed'); + logger.debug('UA already closed'); return; } // Close registrator. @@ -24771,7 +23802,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { for (var session in this._sessions) { if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { - debug("closing session ".concat(session)); + logger.debug("closing session ".concat(session)); try { this._sessions[session].terminate(); @@ -24831,7 +23862,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return this._configuration.authorization_jwt; default: - debugerror('get() | cannot get "%s" parameter in runtime', parameter); + logger.warn('get() | cannot get "%s" parameter in runtime', parameter); return undefined; } } @@ -24883,7 +23914,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } default: - debugerror('set() | cannot set "%s" parameter in runtime', parameter); + logger.warn('set() | cannot set "%s" parameter in runtime', parameter); return false; } @@ -25012,7 +24043,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var method = request.method; // Check that request URI points to us. if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { - debug('Request-URI does not point to us'); + logger.debug('Request-URI does not point to us'); if (request.method !== JsSIP_C.ACK) { request.reply_sl(404); @@ -25059,11 +24090,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var message = new Message(this); message.init_incoming(request); - } else if (method === JsSIP_C.SUBSCRIBE) { - if (this.listeners('newSubscribe').length === 0) { - request.reply(405); - return; - } } else if (method === JsSIP_C.INVITE) { // Initial INVITE. if (!request.to_tag && this.listeners('newRTCSession').length === 0) { @@ -25100,7 +24126,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { session.init_incoming(request); } } else { - debugerror('INVITE received but WebRTC is not supported'); + logger.warn('INVITE received but WebRTC is not supported'); request.reply(488); } @@ -25117,7 +24143,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (session) { session.receiveRequest(request); } else { - debug('received CANCEL request for a non existent session'); + logger.debug('received CANCEL request for a non existent session'); } break; @@ -25138,13 +24164,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(200); break; - case JsSIP_C.SUBSCRIBE: - this.emit('newSubscribe', { - event: request.event, - request: request - }); - break; - default: request.reply(405); break; @@ -25161,7 +24180,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (session) { session.receiveRequest(request); } else { - debug('received NOTIFY request for a non existent subscription'); + logger.debug('received NOTIFY request for a non existent subscription'); request.reply(481, 'Subscription does not exist'); } } @@ -25265,7 +24284,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._transport.ondisconnect = onTransportDisconnect.bind(this); this._transport.ondata = onTransportData.bind(this); } catch (e) { - debugerror(e); + logger.warn(e); throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); } // Remove sockets instance from configuration object. @@ -25343,7 +24362,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } - debug('configuration parameters after validation:'); + logger.debug('configuration parameters after validation:'); for (var _parameter in this._configuration) { // Only show the user user configurable parameters. @@ -25351,29 +24370,48 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { switch (_parameter) { case 'uri': case 'registrar_server': - debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); + logger.debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); break; case 'password': case 'ha1': case 'authorization_jwt': - debug("- ".concat(_parameter, ": NOT SHOWN")); + logger.debug("- ".concat(_parameter, ": NOT SHOWN")); break; default: - debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); + logger.debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); } } } return; } - }], [{ + }, { key: "C", - get: // Expose C object. - function get() { + get: function get() { return C; } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "configuration", + get: function get() { + return this._configuration; + } + }, { + key: "transport", + get: function get() { + return this._transport; + } }]); return UA; @@ -25482,10 +24520,10 @@ function onTransportData(data) { } } } -},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"debug":32,"events":31}],27:[function(require,module,exports){ +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Logger":9,"./Message":10,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Transactions":23,"./Transport":24,"./URI":26,"./Utils":27,"./sanityCheck":29,"events":30}],26:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -25514,6 +24552,24 @@ var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { + _createClass(URI, null, [{ + key: "parse", + + /** + * Parse the given string and returns a JsSIP.URI instance or undefined if + * it is an invalid URI. + */ + value: function parse(uri) { + uri = Grammar.parse(uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } else { + return undefined; + } + } + }]); + function URI(scheme, user, host, port) { var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; @@ -25547,38 +24603,6 @@ module.exports = /*#__PURE__*/function () { } _createClass(URI, [{ - key: "scheme", - get: function get() { - return this._scheme; - }, - set: function set(value) { - this._scheme = value.toLowerCase(); - } - }, { - key: "user", - get: function get() { - return this._user; - }, - set: function set(value) { - this._user = value; - } - }, { - key: "host", - get: function get() { - return this._host; - }, - set: function set(value) { - this._host = value.toLowerCase(); - } - }, { - key: "port", - get: function get() { - return this._port; - }, - set: function set(value) { - this._port = value === 0 ? value : parseInt(value, 10) || null; - } - }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -25722,32 +24746,48 @@ module.exports = /*#__PURE__*/function () { return aor; } - }], [{ - key: "parse", - value: - /** - * Parse the given string and returns a JsSIP.URI instance or undefined if - * it is an invalid URI. - */ - function parse(uri) { - uri = Grammar.parse(uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } else { - return undefined; - } + }, { + key: "scheme", + get: function get() { + return this._scheme; + }, + set: function set(value) { + this._scheme = value.toLowerCase(); + } + }, { + key: "user", + get: function get() { + return this._user; + }, + set: function set(value) { + this._user = value; + } + }, { + key: "host", + get: function get() { + return this._host; + }, + set: function set(value) { + this._host = value.toLowerCase(); + } + }, { + key: "port", + get: function get() { + return this._port; + }, + set: function set(value) { + this._port = value === 0 ? value : parseInt(value, 10) || null; } }]); return URI; }(); -},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./Utils":27}],27:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -26275,7 +25315,7 @@ exports.cloneObject = function (obj) { var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return obj && Object.assign({}, obj) || fallback; }; -},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./URI":26}],28:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -26284,19 +25324,17 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Grammar = require('./Grammar'); - -var debug = require('debug')('JsSIP:WebSocketInterface'); +var Logger = require('./Logger'); -var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); +var Grammar = require('./Grammar'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('WebSocketInterface'); module.exports = /*#__PURE__*/function () { function WebSocketInterface(url) { _classCallCheck(this, WebSocketInterface); - debug('new() [url:"%s"]', url); + logger.debug('new() [url:"%s"]', url); this._url = url; this._sip_uri = null; this._via_transport = null; @@ -26304,10 +25342,10 @@ module.exports = /*#__PURE__*/function () { var parsed_url = Grammar.parse(url, 'absoluteURI'); if (parsed_url === -1) { - debugerror("invalid WebSocket URI: ".concat(url)); + logger.warn("invalid WebSocket URI: ".concat(url)); throw new TypeError("Invalid argument: ".concat(url)); } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { - debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); + logger.warn("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); throw new TypeError("Invalid argument: ".concat(url)); } else { this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws"); @@ -26316,33 +25354,15 @@ module.exports = /*#__PURE__*/function () { } _createClass(WebSocketInterface, [{ - key: "via_transport", - get: function get() { - return this._via_transport; - }, - set: function set(value) { - this._via_transport = value.toUpperCase(); - } - }, { - key: "sip_uri", - get: function get() { - return this._sip_uri; - } - }, { - key: "url", - get: function get() { - return this._url; - } - }, { key: "connect", value: function connect() { - debug('connect()'); + logger.debug('connect()'); if (this.isConnected()) { - debug("WebSocket ".concat(this._url, " is already connected")); + logger.debug("WebSocket ".concat(this._url, " is already connected")); return; } else if (this.isConnecting()) { - debug("WebSocket ".concat(this._url, " is connecting")); + logger.debug("WebSocket ".concat(this._url, " is connecting")); return; } @@ -26350,7 +25370,7 @@ module.exports = /*#__PURE__*/function () { this.disconnect(); } - debug("connecting to WebSocket ".concat(this._url)); + logger.debug("connecting to WebSocket ".concat(this._url)); try { this._ws = new WebSocket(this._url, 'sip'); @@ -26366,7 +25386,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "disconnect", value: function disconnect() { - debug('disconnect()'); + logger.debug('disconnect()'); if (this._ws) { // Unbind websocket event callbacks. @@ -26386,14 +25406,14 @@ module.exports = /*#__PURE__*/function () { }, { key: "send", value: function send(message) { - debug('send()'); + logger.debug('send()'); if (this.isConnected()) { this._ws.send(message); return true; } else { - debugerror('unable to send message, WebSocket is not open'); + logger.warn('unable to send message, WebSocket is not open'); return false; } } @@ -26414,7 +25434,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "_onOpen", value: function _onOpen() { - debug("WebSocket ".concat(this._url, " connected")); + logger.debug("WebSocket ".concat(this._url, " connected")); this.onconnect(); } }, { @@ -26423,10 +25443,10 @@ module.exports = /*#__PURE__*/function () { var wasClean = _ref.wasClean, code = _ref.code, reason = _ref.reason; - debug("WebSocket ".concat(this._url, " closed")); + logger.debug("WebSocket ".concat(this._url, " closed")); if (wasClean === false) { - debug('WebSocket abrupt disconnection'); + logger.debug('WebSocket abrupt disconnection'); } this.ondisconnect(!wasClean, code, reason); @@ -26435,35 +25455,54 @@ module.exports = /*#__PURE__*/function () { key: "_onMessage", value: function _onMessage(_ref2) { var data = _ref2.data; - debug('received WebSocket message'); + logger.debug('received WebSocket message'); this.ondata(data); } }, { key: "_onError", value: function _onError(e) { - debugerror("WebSocket ".concat(this._url, " error: "), e); + logger.warn("WebSocket ".concat(this._url, " error: "), e); + } + }, { + key: "via_transport", + get: function get() { + return this._via_transport; + }, + set: function set(value) { + this._via_transport = value.toUpperCase(); + } + }, { + key: "sip_uri", + get: function get() { + return this._sip_uri; + } + }, { + key: "url", + get: function get() { + return this._url; } }]); return WebSocketInterface; }(); -},{"./Grammar":7,"debug":32}],30:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9}],29:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); var Utils = require('./Utils'); -var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses. - +var logger = new Logger('sanityCheck'); // Checks for requests and responses. var all = [minimumHeaders]; // Checks for requests. @@ -26637,7 +25676,7 @@ function rfc3261_8_2_2_2() { function rfc3261_8_1_3_3() { if (message.getHeaders('via').length > 1) { - debug('more than one Via header field present in the response, dropping the response'); + logger.debug('more than one Via header field present in the response, dropping the response'); return false; } } @@ -26647,7 +25686,7 @@ function rfc3261_18_3_response() { contentLength = message.getHeader('content-length'); if (len < contentLength) { - debug('message body length is lower than the value in Content-Length header field, dropping the response'); + logger.debug('message body length is lower than the value in Content-Length header field, dropping the response'); return false; } } // Sanity Check functions for requests and responses. @@ -26660,7 +25699,7 @@ function minimumHeaders() { var header = _mandatoryHeaders[_i]; if (!message.hasHeader(header)) { - debug("missing mandatory header field : ".concat(header, ", dropping the response")); + logger.debug("missing mandatory header field : ".concat(header, ", dropping the response")); return false; } } @@ -26699,7 +25738,7 @@ function reply(status_code) { response += '\r\n'; transport.send(response); } -},{"./Constants":2,"./SIPMessage":20,"./Utils":28,"debug":32}],31:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Utils":27}],30:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -27224,29 +26263,20 @@ function functionBindPolyfill(context) { }; } -},{}],32:[function(require,module,exports){ -(function (process){(function (){ +},{}],31:[function(require,module,exports){ +(function (process){ /* eslint-env browser */ /** * This is the web browser implementation of `debug()`. */ +exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.storage = localstorage(); -exports.destroy = (() => { - let warned = false; - - return () => { - if (!warned) { - warned = true; - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); - } - }; -})(); /** * Colors. @@ -27407,14 +26437,18 @@ function formatArgs(args) { } /** - * Invokes `console.debug()` when available. - * No-op when `console.debug` is not a "function". - * If `console.debug` is not available, falls back - * to `console.log`. + * Invokes `console.log()` when available. + * No-op when `console.log` is not a "function". * * @api public */ -exports.log = console.debug || console.log || (() => {}); +function log(...args) { + // This hackery is required for IE8/9, where + // the `console.log` function doesn't have 'apply' + return typeof console === 'object' && + console.log && + console.log(...args); +} /** * Save `namespaces`. @@ -27496,8 +26530,8 @@ formatters.j = function (v) { } }; -}).call(this)}).call(this,require('_process')) -},{"./common":33,"_process":35}],33:[function(require,module,exports){ +}).call(this,require('_process')) +},{"./common":32,"_process":34}],32:[function(require,module,exports){ /** * This is the common logic for both the Node.js and web browser @@ -27512,12 +26546,16 @@ function setup(env) { createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = require('ms'); - createDebug.destroy = destroy; Object.keys(env).forEach(key => { createDebug[key] = env[key]; }); + /** + * Active `debug` instances. + */ + createDebug.instances = []; + /** * The currently active debug mode names, and names to skip. */ @@ -27559,7 +26597,6 @@ function setup(env) { */ function createDebug(namespace) { let prevTime; - let enableOverride = null; function debug(...args) { // Disabled? @@ -27589,7 +26626,7 @@ function setup(env) { args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { // If we encounter an escaped % then don't increase the array index if (match === '%%') { - return '%'; + return match; } index++; const formatter = createDebug.formatters[format]; @@ -27612,28 +26649,33 @@ function setup(env) { } debug.namespace = namespace; + debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); - debug.color = createDebug.selectColor(namespace); + debug.color = selectColor(namespace); + debug.destroy = destroy; debug.extend = extend; - debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. - - Object.defineProperty(debug, 'enabled', { - enumerable: true, - configurable: false, - get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, - set: v => { - enableOverride = v; - } - }); + // Debug.formatArgs = formatArgs; + // debug.rawLog = rawLog; - // Env-specific initialization logic for debug instances + // env-specific initialization logic for debug instances if (typeof createDebug.init === 'function') { createDebug.init(debug); } + createDebug.instances.push(debug); + return debug; } + function destroy() { + const index = createDebug.instances.indexOf(this); + if (index !== -1) { + createDebug.instances.splice(index, 1); + return true; + } + return false; + } + function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); newDebug.log = this.log; @@ -27671,6 +26713,11 @@ function setup(env) { createDebug.names.push(new RegExp('^' + namespaces + '$')); } } + + for (i = 0; i < createDebug.instances.length; i++) { + const instance = createDebug.instances[i]; + instance.enabled = createDebug.enabled(instance.namespace); + } } /** @@ -27745,14 +26792,6 @@ function setup(env) { return val; } - /** - * XXX DO NOT USE. This is a temporary stub function. - * XXX It WILL be removed in the next major release. - */ - function destroy() { - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); - } - createDebug.enable(createDebug.load()); return createDebug; @@ -27760,7 +26799,7 @@ function setup(env) { module.exports = setup; -},{"ms":34}],34:[function(require,module,exports){ +},{"ms":33}],33:[function(require,module,exports){ /** * Helpers. */ @@ -27924,7 +26963,7 @@ function plural(ms, msAbs, n, name) { return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); } -},{}],35:[function(require,module,exports){ +},{}],34:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -28110,7 +27149,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],36:[function(require,module,exports){ +},{}],35:[function(require,module,exports){ var grammar = module.exports = { v: [{ name: 'version', @@ -28206,7 +27245,7 @@ var grammar = module.exports = { push: 'rtcpFbTrrInt', reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, names: ['payload', 'value'], - format: 'rtcp-fb:%s trr-int %d' + format: 'rtcp-fb:%d trr-int %d' }, { // a=rtcp-fb:98 nack rpsi @@ -28606,7 +27645,7 @@ Object.keys(grammar).forEach(function (key) { }); }); -},{}],37:[function(require,module,exports){ +},{}],36:[function(require,module,exports){ var parser = require('./parser'); var writer = require('./writer'); @@ -28619,7 +27658,7 @@ exports.parseRemoteCandidates = parser.parseRemoteCandidates; exports.parseImageAttributes = parser.parseImageAttributes; exports.parseSimulcastStreamList = parser.parseSimulcastStreamList; -},{"./parser":38,"./writer":39}],38:[function(require,module,exports){ +},{"./parser":37,"./writer":38}],37:[function(require,module,exports){ var toIntIfInt = function (v) { return String(Number(v)) === v ? Number(v) : v; }; @@ -28745,7 +27784,7 @@ exports.parseSimulcastStreamList = function (str) { }); }; -},{"./grammar":36}],39:[function(require,module,exports){ +},{"./grammar":35}],38:[function(require,module,exports){ var grammar = require('./grammar'); // customized util.format - discards excess arguments and can void middle ones @@ -28861,12 +27900,12 @@ module.exports = function (session, opts) { return sdp.join('\r\n') + '\r\n'; }; -},{"./grammar":36}],40:[function(require,module,exports){ +},{"./grammar":35}],39:[function(require,module,exports){ module.exports={ "name": "jssip", "title": "JsSIP", "description": "the Javascript SIP library", - "version": "3.7.6", + "version": "3.7.11", "homepage": "https://jssip.net", "contributors": [ "José Luis Millán (https://github.com/jmillan)", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 43acec3c2..d5864aacb 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -1,9 +1,9 @@ /* - * JsSIP v3.7.6 + * JsSIP v3.7.11 * the Javascript SIP library * Copyright: 2012-2021 * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag();var v=new f(l(s),t,"UAS");if(v.error)throw _(v.error),new Error("SUBSCRIBE missed Contact");return s._dialog=v,s._expires>0&&s._setExpiresTimer(),s}return t=m,r=[{key:"C",get:function(){return p}}],(n=[{key:"C",get:function(){return p}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&d("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),d('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(p.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){d("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){d("setActiveState()"),this._state===p.STATE_PENDING&&(this._state=p.STATE_ACTIVE)}},{key:"notify",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(d("notify()"),this._is_final_notify_sent)_("final notify has sent");else{var n=this._stateNumberToString(this._state);if(this._state!==p.STATE_TERMINATED){var r=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);r<0&&(r=0),n+=";expires=".concat(r)}else this._terminated_reason&&(n+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(n+=";retry-after=".concat(this._terminated_retry_after));var s=this._headers.slice();if(s.push("Subscription-State: ".concat(n)),t&&s.push("Content-Type: ".concat(this._content_type)),!this._dialog)throw new Error("no dialog");this._dialog.sendRequest(c.NOTIFY,{body:t,extraHeaders:s,eventHandlers:{onRequestTimeout:function(){e._dialogTerminated(p.NOTIFY_RESPONSE_TIMEOUT)},onTransportError:function(){e._dialogTerminated(p.NOTIFY_TRANSPORT_ERROR)},onErrorResponse:function(t){401===t.status_code||407===t.status_code?e._dialogTerminated(p.NOTIFY_FAILED_AUTHENTICATION):e._dialogTerminated(p.NOTIFY_NON_OK_RESPONSE)},onDialogError:function(){e._dialogTerminated(p.NOTIFY_NON_OK_RESPONSE)}}})}}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;d("terminate()"),this._state=p.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._is_final_notify_sent=!0,this._dialogTerminated(p.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_dialogTerminated",value:function(e){if(!this._is_terminated){this._is_terminated=!0,this._state=p.STATE_TERMINATED,clearTimeout(this._expires_timer),this._dialog&&this._dialog.terminate();var t=e===p.SUBSCRIPTION_EXPIRED;d('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._is_final_notify_sent||(e._terminated_reason="timeout",e._is_final_notify_sent=!0,e.notify(),e._dialogTerminated(p.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case p.STATE_PENDING:return"pending";case p.STATE_ACTIVE:return"active";case p.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),m}()},{"./Constants":2,"./Dialog":3,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e,this._headers)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._dialog?this._sendSubsequentSubscribe(t,n):this._sendInitialSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e,t){var n=this;if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._request=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e),new d(this._ua,this._request,{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onAuthenticated:function(e){n._request=e},onReceiveResponse:function(e){n._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return p(t.error),void this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE);this._dialog=t,p('emit "initialSubscribeOK"'),this.emit("initialSubscribeOK")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onSuccessResponse:function(e){n._receiveSubscribeResponse(e)},onErrorResponse:function(e){n._receiveSubscribeResponse(e)},onDialogError:function(e){n._receiveSubscribeResponse(e)}}})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._is_terminated||(this._is_terminated=!0,this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&this._dialog.terminate(),p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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=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);n0)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":21,"./URI":26,"./Utils":27}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":39}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:d.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 o.IncomingResponse&&(s=n.status_code<200?d.STATUS_EARLY:d.STATUS_CONFIRMED);var i=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=i.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=i.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),h.debug("new ".concat(r," dialog created with status ").concat(this._state===d.STATUS_EARLY?"EARLY":"CONFIRMED"))}return s(e,null,[{key:"C",get:function(){return d}}]),s(e,[{key:"update",value:function(e,t){this._state=d.STATUS_CONFIRMED,h.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){h.debug("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=c.cloneArray(n.extraHeaders),s=c.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new a(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===l.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===l.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=c.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===l.CANCEL||e===l.ACK?this._local_seqnum:this._local_seqnum+=1;return new o.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===l.INVITE||e.method===l.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!==u.C.STATUS_ACCEPTED&&e.server_transaction.state!==u.C.STATUS_COMPLETED&&e.server_transaction.state!==u.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===u.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===l.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===u.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,"./Logger":9,"./SIPMessage":20,"./Transactions":23,"./Utils":27}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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":13,"../RequestSender":19,"../Transactions":23}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return o.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return o.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return o.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return o.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop)if(t.qop.indexOf("auth-int")>-1)this._qop="auth-int";else{if(!(t.qop.indexOf("auth")>-1))return o.warn('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=l||i.createRandomToken(12),this._nc+=1;var u,a,c=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-c.length)+c,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=i.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(a))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(i.calculateMD5(s||"")),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(a))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=null [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(a))),o.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Logger":9,"./Utils":27}],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 d=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}(),f=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:d,InvalidStateError:f,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:d,HEXDIG:f,WSP:_,OCTET:p,DQUOTE:m,SP:v,HTAB:g,alphanum:y,reserved:T,unreserved:C,mark:b,escaped:S,LWS:E,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,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:k,token_nodot:D,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:U,STAR:x,SLASH:P,EQUAL:M,LPAREN:L,RPAREN:q,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=L();if(null!==t){for(n=[],null===(r=K())&&null===(r=X())&&(r=e());null!==r;)n.push(r),null===(r=K())&&null===(r=X())&&(r=e());null!==n&&null!==(r=q())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:$,quoted_pair:X,SIP_URI_noparams:J,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:se,password:ie,hostport:oe,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:he,IPv6address:de,h16:fe,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:Ce,method_param:be,ttl_param:Se,maddr_param:Ee,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:De,hname:Ue,hvalue:xe,hnv_unreserved:Pe,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:Le,absoluteURI:qe,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:ze,scheme:$e,authority:Xe,srvr:Je,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:dt,extension_code:ft,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=qt())){for(t=[],o=i,null!==(n=j())&&null!==(r=qt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=qt())?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=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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;tl&&(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 d(){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 f(){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=b()),e}function b(){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 S(){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=f())&&null!==(r=f())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=e.join("")),null===e&&(i=s),e}function E(){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 A(){var e;return e=null!==(e=E())?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=A())?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=E();null!==s;)r.push(s),s=E();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],s=E();null!==s;)r.push(s),s=E();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 N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){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 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&&(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 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&&(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=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null!==t&&null!==(r=A())?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=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null!==t&&null!==(r=A())?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=A())?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=A())?(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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=A())?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=A())&&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=A())?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=E()))),e}function Y(){var e,t,r,s,o,l,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 z(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 $(){var e;return null===(e=E())&&(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 X(){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 J(){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,d;return h=i,d=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=ke())?c:"")?e=[e,t,s,l,u,c]:(e=null,i=d)):(e=null,i=d),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=S())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=S())&&(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=S())&&(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=S())&&(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=d())){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=de())?(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 de(){var e,t,r,s,l,u,c,h,d,f,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=fe())?(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,d,f,_,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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=fe())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,u,c,h,d,f,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(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=fe())?(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=fe())?e=[e,t]:(e=null,i=g),null===e&&(g=i,null!==(e=fe())?("::"===n.substr(i,2)?(t="::",i+=2):(t=null,0===o&&a('"::"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=_e())?e=[e,t,r,s,l,u,c,h,d,f,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?(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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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 fe(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,t,r,s;return s=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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,d,f;return h=i,d=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=d)):(e=null,i=d)):(e=null,i=d)):(e=null,i=d),null!==e&&(f=h,jn.host_type="IPv4",e=n.substring(i,f)),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=be())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ae())&&(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=k())))),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=k())),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 be(){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 Se(){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=An())?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 Ee(){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 Ae(){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=k())?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=Ne())&&null===(e=C())&&(e=S()),e}function Ne(){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 ke(){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=De())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?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=De())?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 De(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=Ue())?(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 Ue(){var e,t;if(null===(t=Pe())&&null===(t=C())&&(t=S()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());else e=null;return e}function xe(){var e,t;for(e=[],null===(t=Pe())&&null===(t=C())&&(t=S());null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());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=Le())&&null!==(r=v())&&null!==(s=et())?e=[e,t,n,r,s]:(e=null,i=o),e}function Le(){var e;return null===(e=Q())&&(e=qe()),e}function qe(){var e,t,r,s;return s=i,null!==(e=$e())?(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=Xe())&&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=S()),e}function Ve(){var e;return null===(e=C())&&null===(e=S())&&(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=ze();null!==t;)e.push(t),t=ze();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=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=S())&&(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 $e(){var e,t,r,s,l,u;if(s=i,l=i,null!==(e=d())){for(t=[],null===(r=d())&&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=d())&&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 Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){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=S())&&(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=S())&&(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,d,f;if(c=i,d=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=d)}else e=null,i=d;else e=null,i=d}else e=null,i=d;else e=null,i=d;return null!==e&&(f=c,e=void(jn.sip_version=n.substring(i,f))),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=k()),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=dt())&&null!==(r=v())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function dt(){var e,t,n;return t=i,null!==(e=ft())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function ft(){var e,t,n,r;return r=i,null!==(e=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=S())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=S())&&null===(t=O())&&null===(t=N())&&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=J())&&(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=k())){for(t=[],l=i,null!==(n=E())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=E())&&null!==(r=k())?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=z()),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=St()),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=bt())?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 bt(){var e,t,r,s,l,u,c,d,f;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&a('"0"')),null!==e?(d=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=d),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=c)):(e=null,i=c),null!==e&&(f=u,e=parseFloat(n.substring(i,f))),null===e&&(i=u),e}function St(){var e,t,n,r,s,o,l,u;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],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 Et(){var e;return null===(e=k())&&null===(e=le())&&(e=Y()),e}function At(){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=k())))),e}function Rt(){var e;return null===(e=wt())&&(e=St()),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=k())),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=Nt())&&(e=kt()),e}function Nt(){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=Dt()))))),e}function kt(){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=Dt())),e}function Dt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){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=k())?e=[e,t]:(e=null,i=r),e}function xt(){var e;return null===(e=Dt())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=Y()),e}function Lt(){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 qt(){var e,t,r,s,l,u;if(l=i,null!==(e=D())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?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=D())?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=St()),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=k())?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=E()))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=k()))if(null!==(t=E()))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=k())&&null!==(t=M())?(null===(n=k())&&(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=$t())&&null===(e=Jt())&&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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,u,c,h,d;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=zt())){if(l=[],d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?u=[u,c]:(u=null,i=d);null!==u;){if(l.push(u),d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;null!==u&&null!==(c=zt())?u=[u,c]:(u=null,i=d)}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 zt(){var e;return null===(e=qe())&&(e=je()),e}function $t(){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=Xt())?e=[e,t,r]:(e=null,i=s),e}function Xt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Jt(){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=z())?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=k())),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,d,f;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(d=i,null!==(s=tn())){for(l=[],f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==u;)l.push(u),f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==l?s=[s,l]:(s=null,i=d)}else s=null,i=d;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=k())),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=St())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=St())?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=St()),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=St())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=St())?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=k()))),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=St()))),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=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=St()),e}function hn(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=bn())){for(r=[],u=i,null!==(s=G())&&null!==(o=dn())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=dn())?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 dn(){var e;return null===(e=fn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=St()),e}function fn(){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=An())?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=de()),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=k())?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=k())&&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=k()),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=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function bn(){var e,t,n,r,s;return r=i,null!==(e=Sn())?(s=i,null!==(t=W())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Sn(){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 En(){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 An(){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=St()),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=N())&&(t=E());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=E());return e}function Nn(){var e,t,r,s,l,u,c,h,d,f,_,p;return f=i,_=i,null!==(e=Dn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(d=Un())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=f,e[0],e=void(jn=n.substring(i+5,p))),null===e&&(i=f),e}function kn(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=f())&&null!==(n=f())&&null!==(r=f())?e=[e,t,n,r]:(e=null,i=s),e}function Dn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function xn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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=Ln())&&null===(e=qn())&&(e=St()),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=k())?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 Ln(){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=k())?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 qn(){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=Gn2&&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=d.cloneArray(r.extraHeaders),o=d.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 h.OutgoingRequest(c.MESSAGE,e,this._ua,null,i),t&&(this._request.body=t);var a=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),a.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=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.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=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.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=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.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){p.debug("MESSAGE failed"),this._close(),p.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){p.debug("MESSAGE succeeded"),this._close(),p.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27,events:30}],11:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),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":26}],12:[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=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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;w.debug("connect()");var r=e,s=v.cloneObject(t.eventHandlers),i=v.cloneArray(t.extraHeaders),o=v.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=v.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 p.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new p.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=v.newTag();var d=t.anonymous||!1,f={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:d,outbound:!0}),d?(f.from_display_name="Anonymous",f.from_uri=new R("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(f.from_uri=new R("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(f.from_display_name=t.fromDisplayName),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 y.InitialOutgoingInviteRequest(e,this._ua,f,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;w.debug("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=v.newTag(),this._createDialog(e,"UAS",!0)?(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,_.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,_.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("answer()");var n=this._request,r=v.cloneArray(t.extraHeaders),i=v.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=v.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=v.cloneObject(t.rtcOfferConstraints),h=!1,d=!1,f=!1,m=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new p.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new p.InvalidStateError(this._status);if(this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.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||(f=!0)),"video"===C.type&&(d=!0,C.direction&&"sendrecv"!==C.direction||(m=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var b,S=s(o.getAudioTracks());try{for(S.s();!(b=S.n()).done;){var E=b.value;o.removeTrack(E)}}catch(e){S.e(e)}finally{S.f()}}if(o&&!1===i.video){var A,R=s(o.getVideoTracks());try{for(R.s();!(A=R.n()).done;){var O=A.value;o.removeTrack(O)}}catch(e){R.e(e)}finally{R.f()}}o||void 0!==i.audio||(i.audio=f),o||void 0!==i.video||(i.video=m),o||h||c.offerToReceiveAudio||(i.audio=!1),o||d||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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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};w.debug('emit "sdp"'),e.emit("sdp",t);var r=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed("system",null,_.causes.WEBRTC_ERROR),w.warn('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,_.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&w.warn(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]:{};w.debug("terminate()");var n,r=t.cause||_.causes.BYE,s=v.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new p.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(w.debug("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||_.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,_.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(w.debug("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,_.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(w.debug("terminating session"),l=t.reason_phrase||_.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!==m.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===_.ACK&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===m.C.STATUS_TERMINATED&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(_.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]:{};w.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||_.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&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.InvalidStateError(this._status);if(i!==_.DTMF_TRANSPORT.INFO&&i!==_.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&&!v.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rb.C.MAX_DURATION?(w.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(b.C.MAX_DURATION," milliseconds")),r=b.C.MAX_DURATION):r=Math.abs(r):r=b.C.DEFAULT_DURATION,t.duration=r,s&&!v.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new b(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(w.debug("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.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};w.debug("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};w.debug("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(w.debug("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:_.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(w.debug("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:_.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;w.debug("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:_.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;w.debug("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 w.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(w.debug("receiveRequest()"),e.method===_.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,_.causes.CANCELED));else switch(e.method){case _.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:_.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",n);var r=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed("remote",e)}).catch(function(e){t.terminate({cause:_.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case _.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,_.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,_.causes.BYE)):e.reply(403,"Wrong Status");break;case _.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case _.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 b(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case _.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case _.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case _.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){w.warn("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.CONNECTION_ERROR,cause:_.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){w.warn("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:_.causes.REQUEST_TIMEOUT,cause:_.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){w.warn("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.DIALOG_ERROR,cause:_.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){w.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){w.debug("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(w.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(w.debug("_isReadyToReOffer() | session not established yet"),!1):(w.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(w.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(w.debug("close() | closing local MediaStream"),v.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){w.warn("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=g.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),ng.T2&&(n=g.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&&(w.debug("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(_.BYE),e._ended("remote",null,_.causes.NO_ACK))},g.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:_.causes.RTP_TIMEOUT,status_code:408,reason_phrase:_.causes.RTP_TIMEOUT})}),w.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(w.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return w.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return w.warn('emit "peerconnection:createanswerfailed" [error:%o]',e),n.emit("peerconnection:createanswerfailed",e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,w.warn('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 w.debug('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};w.debug('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()})})})}},{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 T(this,e,t,T.C.STATUS_EARLY)).error?(w.debug(o.error),this._failed("remote",e,_.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 T(this,e,t);return l.error?(w.debug(l.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;w.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("_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};w.debug('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.warn('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.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){w.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(w.debug("receiveRefer()"),!e.refer_to)return w.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==_.SIP)return w.debug("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);w.debug('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=v.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(w.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(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;w.debug("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(){w.debug("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new C(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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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,_.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,w.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&w.warn(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;w.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(w.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(_.ACK);var n=new T(this,e,"UAC");return void 0!==n.error?void w.debug(n.error):(this.sendRequest(_.ACK),void this.sendRequest(_.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){w.debug("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};w.debug('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.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=I.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,_.causes.MISSING_SDP),this._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};w.debug('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,_.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(_.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=v.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]:{};w.debug("sendReinvite()");var n=v.cloneArray(t.extraHeaders),r=v.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)};w.debug('emit "sdp"'),e.emit("sdp",s),e.sendRequest(_.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(_.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};w.debug('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.warn('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]:{};w.debug("sendUpdate()");var n=v.cloneArray(t.extraHeaders),r=v.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};w.debug('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.warn('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)};w.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(_.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(_.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){w.debug("acceptAndTerminate()");var r=[];t&&(n=n||_.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(_.ACK),this.sendRequest(_.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=d.parse(e),this._localHold&&!this._remoteHold){w.debug("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){w.debug("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){w.debug("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 d.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>=_.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>=_.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&&(w.debug("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===_.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w.warn("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:_.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){w.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){w.debug("session connecting"),w.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){w.debug("session progress"),w.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){w.debug("session accepted"),this._start_time=new Date,w.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){w.debug("session confirmed"),this._is_confirmed=!0,w.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){w.debug("session ended"),this._end_time=new Date,this._close(),w.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){w.debug("session failed"),w.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),w.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){w.debug("session onhold"),this._setLocalMediaStatus(),w.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){w.debug("session onunhold"),this._setLocalMediaStatus(),w.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onmute"),this._setLocalMediaStatus(),w.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onunmute"),this._setLocalMediaStatus(),w.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return I}},{key:"causes",get:function(){return _.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,"./Logger":9,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":22,"./Transactions":23,"./URI":26,"./Utils":27,events:30,"sdp-transform":36}],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;n1&&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 h.InvalidStateError(this._session.status);var r=d.cloneArray(n.extraHeaders);if(this.eventHandlers=d.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(c.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=_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):f.debug("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),a}(),t.exports.C=_},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":27,events:30}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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),d}()},{"../Constants":2,"../Exceptions":6,"../Utils":27,events:30}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(i.NOTIFY,{extraHeaders:["Event: ".concat(l.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(l.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"../Constants":2,"../Logger":9}],17:[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;n1&&void 0!==arguments[1]?arguments[1]:{};f.debug("sendRefer()");var r=d.cloneArray(n.extraHeaders),s=d.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):"",">");if(r.push(l),!r.some(function(e){return e.toLowerCase().startsWith("referred-by:")})){var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u)}r.push("Contact: ".concat(this._session.contact));var a=this._session.sendRequest(c.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,c.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,c.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,c.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,c.causes.DIALOG_ERROR)}}});this._id=a.cseq}},{key:"receiveNotify",value:function(e){if(f.debug("receiveNotify()"),e.body){var t=h.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.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){f.debug("REFER succeeded"),f.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){f.debug("REFER failed"),f.debug('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),a}()},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":27,events:30}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,s;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)a.debug("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var n=new l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new u(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,o.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")){a.debug("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a.debug("no Contact header pointing to us, response ignored");break}var s=r.getParam("expires");!s&&t.hasHeader("expires")&&(s=t.getHeader("expires")),s||(s=e._expires),(s=Number(s))<10&&(s=10);var l=s>64?1e3*s/2+Math.floor(1e3*(s/2-32)*Math.random()):1e3*s-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,o.causes.SIP_FAILURE_CODE));break;default:var u=i.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new u(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,o.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=i.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else a.debug("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}},{key:"_unregistered",value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:"registered",get:function(){return this._registered}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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")),this.setHeader("via",""),this.setHeader("max-forwards",p.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 v(l,a,u),this.setHeader("to",this.to.toString());var h,d=s.from_uri||r.configuration.uri,f={tag:s.from_tag||m.newTag()};h=void 0!==s.from_display_name?s.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new v(d,h,f),this.setHeader("from",this.from.toString());var _=s.call_id||r.configuration.jssip_id+m.createRandomToken(15);this.call_id=_,this.setHeader("call-id",_);var g=s.cseq||Math.floor(1e4*Math.random());this.cseq=g,this.setHeader("cseq","".concat(g," ").concat(t))}return d(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(e=m.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=g.parse(r,e.replace(/-/g,"_"));return-1===s?(this.headers[e].splice(t,1),void y.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=s,s)}y.debug('not so many "'.concat(e,'" headers present'))}else y.debug('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[m.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=f.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),e}(),S=function(e){s(n,b);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 d(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||p.REASON_PHRASE[e]||"",n=m.cloneArray(n);var a="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===p.INVITE&&e>100&&e<=200){var c,h=u(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var d=c.value;a+="Record-Route: ".concat(d,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var f,_=u(this.getHeaders("via"));try{for(_.s();!(f=_.n()).done;){var v=f.value;a+="Via: ".concat(v,"\r\n")}}catch(e){_.e(e)}finally{_.f()}!this.to_tag&&e>100?l+=";tag=".concat(m.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 p.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 p.UPDATE:this.ua.configuration.session_timers&&o.push("timer"),r&&o.push("ice"),o.push("replaces")}if(o.push("outbound"),this.method===p.OPTIONS?(a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(o,"\r\n"),r){var C=m.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||p.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(m.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,b);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:T,InitialOutgoingInviteRequest:C,IncomingRequest:S,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":27,"sdp-transform":36}],21:[function(e,t,n){"use strict";var r=e("./Logger"),s=e("./Utils"),i=e("./Grammar"),o=new r("Socket");n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return o.warn("undefined JsSIP.Socket instance"),!1;try{if(!s.isString(e.url))throw o.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!s.isString(e.via_transport))throw o.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===i.parse(e.sip_uri,"SIP_URI"))throw o.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!s.isFunction(e[t]))throw o.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch(e){return!1}return!0}},{"./Grammar":7,"./Logger":9,"./Utils":27}],22:[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}},{}],23:[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=100&&n<=199)switch(this.state){case b.STATUS_CALLING:this.stateChanged(b.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},m.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return b}}]),n}(),A=function(e){l(n,d);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(){y.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return b}}]),n}(),R=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){T.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,T.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case b.STATUS_TRYING:this.stateChanged(b.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case b.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 b.STATUS_TRYING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){s.timer_J()},m.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case b.STATUS_COMPLETED:}}},{key:"C",get:function(){return b}}]),n}(),w=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){C.debug("Timer H expired for transaction ".concat(this.id)),this.state===b.STATUS_COMPLETED&&C.debug("ACK not received, dialog will be terminated"),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){C.debug("Timer L expired for transaction ".concat(this.id)),this.state===b.STATUS_ACCEPTED&&(this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,C.debug("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(b.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 b.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===b.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){s.resend_provisional()},m.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){s.timer_L()},m.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case b.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case b.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(b.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},m.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:"C",get:function(){return b}}]),n}();t.exports={C:b,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:R,InviteServerTransaction:w,checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case _.INVITE:if(n=r.ist[t.via_branch]){switch(n.state){case b.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case b.STATUS_ACCEPTED:}return!0}break;case _.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===b.STATUS_ACCEPTED)return!1;if(n.state===b.STATUS_COMPLETED)return n.state=b.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},m.TIMER_I),!0;break;case _.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==b.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case b.STATUS_TRYING:break;case b.STATUS_PROCEEDING:case b.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Timers":22,events:30}],24:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),l.debug("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){l.warn("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!i.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,s;return t=e,(n=[{key:"connect",value:function(){l.debug("connect()"),this.isConnected()?l.debug("Transport is already connected"):this.isConnecting()?l.debug("Transport is connecting"):(this.close_requested=!1,this.status=u.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.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.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.debug("send()"),!this.isConnected())return l.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return l.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),l.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void l.debug("received binary message failed to be converted into string, message discarded")}l.debug("received binary message:\n\n".concat(e,"\n"))}else l.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else l.debug("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}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./Socket":21}],25:[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;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(E.settings,i))switch(i){case"uri":case"registrar_server":A.debug("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A.debug("- ".concat(i,": NOT SHOWN"));break;default:A.debug("- ".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,"./Logger":9,"./Message":10,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Transactions":23,"./Transport":24,"./URI":26,"./Utils":27,"./sanityCheck":29,events:30}],26:[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);n4&&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":27}],27:[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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,d,f,_,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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":26}],28:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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);n1)return d.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=h.str_utf8_length(i.body),t=i.getHeader("content-length");if(e0&&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 d(){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;t1&&(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=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=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):[]}},{}],31:[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":32,_process:34}],32:[function(e,t,n){t.exports=function(t){function n(e){let t=0;for(let n=0;n{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{r[e]=t[e]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}},{ms:33}],33:[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))}},{}],34:[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,d=-1;function f(){h&&a&&(h=!1,a.length?c=a.concat(c):d=-1,c.length&&_())}function _(){if(!h){var e=u(f);h=!0;for(var t=c.length;t;){for(a=c,c=[];++d1)for(var n=1;n1&&(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=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":35}],39:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.11",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file From ff125ec257da7cb09c54d5f32cc1416d1e4d35f2 Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 26 Jun 2021 13:44:11 +0300 Subject: [PATCH 49/70] minor code improvement --- dist/jssip.js | 2803 ++++++++++++++++++++++++++++++--------------- dist/jssip.min.js | 4 +- lib/Notifier.js | 26 +- lib/Subscriber.js | 63 +- 4 files changed, 1909 insertions(+), 987 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index d2cb750d2..4dbcca163 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -1,5 +1,5 @@ /* - * JsSIP v3.7.11 + * JsSIP v3.7.6 * the Javascript SIP library * Copyright: 2012-2021 * Homepage: https://jssip.net @@ -9,7 +9,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -294,7 +294,7 @@ exports.load = function (dst, src) { } } }; -},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":26,"./Utils":27}],2:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],2:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -462,7 +462,7 @@ module.exports = { 604: 'Does Not Exist Anywhere', 606: 'Not Acceptable' }, - ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY', + ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE', ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay', MAX_FORWARDS: 69, SESSION_EXPIRES: 90, @@ -470,7 +470,7 @@ module.exports = { CONNECTION_RECOVERY_MAX_INTERVAL: 30, CONNECTION_RECOVERY_MIN_INTERVAL: 2 }; -},{"../package.json":39}],3:[function(require,module,exports){ +},{"../package.json":40}],3:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -479,8 +479,6 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Logger = require('./Logger'); - var SIPMessage = require('./SIPMessage'); var JsSIP_C = require('./Constants'); @@ -491,7 +489,8 @@ var Dialog_RequestSender = require('./Dialog/RequestSender'); var Utils = require('./Utils'); -var logger = new Logger('Dialog'); +var debug = require('debug')('JsSIP:Dialog'); + var C = { // Dialog states. STATUS_EARLY: 1, @@ -499,14 +498,6 @@ var C = { }; // RFC 3261 12.1. module.exports = /*#__PURE__*/function () { - _createClass(Dialog, null, [{ - key: "C", - // Expose C object. - get: function get() { - return C; - } - }]); - function Dialog(owner, message, type) { var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; @@ -566,14 +557,45 @@ module.exports = /*#__PURE__*/function () { this._ua.newDialog(this); - logger.debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); + debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); } _createClass(Dialog, [{ + key: "id", + get: function get() { + return this._id; + } + }, { + key: "local_seqnum", + get: function get() { + return this._local_seqnum; + }, + set: function set(num) { + this._local_seqnum = num; + } + }, { + key: "owner", + get: function get() { + return this._owner; + } + }, { + key: "uac_pending_reply", + get: function get() { + return this._uac_pending_reply; + }, + set: function set(pending) { + this._uac_pending_reply = pending; + } + }, { + key: "uas_pending_reply", + get: function get() { + return this._uas_pending_reply; + } + }, { key: "update", value: function update(message, type) { this._state = C.STATUS_CONFIRMED; - logger.debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); + debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); if (type === 'UAC') { // RFC 3261 13.2.2.4. @@ -583,7 +605,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "terminate", value: function terminate() { - logger.debug("dialog ".concat(this._id.toString(), " deleted")); + debug("dialog ".concat(this._id.toString(), " deleted")); this._ua.destroyDialog(this); } @@ -714,42 +736,17 @@ module.exports = /*#__PURE__*/function () { return true; } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "local_seqnum", - get: function get() { - return this._local_seqnum; - }, - set: function set(num) { - this._local_seqnum = num; - } - }, { - key: "owner", - get: function get() { - return this._owner; - } - }, { - key: "uac_pending_reply", - get: function get() { - return this._uac_pending_reply; - }, - set: function set(pending) { - this._uac_pending_reply = pending; - } - }, { - key: "uas_pending_reply", - get: function get() { - return this._uas_pending_reply; + }], [{ + key: "C", + get: // Expose C object. + function get() { + return C; } }]); return Dialog; }(); -},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":20,"./Transactions":23,"./Utils":27}],4:[function(require,module,exports){ +},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,"debug":32}],4:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -798,6 +795,11 @@ module.exports = /*#__PURE__*/function () { } _createClass(DialogRequestSender, [{ + key: "request", + get: function get() { + return this._request; + } + }, { key: "send", value: function send() { var _this = this; @@ -863,16 +865,11 @@ module.exports = /*#__PURE__*/function () { this._eventHandlers.onErrorResponse(response); } } - }, { - key: "request", - get: function get() { - return this._request; - } }]); return DialogRequestSender; }(); -},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":23}],5:[function(require,module,exports){ +},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -881,11 +878,13 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Logger = require('./Logger'); - var Utils = require('./Utils'); -var logger = new Logger('DigestAuthentication'); +var debug = require('debug')('JsSIP:DigestAuthentication'); + +var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); + +debugerror.log = console.warn.bind(console); module.exports = /*#__PURE__*/function () { function DigestAuthentication(credentials) { @@ -918,7 +917,7 @@ module.exports = /*#__PURE__*/function () { return this._ha1; default: - logger.warn('get() | cannot get "%s" parameter', parameter); + debugerror('get() | cannot get "%s" parameter', parameter); return undefined; } } @@ -945,7 +944,7 @@ module.exports = /*#__PURE__*/function () { if (this._algorithm) { if (this._algorithm !== 'MD5') { - logger.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); + debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); return false; } } else { @@ -953,12 +952,12 @@ module.exports = /*#__PURE__*/function () { } if (!this._nonce) { - logger.warn('authenticate() | challenge without Digest nonce, authentication aborted'); + debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); return false; } if (!this._realm) { - logger.warn('authenticate() | challenge without Digest realm, authentication aborted'); + debugerror('authenticate() | challenge without Digest realm, authentication aborted'); return false; } // If no plain SIP password is provided. @@ -966,13 +965,13 @@ module.exports = /*#__PURE__*/function () { if (!this._credentials.password) { // If ha1 is not provided we cannot authenticate. if (!this._credentials.ha1) { - logger.warn('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); + debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); return false; } // If the realm does not match the stored realm we cannot authenticate. if (this._credentials.realm !== this._realm) { - logger.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm); + debugerror('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); return false; } } // 'qop' can contain a list of values (Array). Let's choose just one. @@ -985,7 +984,7 @@ module.exports = /*#__PURE__*/function () { this._qop = 'auth'; } else { // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. - logger.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); + debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); return false; } } else { @@ -1022,26 +1021,26 @@ module.exports = /*#__PURE__*/function () { // HA2 = MD5(A2) = MD5(method:digestURI). a2 = "".concat(this._method, ":").concat(this._uri); ha2 = Utils.calculateMD5(a2); - logger.debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2)); } else if (this._qop === 'auth-int') { // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)). a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : '')); ha2 = Utils.calculateMD5(a2); - logger.debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2)); } else if (this._qop === null) { // HA2 = MD5(A2) = MD5(method:digestURI). a2 = "".concat(this._method, ":").concat(this._uri); ha2 = Utils.calculateMD5(a2); - logger.debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). + debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2)); } - logger.debug('authenticate() | response generated'); + debug('authenticate() | response generated'); return true; } /** @@ -1080,7 +1079,7 @@ module.exports = /*#__PURE__*/function () { return DigestAuthentication; }(); -},{"./Logger":9,"./Utils":27}],6:[function(require,module,exports){ +},{"./Utils":28,"debug":32}],6:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -1099,7 +1098,7 @@ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } @@ -16097,7 +16096,7 @@ module.exports = function () { result.SyntaxError.prototype = Error.prototype; return result; }(); -},{"./NameAddrHeader":11,"./URI":26}],8:[function(require,module,exports){ +},{"./NameAddrHeader":10,"./URI":27}],8:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -16146,61 +16145,7 @@ module.exports = { } }; -},{"../package.json":39,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":11,"./UA":25,"./URI":26,"./Utils":27,"./WebSocketInterface":28,"debug":31}],9:[function(require,module,exports){ -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var debug = require('debug'); - -var APP_NAME = 'JsSIP'; - -module.exports = /*#__PURE__*/function () { - function Logger(prefix) { - _classCallCheck(this, Logger); - - if (prefix) { - this._debug = debug["default"]("".concat(APP_NAME, ":").concat(prefix)); - this._warn = debug["default"]("".concat(APP_NAME, ":WARN:").concat(prefix)); - this._error = debug["default"]("".concat(APP_NAME, ":ERROR:").concat(prefix)); - } else { - this._debug = debug["default"](APP_NAME); - this._warn = debug["default"]("".concat(APP_NAME, ":WARN")); - this._error = debug["default"]("".concat(APP_NAME, ":ERROR")); - } - /* eslint-disable no-console */ - - - this._debug.log = console.info.bind(console); - this._warn.log = console.warn.bind(console); - this._error.log = console.error.bind(console); - /* eslint-enable no-console */ - } - - _createClass(Logger, [{ - key: "debug", - get: function get() { - return this._debug; - } - }, { - key: "warn", - get: function get() { - return this._warn; - } - }, { - key: "error", - get: function get() { - return this._error; - } - }]); - - return Logger; -}(); -},{"debug":31}],10:[function(require,module,exports){ +},{"../package.json":40,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":26,"./URI":27,"./Utils":28,"./WebSocketInterface":29,"debug":32}],9:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -16221,14 +16166,12 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; -var Logger = require('./Logger'); - var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); @@ -16239,7 +16182,7 @@ var RequestSender = require('./RequestSender'); var Exceptions = require('./Exceptions'); -var logger = new Logger('Message'); +var debug = require('debug')('JsSIP:Message'); module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(Message, _EventEmitter); @@ -16266,6 +16209,21 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Message, [{ + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { key: "send", value: function send(target, body) { var _this2 = this; @@ -16465,11 +16423,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_failed", value: function _failed(originator, response, cause) { - logger.debug('MESSAGE failed'); + debug('MESSAGE failed'); this._close(); - logger.debug('emit "failed"'); + debug('emit "failed"'); this.emit('failed', { originator: originator, response: response || null, @@ -16479,36 +16437,21 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_succeeded", value: function _succeeded(originator, response) { - logger.debug('MESSAGE succeeded'); + debug('MESSAGE succeeded'); this._close(); - logger.debug('emit "succeeded"'); + debug('emit "succeeded"'); this.emit('succeeded', { originator: originator, response: response }); } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } }]); return Message; }(EventEmitter); -},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27,"events":30}],11:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],10:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -16522,24 +16465,6 @@ var URI = require('./URI'); var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { - _createClass(NameAddrHeader, null, [{ - key: "parse", - - /** - * Parse the given string and returns a NameAddrHeader instance or undefined if - * it is an invalid NameAddrHeader. - */ - value: function parse(name_addr_header) { - name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); - - if (name_addr_header !== -1) { - return name_addr_header; - } else { - return undefined; - } - } - }]); - function NameAddrHeader(uri, display_name, parameters) { _classCallCheck(this, NameAddrHeader); @@ -16561,6 +16486,19 @@ module.exports = /*#__PURE__*/function () { } _createClass(NameAddrHeader, [{ + key: "uri", + get: function get() { + return this._uri; + } + }, { + key: "display_name", + get: function get() { + return this._display_name; + }, + set: function set(value) { + this._display_name = value === 0 ? '0' : value; + } + }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -16625,94 +16563,498 @@ module.exports = /*#__PURE__*/function () { return body; } - }, { - key: "uri", - get: function get() { - return this._uri; - } - }, { - key: "display_name", - get: function get() { - return this._display_name; - }, - set: function set(value) { - this._display_name = value === 0 ? '0' : value; + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a NameAddrHeader instance or undefined if + * it is an invalid NameAddrHeader. + */ + function parse(name_addr_header) { + name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); + + if (name_addr_header !== -1) { + return name_addr_header; + } else { + return undefined; + } } }]); return NameAddrHeader; }(); -},{"./Grammar":7,"./URI":26}],12:[function(require,module,exports){ +},{"./Grammar":7,"./URI":27}],11:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } -var Logger = require('./Logger'); +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Grammar = require('./Grammar'); +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } -var SIPMessage = require('./SIPMessage'); +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } -var logger = new Logger('Parser'); -/** - * Parse SIP Message - */ +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } -exports.parseMessage = function (data, ua) { - var message; - var bodyStart; - var headerEnd = data.indexOf('\r\n'); +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - if (headerEnd === -1) { - logger.warn('parseMessage() | no CRLF found, not a SIP message'); - return; - } // Parse first line. Check if it is a Request or a Reply. +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - var firstLine = data.substring(0, headerEnd); - var parsed = Grammar.parse(firstLine, 'Request_Response'); +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - if (parsed === -1) { - logger.warn("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); - return; - } else if (!parsed.status_code) { - message = new SIPMessage.IncomingRequest(ua); - message.method = parsed.method; - message.ruri = parsed.uri; - } else { - message = new SIPMessage.IncomingResponse(); - message.status_code = parsed.status_code; - message.reason_phrase = parsed.reason_phrase; - } +var EventEmitter = require('events').EventEmitter; - message.data = data; - var headerStart = headerEnd + 2; - /* Loop over every line in data. Detect the end of each header and parse - * it or simply add to the headers collection. - */ +var JsSIP_C = require('./Constants'); - while (true) { - headerEnd = getHeader(data, headerStart); // The SIP message has normally finished. +var Utils = require('./Utils'); - if (headerEnd === -2) { - bodyStart = headerStart + 2; - break; - } // Data.indexOf returned -1 due to a malformed message. - else if (headerEnd === -1) { - logger.warn('parseMessage() | malformed message'); - return; - } +var Dialog = require('./Dialog'); - parsed = parseHeader(message, data, headerStart, headerEnd); +var debug = require('debug')('JsSIP:Notifier'); - if (parsed !== true) { - logger.warn('parseMessage() |', parsed.error); - return; - } +var debugerror = require('debug')('JsSIP:ERROR:Notifier'); + +debugerror.log = console.warn.bind(console); +/** + * Termination codes. + */ + +var C = { + // Termination codes. + NOTIFY_RESPONSE_TIMEOUT: 0, + NOTIFY_TRANSPORT_ERROR: 1, + NOTIFY_NON_OK_RESPONSE: 2, + NOTIFY_FAILED_AUTHENTICATION: 3, + SEND_FINAL_NOTIFY: 4, + RECEIVE_UNSUBSCRIBE: 5, + SUBSCRIPTION_EXPIRED: 6, + // Notifer states + STATE_PENDING: 0, + STATE_ACTIVE: 1, + STATE_TERMINATED: 2 +}; +/** + * RFC 6665 Notifier implementation. + */ + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Notifier, _EventEmitter); + + var _super = _createSuper(Notifier); + + /** + * @param {UA} ua - JsSIP User Agent instance. + * @param {IncomingRequest} subscribe - Subscribe request. + * @param {string} contentType - Content-Type header value. + * @param {NotifierOptions} options - Optional parameters. + * @param {Array} extraHeaders - Additional SIP headers. + * @param {string} allowEvents - Allow-Events header value. + * @param {boolean} pending - Set initial dialog state as "pending". + */ + function Notifier(ua, subscribe, contentType, _ref) { + var _this; + + var extraHeaders = _ref.extraHeaders, + allowEvents = _ref.allowEvents, + pending = _ref.pending; + + _classCallCheck(this, Notifier); + + debug('new'); + _this = _super.call(this); + + if (!subscribe) { + throw new TypeError('subscribe is undefined'); + } + + if (!contentType) { + throw new TypeError('contentType is undefined'); + } + + _this._ua = ua; + _this._initial_subscribe = subscribe; + _this._expires_timestamp = null; + _this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait. + + _this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; // Optional. Used to build terminated Subscription-State. + + _this._terminated_reason = null; + _this._terminated_retry_after = null; // Custom session empty object for high level use. + + _this.data = {}; + _this._dialog = null; + var eventName = subscribe.getHeader('event'); + _this._content_type = contentType; + _this._expires = parseInt(subscribe.getHeader('expires')); + _this._headers = Utils.cloneArray(extraHeaders); + + _this._headers.push("Event: ".concat(eventName)); // Use contact from extraHeaders or create it. + + + _this._contact = _this._headers.find(function (header) { + return header.startsWith('Contact'); + }); + + if (!_this._contact) { + _this._contact = "Contact: "); + + _this._headers.push(_this._contact); + } + + if (allowEvents) { + _this._headers.push("Allow-Events: ".concat(allowEvents)); + } + + _this._target = subscribe.from.uri.user; + subscribe.to_tag = Utils.newTag(); // Create dialog for normal and fetch-subscribe. + + var dialog = new Dialog(_assertThisInitialized(_this), subscribe, 'UAS'); + + if (dialog.error) { + debugerror(dialog.error); + throw new Error('SUBSCRIBE missed Contact'); + } + + _this._dialog = dialog; + + if (_this._expires > 0) { + // Set expires timer and time-stamp. + _this._setExpiresTimer(); + } + + return _this; + } + /** + * Dialog callback. + * Called also for initial subscribe. + * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). + */ + + + _createClass(Notifier, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + if (request.method !== JsSIP_C.SUBSCRIBE) { + request.reply(405); + return; + } + + var expiresValue = request.getHeader('expires'); + + if (expiresValue === undefined || expiresValue === null) { + // Missed header Expires. RFC 6665 3.1.1. Set default expires value. + expiresValue = '900'; + debug("Missed expires header. Set by default ".concat(expiresValue)); + } + + this._expires = parseInt(expiresValue); + request.reply(200, null, ["Expires: ".concat(this._expires), "".concat(this._contact)]); + var body = request.body; + var content_type = request.getHeader('content-type'); + var is_unsubscribe = this._expires === 0; + + if (!is_unsubscribe) { + this._setExpiresTimer(); + } + + debug('emit "subscribe"'); + this.emit('subscribe', is_unsubscribe, request, body, content_type); + + if (is_unsubscribe) { + this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); + } + } + /** + * User API + */ + + /** + * Please call after creating the Notifier instance and setting the event handlers. + */ + + }, { + key: "start", + value: function start() { + debug('start()'); + this.receiveRequest(this._initial_subscribe); + } + /** + * Switch pending dialog state to active. + */ + + }, { + key: "setActiveState", + value: function setActiveState() { + debug('setActiveState()'); + + if (this._state === C.STATE_PENDING) { + this._state = C.STATE_ACTIVE; + } + } + /** + * Send the initial and subsequent notify request. + * @param {string} body - notify request body. + */ + + }, { + key: "notify", + value: function notify() { + var _this2 = this; + + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + debug('notify()'); // Prevent send notify after final notify. + + if (!this._dialog) { + debugerror('final notify has sent'); + return; + } + + var subs_state = this._stateNumberToString(this._state); + + if (this._state !== C.STATE_TERMINATED) { + var expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); + + if (expires < 0) { + expires = 0; + } + + subs_state += ";expires=".concat(expires); + } else { + if (this._terminated_reason) { + subs_state += ";reason=".concat(this._terminated_reason); + } + + if (this._terminated_retry_after !== null) { + subs_state += ";retry-after=".concat(this._terminated_retry_after); + } + } + + var headers = this._headers.slice(); + + headers.push("Subscription-State: ".concat(subs_state)); + + if (body) { + headers.push("Content-Type: ".concat(this._content_type)); + } + + this._dialog.sendRequest(JsSIP_C.NOTIFY, { + body: body, + extraHeaders: headers, + eventHandlers: { + onRequestTimeout: function onRequestTimeout() { + _this2._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); + }, + onTransportError: function onTransportError() { + _this2._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); + }, + onErrorResponse: function onErrorResponse(response) { + if (response.status_code === 401 || response.status_code === 407) { + _this2._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); + } else { + _this2._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); + } + }, + onDialogError: function onDialogError() { + _this2._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); + } + } + }); + } + /** + * Terminate. (Send the final NOTIFY request). + * + * @param {string} body - Notify message body. + * @param {string} reason - Set Subscription-State reason parameter. + * @param {number} retryAfter - Set Subscription-State retry-after parameter. + */ + + }, { + key: "terminate", + value: function terminate() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + debug('terminate()'); + this._state = C.STATE_TERMINATED; + this._terminated_reason = reason; + this._terminated_retry_after = retryAfter; + this.notify(body); + + this._dialogTerminated(C.SEND_FINAL_NOTIFY); + } + /** + * Get dialog state. + */ + + }, { + key: "state", + get: function get() { + return this._state; + } + /** + * Get dialog id. + */ + + }, { + key: "id", + get: function get() { + return this._dialog ? this._dialog.id : null; + } + /** + * Private API + */ + + }, { + key: "_dialogTerminated", + value: function _dialogTerminated(termination_code) { + if (!this._dialog) { + return; + } + + this._state = C.STATE_TERMINATED; + clearTimeout(this._expires_timer); + + if (this._dialog) { + this._dialog.terminate(); + + this._dialog = null; + } + + var send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; + debug("emit \"terminated\" code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); + this.emit('terminated', termination_code, send_final_notify); + } + }, { + key: "_setExpiresTimer", + value: function _setExpiresTimer() { + var _this3 = this; + + this._expires_timestamp = new Date().getTime() + this._expires * 1000; + clearTimeout(this._expires_timer); + this._expires_timer = setTimeout(function () { + if (!_this3._dialog) { + return; + } + + _this3._terminated_reason = 'timeout'; + + _this3.notify(); + + _this3._dialogTerminated(C.SUBSCRIPTION_EXPIRED); + }, this._expires * 1000); + } + }, { + key: "_stateNumberToString", + value: function _stateNumberToString(state) { + switch (state) { + case C.STATE_PENDING: + return 'pending'; + + case C.STATE_ACTIVE: + return 'active'; + + case C.STATE_TERMINATED: + return 'terminated'; + + default: + throw new TypeError('wrong state value'); + } + } + }], [{ + key: "C", + get: + /** + * Expose C object. + */ + function get() { + return C; + } + }]); + + return Notifier; +}(EventEmitter); +},{"./Constants":2,"./Dialog":3,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ +"use strict"; + +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +var Grammar = require('./Grammar'); + +var SIPMessage = require('./SIPMessage'); + +var debugerror = require('debug')('JsSIP:ERROR:Parser'); + +debugerror.log = console.warn.bind(console); +/** + * Parse SIP Message + */ + +exports.parseMessage = function (data, ua) { + var message; + var bodyStart; + var headerEnd = data.indexOf('\r\n'); + + if (headerEnd === -1) { + debugerror('parseMessage() | no CRLF found, not a SIP message'); + return; + } // Parse first line. Check if it is a Request or a Reply. + + + var firstLine = data.substring(0, headerEnd); + var parsed = Grammar.parse(firstLine, 'Request_Response'); + + if (parsed === -1) { + debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); + return; + } else if (!parsed.status_code) { + message = new SIPMessage.IncomingRequest(ua); + message.method = parsed.method; + message.ruri = parsed.uri; + } else { + message = new SIPMessage.IncomingResponse(); + message.status_code = parsed.status_code; + message.reason_phrase = parsed.reason_phrase; + } + + message.data = data; + var headerStart = headerEnd + 2; + /* Loop over every line in data. Detect the end of each header and parse + * it or simply add to the headers collection. + */ + + while (true) { + headerEnd = getHeader(data, headerStart); // The SIP message has normally finished. + + if (headerEnd === -2) { + bodyStart = headerStart + 2; + break; + } // Data.indexOf returned -1 due to a malformed message. + else if (headerEnd === -1) { + debugerror('parseMessage() | malformed message'); + return; + } + + parsed = parseHeader(message, data, headerStart, headerEnd); + + if (parsed !== true) { + debugerror('parseMessage() |', parsed.error); + return; + } headerStart = headerEnd + 2; } @@ -16974,12 +17316,12 @@ function parseHeader(message, data, headerStart, headerEnd) { return true; } } -},{"./Grammar":7,"./Logger":9,"./SIPMessage":20}],13:[function(require,module,exports){ +},{"./Grammar":7,"./SIPMessage":20,"debug":32}],13:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -17001,7 +17343,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -17010,8 +17352,6 @@ var EventEmitter = require('events').EventEmitter; var sdp_transform = require('sdp-transform'); -var Logger = require('./Logger'); - var JsSIP_C = require('./Constants'); var Exceptions = require('./Exceptions'); @@ -17038,8 +17378,12 @@ var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); var URI = require('./URI'); -var logger = new Logger('RTCSession'); -var C = { +var debug = require('debug')('JsSIP:RTCSession'); + +var debugerror = require('debug')('JsSIP:ERROR:RTCSession'); + +debugerror.log = console.warn.bind(console); +var C = { // RTCSession states. STATUS_NULL: 0, STATUS_INVITE_SENT: 1, @@ -17063,23 +17407,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(RTCSession); - _createClass(RTCSession, null, [{ - key: "C", - - /** - * Expose C object. - */ - get: function get() { - return C; - } - }]); - function RTCSession(ua) { var _this; _classCallCheck(this, RTCSession); - logger.debug('new'); + debug('new'); _this = _super.call(this); _this._id = null; _this._ua = ua; @@ -17153,6 +17486,70 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _createClass(RTCSession, [{ + key: "C", + get: function get() { + return C; + } // Expose session failed/ended causes as a property of the RTCSession instance. + + }, { + key: "causes", + get: function get() { + return JsSIP_C.causes; + } + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "connection", + get: function get() { + return this._connection; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "start_time", + get: function get() { + return this._start_time; + } + }, { + key: "end_time", + get: function get() { + return this._end_time; + } + }, { + key: "data", + get: function get() { + return this._data; + }, + set: function set(_data) { + this._data = _data; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { key: "isInProgress", value: function isInProgress() { switch (this._status) { @@ -17213,7 +17610,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function connect(target) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var initCallback = arguments.length > 2 ? arguments[2] : undefined; - logger.debug('connect()'); + debug('connect()'); var originalTarget = target; var eventHandlers = Utils.cloneObject(options.eventHandlers); var extraHeaders = Utils.cloneArray(options.extraHeaders); @@ -17326,7 +17723,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function init_incoming(request, initCallback) { var _this2 = this; - logger.debug('init_incoming()'); + debug('init_incoming()'); var expires; var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type. @@ -17417,7 +17814,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this3 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - logger.debug('answer()'); + debug('answer()'); var request = this._request; var extraHeaders = Utils.cloneArray(options.extraHeaders); var mediaConstraints = Utils.cloneObject(options.mediaConstraints); @@ -17582,7 +17979,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - logger.warn('emit "getusermediafailed" [error:%o]', error); + debugerror('emit "getusermediafailed" [error:%o]', error); _this3.emit('getusermediafailed', error); @@ -17613,7 +18010,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: request.body }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); _this3.emit('sdp', e); @@ -17628,7 +18025,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); - logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this3.emit('peerconnection:setremotedescriptionfailed', error); @@ -17679,7 +18076,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - logger.warn(error); + debugerror(error); }); } /** @@ -17692,7 +18089,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this4 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - logger.debug('terminate()'); + debug('terminate()'); var cause = options.cause || JsSIP_C.causes.BYE; var extraHeaders = Utils.cloneArray(options.extraHeaders); var body = options.body; @@ -17709,7 +18106,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_NULL: case C.STATUS_INVITE_SENT: case C.STATUS_1XX_RECEIVED: - logger.debug('canceling session'); + debug('canceling session'); if (status_code && (status_code < 200 || status_code >= 700)) { throw new TypeError("Invalid status_code: ".concat(status_code)); @@ -17735,7 +18132,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_WAITING_FOR_ANSWER: case C.STATUS_ANSWERED: - logger.debug('rejecting session'); + debug('rejecting session'); status_code = status_code || 480; if (status_code < 300 || status_code >= 700) { @@ -17750,7 +18147,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_WAITING_FOR_ACK: case C.STATUS_CONFIRMED: - logger.debug('terminating session'); + debug('terminating session'); reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; if (status_code && (status_code < 200 || status_code >= 700)) { @@ -17816,7 +18213,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendDTMF", value: function sendDTMF(tones) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - logger.debug('sendDTMF() | tones: %s', tones); + debug('sendDTMF() | tones: %s', tones); var position = 0; var duration = options.duration || null; var interToneGap = options.interToneGap || null; @@ -17827,7 +18224,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } // Check Session Status. - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_1XX_RECEIVED) { + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { throw new Exceptions.InvalidStateError(this._status); } // Check Transport type. @@ -17852,10 +18249,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } else if (!duration) { duration = RTCSession_DTMF.C.DEFAULT_DURATION; } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { - logger.debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); + debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); duration = RTCSession_DTMF.C.MIN_DURATION; } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { - logger.debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); + debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); duration = RTCSession_DTMF.C.MAX_DURATION; } else { duration = Math.abs(duration); @@ -17868,7 +18265,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } else if (!interToneGap) { interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP; } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { - logger.debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); + debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; } else { interToneGap = Math.abs(interToneGap); @@ -17935,9 +18332,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendInfo", value: function sendInfo(contentType, body) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - logger.debug('sendInfo()'); // Check Session Status. + debug('sendInfo()'); // Check Session Status. - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_1XX_RECEIVED) { + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { throw new Exceptions.InvalidStateError(this._status); } @@ -17955,7 +18352,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { audio: true, video: false }; - logger.debug('mute()'); + debug('mute()'); var audioMuted = false, videoMuted = false; @@ -17991,7 +18388,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { audio: true, video: true }; - logger.debug('unmute()'); + debug('unmute()'); var audioUnMuted = false, videoUnMuted = false; @@ -18031,7 +18428,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - logger.debug('hold()'); + debug('hold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { return false; @@ -18086,7 +18483,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - logger.debug('unhold()'); + debug('unhold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { return false; @@ -18141,7 +18538,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - logger.debug('renegotiate()'); + debug('renegotiate()'); var rtcOfferConstraints = options.rtcOfferConstraints || null; if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -18195,7 +18592,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function refer(target, options) { var _this9 = this; - logger.debug('refer()'); + debug('refer()'); var originalTarget = target; if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -18233,7 +18630,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "sendRequest", value: function sendRequest(method, options) { - logger.debug('sendRequest()'); + debug('sendRequest()'); return this._dialog.sendRequest(method, options); } /** @@ -18245,7 +18642,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function receiveRequest(request) { var _this10 = this; - logger.debug('receiveRequest()'); + debug('receiveRequest()'); if (request.method === JsSIP_C.CANCEL) { /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL @@ -18293,7 +18690,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: request.body }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -18311,7 +18708,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { status_code: 488 }); - logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this10.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -18407,7 +18804,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onTransportError", value: function onTransportError() { - logger.warn('onTransportError()'); + debugerror('onTransportError()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18420,7 +18817,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onRequestTimeout", value: function onRequestTimeout() { - logger.warn('onRequestTimeout()'); + debugerror('onRequestTimeout()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18433,7 +18830,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onDialogError", value: function onDialogError() { - logger.warn('onDialogError()'); + debugerror('onDialogError()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18447,14 +18844,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "newDTMF", value: function newDTMF(data) { - logger.debug('newDTMF()'); + debug('newDTMF()'); this.emit('newDTMF', data); } // Called from Info handler. }, { key: "newInfo", value: function newInfo(data) { - logger.debug('newInfo()'); + debug('newInfo()'); this.emit('newInfo', data); } /** @@ -18465,19 +18862,19 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "_isReadyToReOffer", value: function _isReadyToReOffer() { if (!this._rtcReady) { - logger.debug('_isReadyToReOffer() | internal WebRTC status not ready'); + debug('_isReadyToReOffer() | internal WebRTC status not ready'); return false; } // No established yet. if (!this._dialog) { - logger.debug('_isReadyToReOffer() | session not established yet'); + debug('_isReadyToReOffer() | session not established yet'); return false; } // Another INVITE transaction is in progress. if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { - logger.debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); + debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); return false; } @@ -18486,10 +18883,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_close", value: function _close() { - logger.debug('close()'); // Close local MediaStream if it was not given by the user. + debug('close()'); // Close local MediaStream if it was not given by the user. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { - logger.debug('close() | closing local MediaStream'); + debug('close() | closing local MediaStream'); Utils.closeMediaStream(this._localMediaStream); } @@ -18503,7 +18900,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { try { this._connection.close(); } catch (error) { - logger.warn('close() | error closing the RTCPeerConnection: %o', error); + debugerror('close() | error closing the RTCPeerConnection: %o', error); } } // Terminate signaling. // Clear SIP timers. @@ -18590,7 +18987,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._timers.ackTimer = setTimeout(function () { if (_this11._status === C.STATUS_WAITING_FOR_ACK) { - logger.debug('no ACK received, terminating the session'); + debug('no ACK received, terminating the session'); clearTimeout(_this11._timers.invite2xxTimer); _this11.sendRequest(JsSIP_C.BYE); @@ -18618,7 +19015,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }); - logger.debug('emit "peerconnection"'); + debug('emit "peerconnection"'); this.emit('peerconnection', { peerconnection: this._connection }); @@ -18628,7 +19025,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _createLocalDescription(type, constraints) { var _this13 = this; - logger.debug('createLocalDescription()'); + debug('createLocalDescription()'); if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\"")); var connection = this._connection; this._rtcReady = false; @@ -18636,7 +19033,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { .then(function () { if (type === 'offer') { return connection.createOffer(constraints)["catch"](function (error) { - logger.warn('emit "peerconnection:createofferfailed" [error:%o]', error); + debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); _this13.emit('peerconnection:createofferfailed', error); @@ -18644,7 +19041,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } else { return connection.createAnswer(constraints)["catch"](function (error) { - logger.warn('emit "peerconnection:createanswerfailed" [error:%o]', error); + debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); _this13.emit('peerconnection:createanswerfailed', error); @@ -18655,7 +19052,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { .then(function (desc) { return connection.setLocalDescription(desc)["catch"](function (error) { _this13._rtcReady = true; - logger.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); _this13.emit('peerconnection:setlocaldescriptionfailed', error); @@ -18670,7 +19067,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: type, sdp: connection.localDescription.sdp }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); _this13.emit('sdp', e); @@ -18693,7 +19090,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: type, sdp: connection.localDescription.sdp }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); _this13.emit('sdp', e); @@ -18739,7 +19136,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created. if (early_dialog.error) { - logger.debug(early_dialog.error); + debug(early_dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); @@ -18765,7 +19162,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var dialog = new Dialog(this, message, type); if (dialog.error) { - logger.debug(dialog.error); + debug(dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); @@ -18785,7 +19182,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveReinvite(request) { var _this14 = this; - logger.debug('receiveReinvite()'); + debug('receiveReinvite()'); var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; var data = { request: request, @@ -18842,7 +19239,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (contentType !== 'application/sdp') { - logger.debug('invalid Content-Type'); + debug('invalid Content-Type'); request.reply(415); return; } @@ -18855,7 +19252,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sendAnswer.call(_this14, desc); })["catch"](function (error) { - logger.warn(error); + debugerror(error); }); function sendAnswer(desc) { @@ -18891,7 +19288,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveUpdate(request) { var _this16 = this; - logger.debug('receiveUpdate()'); + debug('receiveUpdate()'); var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; var data = { request: request, @@ -18931,7 +19328,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (contentType !== 'application/sdp') { - logger.debug('invalid Content-Type'); + debug('invalid Content-Type'); request.reply(415); return; } @@ -18944,7 +19341,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sendAnswer.call(_this16, desc); })["catch"](function (error) { - logger.warn(error); + debugerror(error); }); function sendAnswer(desc) { @@ -18964,7 +19361,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _processInDialogSdpOffer(request) { var _this17 = this; - logger.debug('_processInDialogSdpOffer()'); + debug('_processInDialogSdpOffer()'); var sdp = request.parseSDP(); var hold = false; @@ -19000,7 +19397,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: request.body }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); this.emit('sdp', e); var offer = new RTCSessionDescription({ type: 'offer', @@ -19014,7 +19411,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this17._connection.setRemoteDescription(offer)["catch"](function (error) { request.reply(488); - logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this17.emit('peerconnection:setremotedescriptionfailed', error); @@ -19042,11 +19439,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) { request.reply(500); - logger.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); throw error; }); })["catch"](function (error) { - logger.warn('_processInDialogSdpOffer() failed [error: %o]', error); + debugerror('_processInDialogSdpOffer() failed [error: %o]', error); }); return this._connectionPromiseQueue; } @@ -19059,16 +19456,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveRefer(request) { var _this18 = this; - logger.debug('receiveRefer()'); + debug('receiveRefer()'); if (!request.refer_to) { - logger.debug('no Refer-To header field present in REFER'); + debug('no Refer-To header field present in REFER'); request.reply(400); return; } if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { - logger.debug('Refer-To header field points to a non-SIP URI scheme'); + debug('Refer-To header field points to a non-SIP URI scheme'); request.reply(416); return; } // Reply before the transaction timer expires. @@ -19076,7 +19473,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(202); var notifier = new RTCSession_ReferNotifier(this, request.cseq); - logger.debug('emit "refer"'); // Emit 'refer'. + debug('emit "refer"'); // Emit 'refer'. this.emit('refer', { request: request, @@ -19136,7 +19533,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_receiveNotify", value: function _receiveNotify(request) { - logger.debug('receiveNotify()'); + debug('receiveNotify()'); if (!request.event) { request.reply(400); @@ -19183,7 +19580,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveReplaces(request) { var _this20 = this; - logger.debug('receiveReplaces()'); + debug('receiveReplaces()'); function _accept2(initCallback) { var _this19 = this; @@ -19201,7 +19598,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } function _reject2() { - logger.debug('Replaced INVITE rejected by the user'); + debug('Replaced INVITE rejected by the user'); request.reply(486); } // Emit 'replace'. @@ -19257,7 +19654,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - logger.warn('emit "getusermediafailed" [error:%o]', error); + debugerror('emit "getusermediafailed" [error:%o]', error); _this21.emit('getusermediafailed', error); @@ -19292,7 +19689,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this21._request.body = desc; _this21._status = C.STATUS_INVITE_SENT; - logger.debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. + debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. _this21.emit('sending', { request: _this21._request @@ -19304,7 +19701,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - logger.warn(error); + debugerror(error); }); } /** @@ -19319,7 +19716,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); if (!(sender && sender.dtmf)) { - logger.warn('sendDTMF() | no local audio track to send DTMF with'); + debugerror('sendDTMF() | no local audio track to send DTMF with'); return; } @@ -19334,7 +19731,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveInviteResponse(response) { var _this22 = this; - logger.debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. + debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. if (this._dialog && response.status_code >= 200 && response.status_code <= 299) { /* @@ -19349,7 +19746,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var dialog = new Dialog(this, response, 'UAC'); if (dialog.error !== undefined) { - logger.debug(dialog.error); + debug(dialog.error); return; } @@ -19383,7 +19780,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { { // Do nothing with 1xx responses without To tag. if (!response.to_tag) { - logger.debug('1xx response received without to tag'); + debug('1xx response received without to tag'); break; } // Create Early Dialog if 1XX comes with contact. @@ -19408,7 +19805,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -19419,7 +19816,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }).then(function () { return _this22._progress('remote', response); })["catch"](function (error) { - logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this22.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19448,7 +19845,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); this.emit('sdp', _e); var _answer = new RTCSessionDescription({ @@ -19483,7 +19880,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this22.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19509,7 +19906,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this23 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - logger.debug('sendReinvite()'); + debug('sendReinvite()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; @@ -19530,7 +19927,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: sdp }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); _this23.emit('sdp', e); @@ -19593,7 +19990,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -19607,7 +20004,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } })["catch"](function (error) { onFailed.call(_this24); - logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this24.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19629,7 +20026,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this25 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - logger.debug('sendUpdate()'); + debug('sendUpdate()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; @@ -19652,7 +20049,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: sdp }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); _this25.emit('sdp', e); @@ -19741,7 +20138,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - logger.debug('emit "sdp"'); + debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -19755,7 +20152,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } })["catch"](function (error) { onFailed.call(_this26); - logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this26.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19774,7 +20171,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_acceptAndTerminate", value: function _acceptAndTerminate(response, status_code, reason_phrase) { - logger.debug('acceptAndTerminate()'); + debug('acceptAndTerminate()'); var extraHeaders = []; if (status_code) { @@ -19807,7 +20204,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sdp = sdp_transform.parse(sdp); // Local hold. if (this._localHold && !this._remoteHold) { - logger.debug('mangleOffer() | me on hold, mangling offer'); + debug('mangleOffer() | me on hold, mangling offer'); var _iterator5 = _createForOfIteratorHelper(sdp.media), _step5; @@ -19835,7 +20232,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } // Local and remote hold. else if (this._localHold && this._remoteHold) { - logger.debug('mangleOffer() | both on hold, mangling offer'); + debug('mangleOffer() | both on hold, mangling offer'); var _iterator6 = _createForOfIteratorHelper(sdp.media), _step6; @@ -19857,7 +20254,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } // Remote hold. else if (this._remoteHold) { - logger.debug('mangleOffer() | remote on hold, mangling offer'); + debug('mangleOffer() | remote on hold, mangling offer'); var _iterator7 = _createForOfIteratorHelper(sdp.media), _step7; @@ -19979,7 +20376,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - logger.debug('runSessionTimer() | sending session refresh request'); + debug('runSessionTimer() | sending session refresh request'); if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { _this27._sendUpdate(); @@ -19994,7 +20391,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - logger.warn('runSessionTimer() | timer expired, terminating the session'); + debugerror('runSessionTimer() | timer expired, terminating the session'); _this27.terminate({ cause: JsSIP_C.causes.REQUEST_TIMEOUT, @@ -20049,7 +20446,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_newRTCSession", value: function _newRTCSession(originator, request) { - logger.debug('newRTCSession()'); + debug('newRTCSession()'); this._ua.newRTCSession(this, { originator: originator, @@ -20060,8 +20457,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_connecting", value: function _connecting(request) { - logger.debug('session connecting'); - logger.debug('emit "connecting"'); + debug('session connecting'); + debug('emit "connecting"'); this.emit('connecting', { request: request }); @@ -20069,8 +20466,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_progress", value: function _progress(originator, response) { - logger.debug('session progress'); - logger.debug('emit "progress"'); + debug('session progress'); + debug('emit "progress"'); this.emit('progress', { originator: originator, response: response || null @@ -20079,9 +20476,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_accepted", value: function _accepted(originator, message) { - logger.debug('session accepted'); + debug('session accepted'); this._start_time = new Date(); - logger.debug('emit "accepted"'); + debug('emit "accepted"'); this.emit('accepted', { originator: originator, response: message || null @@ -20090,9 +20487,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_confirmed", value: function _confirmed(originator, ack) { - logger.debug('session confirmed'); + debug('session confirmed'); this._is_confirmed = true; - logger.debug('emit "confirmed"'); + debug('emit "confirmed"'); this.emit('confirmed', { originator: originator, ack: ack || null @@ -20101,12 +20498,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_ended", value: function _ended(originator, message, cause) { - logger.debug('session ended'); + debug('session ended'); this._end_time = new Date(); this._close(); - logger.debug('emit "ended"'); + debug('emit "ended"'); this.emit('ended', { originator: originator, message: message || null, @@ -20116,9 +20513,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_failed", value: function _failed(originator, message, cause) { - logger.debug('session failed'); // Emit private '_failed' event first. + debug('session failed'); // Emit private '_failed' event first. - logger.debug('emit "_failed"'); + debug('emit "_failed"'); this.emit('_failed', { originator: originator, message: message || null, @@ -20127,7 +20524,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._close(); - logger.debug('emit "failed"'); + debug('emit "failed"'); this.emit('failed', { originator: originator, message: message || null, @@ -20137,11 +20534,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_onhold", value: function _onhold(originator) { - logger.debug('session onhold'); + debug('session onhold'); this._setLocalMediaStatus(); - logger.debug('emit "hold"'); + debug('emit "hold"'); this.emit('hold', { originator: originator }); @@ -20149,11 +20546,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_onunhold", value: function _onunhold(originator) { - logger.debug('session onunhold'); + debug('session onunhold'); this._setLocalMediaStatus(); - logger.debug('emit "unhold"'); + debug('emit "unhold"'); this.emit('unhold', { originator: originator }); @@ -20163,11 +20560,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _onmute(_ref5) { var audio = _ref5.audio, video = _ref5.video; - logger.debug('session onmute'); + debug('session onmute'); this._setLocalMediaStatus(); - logger.debug('emit "muted"'); + debug('emit "muted"'); this.emit('muted', { audio: audio, video: video @@ -20178,85 +20575,30 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _onunmute(_ref6) { var audio = _ref6.audio, video = _ref6.video; - logger.debug('session onunmute'); + debug('session onunmute'); this._setLocalMediaStatus(); - logger.debug('emit "unmuted"'); + debug('emit "unmuted"'); this.emit('unmuted', { audio: audio, video: video }); } - }, { + }], [{ key: "C", - get: function get() { + get: + /** + * Expose C object. + */ + function get() { return C; - } // Expose session failed/ended causes as a property of the RTCSession instance. - - }, { - key: "causes", - get: function get() { - return JsSIP_C.causes; - } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "connection", - get: function get() { - return this._connection; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "start_time", - get: function get() { - return this._start_time; - } - }, { - key: "end_time", - get: function get() { - return this._end_time; - } - }, { - key: "data", - get: function get() { - return this._data; - }, - set: function set(_data) { - this._data = _data; - } - }, { - key: "status", - get: function get() { - return this._status; } }]); return RTCSession; }(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./Logger":9,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":22,"./Transactions":23,"./URI":26,"./Utils":27,"events":30,"sdp-transform":36}],14:[function(require,module,exports){ +},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,"debug":32,"events":31,"sdp-transform":37}],14:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20277,21 +20619,23 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; -var Logger = require('../Logger'); - var JsSIP_C = require('../Constants'); var Exceptions = require('../Exceptions'); var Utils = require('../Utils'); -var logger = new Logger('RTCSession:DTMF'); +var debug = require('debug')('JsSIP:RTCSession:DTMF'); + +var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); + +debugerror.log = console.warn.bind(console); var C = { MIN_DURATION: 70, MAX_DURATION: 6000, @@ -20320,6 +20664,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(DTMF, [{ + key: "tone", + get: function get() { + return this._tone; + } + }, { + key: "duration", + get: function get() { + return this._duration; + } + }, { key: "send", value: function send(tone) { var _this2 = this; @@ -20428,7 +20782,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (!this._tone) { - logger.debug('invalid INFO DTMF received, discarded'); + debug('invalid INFO DTMF received, discarded'); } else { this._session.newDTMF({ originator: 'remote', @@ -20437,16 +20791,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } } - }, { - key: "tone", - get: function get() { - return this._tone; - } - }, { - key: "duration", - get: function get() { - return this._duration; - } }]); return DTMF; @@ -20457,7 +20801,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { module.exports.C = C; -},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":27,"events":30}],15:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],15:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20478,12 +20822,16 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); + +debugerror.log = console.warn.bind(console); + var JsSIP_C = require('../Constants'); var Exceptions = require('../Exceptions'); @@ -20509,6 +20857,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Info, [{ + key: "contentType", + get: function get() { + return this._contentType; + } + }, { + key: "body", + get: function get() { + return this._body; + } + }, { key: "send", value: function send(contentType, body) { var _this2 = this; @@ -20579,21 +20937,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request: request }); } - }, { - key: "contentType", - get: function get() { - return this._contentType; - } - }, { - key: "body", - get: function get() { - return this._body; - } }]); return Info; }(EventEmitter); -},{"../Constants":2,"../Exceptions":6,"../Utils":27,"events":30}],16:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],16:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -20602,11 +20950,10 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Logger = require('../Logger'); - var JsSIP_C = require('../Constants'); -var logger = new Logger('RTCSession:ReferNotifier'); +var debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); + var C = { event_type: 'refer', body_type: 'message/sipfrag;version=2.0', @@ -20628,7 +20975,7 @@ module.exports = /*#__PURE__*/function () { _createClass(ReferNotifier, [{ key: "notify", value: function notify(code, reason) { - logger.debug('notify()'); + debug('notify()'); if (this._active === false) { return; @@ -20659,7 +21006,7 @@ module.exports = /*#__PURE__*/function () { return ReferNotifier; }(); -},{"../Constants":2,"../Logger":9}],17:[function(require,module,exports){ +},{"../Constants":2,"debug":32}],17:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20680,21 +21027,19 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; -var Logger = require('../Logger'); - var JsSIP_C = require('../Constants'); var Grammar = require('../Grammar'); var Utils = require('../Utils'); -var logger = new Logger('RTCSession:ReferSubscriber'); +var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(ReferSubscriber, _EventEmitter); @@ -20713,12 +21058,17 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(ReferSubscriber, [{ + key: "id", + get: function get() { + return this._id; + } + }, { key: "sendRefer", value: function sendRefer(target) { var _this2 = this; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - logger.debug('sendRefer()'); + debug('sendRefer()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers. @@ -20740,15 +21090,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">"); - extraHeaders.push(referTo); // Referred-By header field (if not already present). - - if (!extraHeaders.some(function (header) { - return header.toLowerCase().startsWith('referred-by:'); - })) { - var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); - extraHeaders.push(referredBy); - } + extraHeaders.push(referTo); // Referred-By header field. + var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); + extraHeaders.push(referredBy); extraHeaders.push("Contact: ".concat(this._session.contact)); var request = this._session.sendRequest(JsSIP_C.REFER, { @@ -20777,7 +21122,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "receiveNotify", value: function receiveNotify(request) { - logger.debug('receiveNotify()'); + debug('receiveNotify()'); if (!request.body) { return; @@ -20786,7 +21131,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var status_line = Grammar.parse(request.body.trim(), 'Status_Line'); if (status_line === -1) { - logger.debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); + debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); return; } @@ -20823,8 +21168,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_requestSucceeded", value: function _requestSucceeded(response) { - logger.debug('REFER succeeded'); - logger.debug('emit "requestSucceeded"'); + debug('REFER succeeded'); + debug('emit "requestSucceeded"'); this.emit('requestSucceeded', { response: response }); @@ -20832,23 +21177,18 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_requestFailed", value: function _requestFailed(response, cause) { - logger.debug('REFER failed'); - logger.debug('emit "requestFailed"'); + debug('REFER failed'); + debug('emit "requestFailed"'); this.emit('requestFailed', { response: response || null, cause: cause }); } - }, { - key: "id", - get: function get() { - return this._id; - } }]); return ReferSubscriber; }(EventEmitter); -},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":27,"events":30}],18:[function(require,module,exports){ +},{"../Constants":2,"../Grammar":7,"../Utils":28,"debug":32,"events":31}],18:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -20857,8 +21197,6 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Logger = require('./Logger'); - var Utils = require('./Utils'); var JsSIP_C = require('./Constants'); @@ -20867,7 +21205,8 @@ var SIPMessage = require('./SIPMessage'); var RequestSender = require('./RequestSender'); -var logger = new Logger('Registrator'); +var debug = require('debug')('JsSIP:Registrator'); + var MIN_REGISTER_EXPIRES = 10; // In seconds. module.exports = /*#__PURE__*/function () { @@ -20904,6 +21243,11 @@ module.exports = /*#__PURE__*/function () { } _createClass(Registrator, [{ + key: "registered", + get: function get() { + return this._registered; + } + }, { key: "setExtraHeaders", value: function setExtraHeaders(extraHeaders) { if (!Array.isArray(extraHeaders)) { @@ -20939,7 +21283,7 @@ module.exports = /*#__PURE__*/function () { var _this = this; if (this._registering) { - logger.debug('Register request in progress...'); + debug('Register request in progress...'); return; } @@ -20987,7 +21331,7 @@ module.exports = /*#__PURE__*/function () { _this._registering = false; if (!response.hasHeader('Contact')) { - logger.debug('no Contact header in response to REGISTER, response ignored'); + debug('no Contact header in response to REGISTER, response ignored'); break; } @@ -21007,7 +21351,7 @@ module.exports = /*#__PURE__*/function () { } if (!contact) { - logger.debug('no Contact header pointing to us, response ignored'); + debug('no Contact header pointing to us, response ignored'); break; } @@ -21067,7 +21411,7 @@ module.exports = /*#__PURE__*/function () { _this.register(); } else { // This response MUST contain a Min-Expires header field. - logger.debug('423 response received for REGISTER without Min-Expires'); + debug('423 response received for REGISTER without Min-Expires'); _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); } @@ -21095,7 +21439,7 @@ module.exports = /*#__PURE__*/function () { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (!this._registered) { - logger.debug('already unregistered'); + debug('already unregistered'); return; } @@ -21206,16 +21550,11 @@ module.exports = /*#__PURE__*/function () { cause: cause || null }); } - }, { - key: "registered", - get: function get() { - return this._registered; - } }]); return Registrator; }(); -},{"./Constants":2,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27}],19:[function(require,module,exports){ +},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32}],19:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -21224,15 +21563,14 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Logger = require('./Logger'); - var JsSIP_C = require('./Constants'); var DigestAuthentication = require('./DigestAuthentication'); var Transactions = require('./Transactions'); -var logger = new Logger('RequestSender'); // Default event handlers. +var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers. + var EventHandlers = { onRequestTimeout: function onRequestTimeout() {}, @@ -21336,7 +21674,7 @@ module.exports = /*#__PURE__*/function () { if (!challenge) { - logger.debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); + debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); this._eventHandlers.onReceiveResponse(response); @@ -21391,7 +21729,7 @@ module.exports = /*#__PURE__*/function () { return RequestSender; }(); -},{"./Constants":2,"./DigestAuthentication":5,"./Logger":9,"./Transactions":23}],20:[function(require,module,exports){ +},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,"debug":32}],20:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -21406,11 +21744,11 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -21424,8 +21762,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d var sdp_transform = require('sdp-transform'); -var Logger = require('./Logger'); - var JsSIP_C = require('./Constants'); var Utils = require('./Utils'); @@ -21434,7 +21770,7 @@ var NameAddrHeader = require('./NameAddrHeader'); var Grammar = require('./Grammar'); -var logger = new Logger('SIPMessage'); +var debug = require('debug')('JsSIP:SIPMessage'); /** * -param {String} method request method * -param {String} ruri request uri @@ -21446,6 +21782,7 @@ var logger = new Logger('SIPMessage'); * -param {String} [body] */ + var OutgoingRequest = /*#__PURE__*/function () { function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) { _classCallCheck(this, OutgoingRequest); @@ -21924,10 +22261,10 @@ var IncomingMessage = /*#__PURE__*/function () { name = Utils.headerize(name); if (!this.headers[name]) { - logger.debug("header \"".concat(name, "\" not present")); + debug("header \"".concat(name, "\" not present")); return; } else if (idx >= this.headers[name].length) { - logger.debug("not so many \"".concat(name, "\" headers present")); + debug("not so many \"".concat(name, "\" headers present")); return; } @@ -21944,7 +22281,7 @@ var IncomingMessage = /*#__PURE__*/function () { if (parsed === -1) { this.headers[name].splice(idx, 1); // delete from headers - logger.debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); + debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); return; } else { header.parsed = parsed; @@ -22163,165 +22500,733 @@ var IncomingRequest = /*#__PURE__*/function (_IncomingMessage) { response += "Content-Length: ".concat(0, "\r\n\r\n"); } - this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); + this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); + } + /** + * Stateless reply. + * -param {Number} code status code + * -param {String} reason reason phrase + */ + + }, { + key: "reply_sl", + value: function reply_sl() { + var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var vias = this.getHeaders('via'); // Validate code and reason values. + + if (!code || code < 100 || code > 699) { + throw new TypeError("Invalid status_code: ".concat(code)); + } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { + throw new TypeError("Invalid reason_phrase: ".concat(reason)); + } + + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); + + var _iterator11 = _createForOfIteratorHelper(vias), + _step11; + + try { + for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { + var via = _step11.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator11.e(err); + } finally { + _iterator11.f(); + } + + var to = this.getHeader('To'); + + if (!this.to_tag && code > 100) { + to += ";tag=".concat(Utils.newTag()); + } else if (this.to_tag && !this.s('to').hasParam('tag')) { + to += ";tag=".concat(this.to_tag); + } + + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(this.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(this.call_id, "\r\n"); + response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); + response += "Content-Length: ".concat(0, "\r\n\r\n"); + this.transport.send(response); + } + }]); + + return IncomingRequest; +}(IncomingMessage); + +var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { + _inherits(IncomingResponse, _IncomingMessage2); + + var _super3 = _createSuper(IncomingResponse); + + function IncomingResponse() { + var _this3; + + _classCallCheck(this, IncomingResponse); + + _this3 = _super3.call(this); + _this3.headers = {}; + _this3.status_code = null; + _this3.reason_phrase = null; + return _this3; + } + + return IncomingResponse; +}(IncomingMessage); + +module.exports = { + OutgoingRequest: OutgoingRequest, + InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, + IncomingRequest: IncomingRequest, + IncomingResponse: IncomingResponse +}; +},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,"debug":32,"sdp-transform":37}],21:[function(require,module,exports){ +"use strict"; + +var Utils = require('./Utils'); + +var Grammar = require('./Grammar'); + +var debugerror = require('debug')('JsSIP:ERROR:Socket'); + +debugerror.log = console.warn.bind(console); +/** + * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ + * + * interface Socket { + * attribute String via_transport + * attribute String url + * attribute String sip_uri + * + * method connect(); + * method disconnect(); + * method send(data); + * + * attribute EventHandler onconnect + * attribute EventHandler ondisconnect + * attribute EventHandler ondata + * } + * + */ + +exports.isSocket = function (socket) { + // Ignore if an array is given. + if (Array.isArray(socket)) { + return false; + } + + if (typeof socket === 'undefined') { + debugerror('undefined JsSIP.Socket instance'); + return false; + } // Check Properties. + + + try { + if (!Utils.isString(socket.url)) { + debugerror('missing or invalid JsSIP.Socket url property'); + throw new Error(); + } + + if (!Utils.isString(socket.via_transport)) { + debugerror('missing or invalid JsSIP.Socket via_transport property'); + throw new Error(); + } + + if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { + debugerror('missing or invalid JsSIP.Socket sip_uri property'); + throw new Error(); + } + } catch (e) { + return false; + } // Check Methods. + + + try { + ['connect', 'disconnect', 'send'].forEach(function (method) { + if (!Utils.isFunction(socket[method])) { + debugerror("missing or invalid JsSIP.Socket method: ".concat(method)); + throw new Error(); + } + }); + } catch (e) { + return false; + } + + return true; +}; +},{"./Grammar":7,"./Utils":28,"debug":32}],22:[function(require,module,exports){ +"use strict"; + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +var EventEmitter = require('events').EventEmitter; + +var JsSIP_C = require('./Constants'); + +var Utils = require('./Utils'); + +var Grammar = require('./Grammar'); + +var SIPMessage = require('./SIPMessage'); + +var RequestSender = require('./RequestSender'); + +var Dialog = require('./Dialog'); + +var debug = require('debug')('JsSIP:Subscriber'); + +var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); + +debugerror.log = console.warn.bind(console); +/** + * Termination codes. + */ + +var C = { + // Termination codes. + SUBSCRIBE_RESPONSE_TIMEOUT: 0, + SUBSCRIBE_TRANSPORT_ERROR: 1, + SUBSCRIBE_NON_OK_RESPONSE: 2, + SUBSCRIBE_BAD_OK_RESPONSE: 3, + SUBSCRIBE_FAILED_AUTHENTICATION: 4, + UNSUBSCRIBE_TIMEOUT: 5, + RECEIVE_FINAL_NOTIFY: 6, + RECEIVE_BAD_NOTIFY: 7, + // Subscriber states. + STATE_PENDING: 0, + STATE_ACTIVE: 1, + STATE_TERMINATED: 2, + STATE_INIT: 3, + STATE_NOTIFY_WAIT: 4 +}; +/** + * RFC 6665 Subscriber implementation. + */ + +module.exports = /*#__PURE__*/function (_EventEmitter) { + _inherits(Subscriber, _EventEmitter); + + var _super = _createSuper(Subscriber); + + /** + * @param {UA} ua - reference to JsSIP.UA + * @param {string} target + * @param {string} eventName - Event header value. May end with optional ;id=xxx + * @param {string} accept - Accept header value. + * + * @param {SubscriberOption} options - optional parameters. + * @param {number} expires - Expires header value. Default is 900. + * @param {string} contentType - Content-Type header value. Used for SUBSCRIBE with body + * @param {string} allowEvents - Allow-Events header value. + * @param {RequestParams} params - Will have priority over ua.configuration. + * If set please define: to_uri, to_display_name, from_uri, from_display_name + * @param {Array} extraHeaders - Additional SIP headers. + */ + function Subscriber(ua, target, eventName, accept, _ref) { + var _this; + + var expires = _ref.expires, + contentType = _ref.contentType, + allowEvents = _ref.allowEvents, + params = _ref.params, + extraHeaders = _ref.extraHeaders; + + _classCallCheck(this, Subscriber); + + debug('new'); + _this = _super.call(this); // Check that arguments are defined + + if (!target) { + throw new TypeError('target is undefined'); + } + + if (!eventName) { + throw new TypeError('eventName is undefined'); + } + + if (!accept) { + throw new TypeError('accept is undefined'); + } + + _this._ua = ua; + _this._target = target; + + if (expires !== 0 && !expires) { + expires = 900; + } + + _this._expires = expires; // Used to subscribe with body. + + _this._content_type = contentType; // Set initial subscribe parameters. + + _this._params = Utils.cloneObject(params); + + if (!_this._params.from_uri) { + _this._params.from_uri = _this._ua.configuration.uri; + } + + _this._params.from_tag = Utils.newTag(); + _this._params.to_tag = null; + _this._params.call_id = Utils.createRandomToken(20); // Create subscribe cseq if not defined custom cseq. + + if (_this._params.cseq === undefined) { + _this._params.cseq = Math.floor(Math.random() * 10000 + 1); + } // Subscriber state. + + + _this._state = C.STATE_INIT; // Dialog + + _this._dialog = null; // To refresh subscription. + + _this._expires_timer = null; + _this._expires_timestamp = null; // To prevent duplicate un-subscribe sending. + + _this._send_unsubscribe = false; // After send un-subscribe wait final notify limited time. + + _this._unsubscribe_timeout_timer = null; // Custom session empty object for high level use. + + _this.data = {}; + var parsed = Grammar.parse(eventName, 'Event'); + + if (parsed === -1) { + throw new TypeError('eventName - wrong format'); + } + + _this._event_name = parsed.event; + _this._event_id = parsed.params && parsed.params.id; + var eventValue = _this._event_name; + + if (_this._event_id) { + eventValue += ";id=".concat(_this._event_id); + } + + _this._headers = Utils.cloneArray(extraHeaders); + _this._headers = _this._headers.concat(["Event: ".concat(eventValue), "Expires: ".concat(_this._expires), "Accept: ".concat(accept)]); + + if (!_this._headers.find(function (header) { + return header.startsWith('Contact'); + })) { + var contact = "Contact: "); + contact += ";+sip.instance=\"\""); + + _this._headers.push(contact); + } + + if (allowEvents) { + _this._headers.push("Allow-Events: ".concat(allowEvents)); + } + + return _this; + } + + _createClass(Subscriber, [{ + key: "C", + get: function get() { + return C; + } + }, { + key: "onRequestTimeout", + value: function onRequestTimeout() { + this._dialogTerminated(C.SUBSCRIBE_RESPONSE_TIMEOUT); + } + }, { + key: "onTransportError", + value: function onTransportError() { + this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); + } + /** + * Dialog callback. + */ + + }, { + key: "receiveRequest", + value: function receiveRequest(request) { + if (request.method !== JsSIP_C.NOTIFY) { + debugerror('received non-NOTIFY request'); + request.reply(405); + return; + } // RFC 6665 8.2.1. Check if event header matches. + + + var event_header = request.parseHeader('Event'); + + if (!event_header) { + debugerror('missed Event header'); + request.reply(400); + + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + + return; + } + + var event_name = event_header.event; + var event_id = event_header.params && event_header.params.id; + + if (event_name !== this._event_name || event_id !== this._event_id) { + debugerror('Event header does not match SUBSCRIBE'); + request.reply(489); + + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + + return; + } // Process Subscription-State header. + + + var subs_state = request.parseHeader('subscription-state'); + + if (!subs_state) { + debugerror('missed Subscription-State header'); + request.reply(400); + + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + + return; + } + + request.reply(200); + + var new_state = this._stateStringToNumber(subs_state.state); + + var prev_state = this._state; + + if (prev_state !== C.STATE_TERMINATED && new_state !== C.STATE_TERMINATED) { + this._state = new_state; + + if (subs_state.expires !== undefined) { + var expires = subs_state.expires; + var expires_timestamp = new Date().getTime() + expires * 1000; + var max_time_deviation = 2000; // Expiration time is shorter and the difference is not too small. + + if (this._expires_timestamp - expires_timestamp > max_time_deviation) { + debug('update sending re-SUBSCRIBE time'); + + this._scheduleSubscribe(expires); + } + } + } + + if (prev_state !== C.STATE_PENDING && new_state === C.STATE_PENDING) { + debug('emit "pending"'); + this.emit('pending'); + } else if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { + debug('emit "active"'); + this.emit('active'); + } + + var body = request.body; // Check if the notify is final. + + var is_final = new_state === C.STATE_TERMINATED; // Notify event fired only for notify with body. + + if (body) { + var content_type = request.getHeader('content-type'); + debug('emit "notify"'); + this.emit('notify', is_final, request, body, content_type); + } + + if (is_final) { + var reason = subs_state.reason; + var retry_after = undefined; + + if (subs_state.params && subs_state.params['retry-after'] !== undefined) { + retry_after = parseInt(subs_state.params['retry-after']); + } + + this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason, retry_after); + } + } + /** + * User API + */ + + /** + * Send the initial (non-fetch) and subsequent subscribe. + * @param {string} body - subscribe request body. + */ + + }, { + key: "subscribe", + value: function subscribe() { + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + debug('subscribe()'); + + if (this._state === C.STATE_INIT) { + this._state = C.STATE_NOTIFY_WAIT; + + this._sendInitialSubscribe(body, this._headers); + } else { + this._sendSubsequentSubscribe(body, this._headers); + } + } + /** + * terminate. + * Send un-subscribe or fetch-subscribe (with Expires: 0). + * @param {string} body - un-subscribe request body + */ + + }, { + key: "terminate", + value: function terminate() { + var _this2 = this; + + var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + debug('terminate()'); // Prevent duplication un-subscribe sending. + + if (this._send_unsubscribe) { + debugerror('unsubscribe has already been sent'); + return; + } + + this._send_unsubscribe = true; // Set header Expires: 0. + + var headers = this._headers.map(function (s) { + return s.startsWith('Expires') ? 'Expires: 0' : s; + }); + + if (!this._dialog) { + // fetch-subscribe - initial subscribe with Expires: 0. + this._sendInitialSubscribe(body, headers); + } else { + this._sendSubsequentSubscribe(body, headers); + } // Waiting for the final notify for a while. + + + var final_notify_timeout = 30000; + this._unsubscribe_timeout_timer = setTimeout(function () { + _this2._dialogTerminated(C.UNSUBSCRIBE_TIMEOUT); + }, final_notify_timeout); } /** - * Stateless reply. - * -param {Number} code status code - * -param {String} reason reason phrase - */ + * Get dialog state. + */ }, { - key: "reply_sl", - value: function reply_sl() { - var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var vias = this.getHeaders('via'); // Validate code and reason values. - - if (!code || code < 100 || code > 699) { - throw new TypeError("Invalid status_code: ".concat(code)); - } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { - throw new TypeError("Invalid reason_phrase: ".concat(reason)); - } + key: "state", + get: function get() { + return this._state; + } + /** + * Get dialog id. + */ - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); + }, { + key: "id", + get: function get() { + return this._dialog ? this._dialog.id : null; + } + /** + * Private API. + */ - var _iterator11 = _createForOfIteratorHelper(vias), - _step11; + }, { + key: "_sendInitialSubscribe", + value: function _sendInitialSubscribe(body, headers) { + var _this3 = this; - try { - for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { - var via = _step11.value; - response += "Via: ".concat(via, "\r\n"); + if (body) { + if (!this._content_type) { + throw new TypeError('content_type is undefined'); } - } catch (err) { - _iterator11.e(err); - } finally { - _iterator11.f(); - } - var to = this.getHeader('To'); - - if (!this.to_tag && code > 100) { - to += ";tag=".concat(Utils.newTag()); - } else if (this.to_tag && !this.s('to').hasParam('tag')) { - to += ";tag=".concat(this.to_tag); + headers = headers.slice(); + headers.push("Content-Type: ".concat(this._content_type)); } - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(this.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(this.call_id, "\r\n"); - response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); - response += "Content-Length: ".concat(0, "\r\n\r\n"); - this.transport.send(response); + var request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); + var request_sender = new RequestSender(this._ua, request, { + onRequestTimeout: function onRequestTimeout() { + _this3.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this3.onTransportError(); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this3._receiveSubscribeResponse(response); + } + }); + request_sender.send(); } - }]); + }, { + key: "_receiveSubscribeResponse", + value: function _receiveSubscribeResponse(response) { + if (response.status_code >= 200 && response.status_code < 300) { + // Create dialog + if (this._dialog === null) { + var dialog = new Dialog(this, response, 'UAC'); - return IncomingRequest; -}(IncomingMessage); + if (dialog.error) { + // OK response without Contact + debugerror(dialog.error); -var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { - _inherits(IncomingResponse, _IncomingMessage2); + this._dialogTerminated(C.SUBSCRIBE_BAD_OK_RESPONSE); - var _super3 = _createSuper(IncomingResponse); + return; + } - function IncomingResponse() { - var _this3; + this._dialog = dialog; + debug('emit "dialogCreated"'); + this.emit('dialogCreated'); + } // Check expires value. - _classCallCheck(this, IncomingResponse); - _this3 = _super3.call(this); - _this3.headers = {}; - _this3.status_code = null; - _this3.reason_phrase = null; - return _this3; - } + var expires_value = response.getHeader('expires'); - return IncomingResponse; -}(IncomingMessage); + if (expires_value !== 0 && !expires_value) { + debugerror('response without Expires header'); // RFC 6665 3.1.1 subscribe OK response must contain Expires header. + // Use workaround expires value. -module.exports = { - OutgoingRequest: OutgoingRequest, - InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, - IncomingRequest: IncomingRequest, - IncomingResponse: IncomingResponse -}; -},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":27,"sdp-transform":36}],21:[function(require,module,exports){ -"use strict"; + expires_value = '900'; + } -var Logger = require('./Logger'); + var expires = parseInt(expires_value); -var Utils = require('./Utils'); + if (expires > 0) { + this._scheduleSubscribe(expires); + } + } else if (response.status_code === 401 || response.status_code === 407) { + this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); + } else if (response.status_code >= 300) { + this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); + } + } + }, { + key: "_sendSubsequentSubscribe", + value: function _sendSubsequentSubscribe(body, headers) { + var _this4 = this; -var Grammar = require('./Grammar'); + if (!this._dialog) { + debugerror('sending subsequent subscribe before OK response to initial subscribe'); + throw new Error('not received final response to initial SUBSCRIBE'); + } -var logger = new Logger('Socket'); -/** - * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ - * - * interface Socket { - * attribute String via_transport - * attribute String url - * attribute String sip_uri - * - * method connect(); - * method disconnect(); - * method send(data); - * - * attribute EventHandler onconnect - * attribute EventHandler ondisconnect - * attribute EventHandler ondata - * } - * - */ + if (body) { + if (!this._content_type) { + throw new TypeError('content_type is undefined'); + } -exports.isSocket = function (socket) { - // Ignore if an array is given. - if (Array.isArray(socket)) { - return false; - } + headers = headers.slice(); + headers.push("Content-Type: ".concat(this._content_type)); + } - if (typeof socket === 'undefined') { - logger.warn('undefined JsSIP.Socket instance'); - return false; - } // Check Properties. + this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { + body: body, + extraHeaders: headers, + eventHandlers: { + onRequestTimeout: function onRequestTimeout() { + _this4.onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this4.onTransportError(); + }, + onSuccessResponse: function onSuccessResponse(response) { + _this4._receiveSubscribeResponse(response); + }, + onErrorResponse: function onErrorResponse(response) { + _this4._receiveSubscribeResponse(response); + }, + onDialogError: function onDialogError(response) { + _this4._receiveSubscribeResponse(response); + } + } + }); + } + }, { + key: "_dialogTerminated", + value: function _dialogTerminated(terminationCode) { + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; + var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; + // To prevent duplicate emit terminated event. + if (!this._dialog) { + return; + } - try { - if (!Utils.isString(socket.url)) { - logger.warn('missing or invalid JsSIP.Socket url property'); - throw new Error('Missing or invalid JsSIP.Socket url property'); - } + this._state = C.STATE_TERMINATED; // Clear timers. - if (!Utils.isString(socket.via_transport)) { - logger.warn('missing or invalid JsSIP.Socket via_transport property'); - throw new Error('Missing or invalid JsSIP.Socket via_transport property'); + clearTimeout(this._expires_timer); + clearTimeout(this._unsubscribe_timeout_timer); + + this._dialog.terminate(); + + this._dialog = null; + debug("emit \"terminated\" code=".concat(terminationCode)); + this.emit('terminated', terminationCode, reason, retryAfter); } + }, { + key: "_scheduleSubscribe", + value: function _scheduleSubscribe(expires) { + var _this5 = this; - if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { - logger.warn('missing or invalid JsSIP.Socket sip_uri property'); - throw new Error('missing or invalid JsSIP.Socket sip_uri property'); + var timeout = expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; + this._expires_timestamp = new Date().getTime() + expires * 1000; + debug("next SUBSCRIBE will be sent in ".concat(Math.floor(timeout / 1000), " sec")); + clearTimeout(this._expires_timer); + this._expires_timer = setTimeout(function () { + _this5._expires_timer = null; + + _this5._sendSubsequentSubscribe(null, _this5._headers); + }, timeout); } - } catch (e) { - return false; - } // Check Methods. + }, { + key: "_stateStringToNumber", + value: function _stateStringToNumber(strState) { + switch (strState) { + case 'pending': + return C.STATE_PENDING; + case 'active': + return C.STATE_ACTIVE; - try { - ['connect', 'disconnect', 'send'].forEach(function (method) { - if (!Utils.isFunction(socket[method])) { - logger.warn("missing or invalid JsSIP.Socket method: ".concat(method)); - throw new Error("Missing or invalid JsSIP.Socket method: ".concat(method)); + case 'terminated': + return C.STATE_TERMINATED; + + case 'init': + return C.STATE_INIT; + + case 'notify_wait': + return C.STATE_NOTIFY_WAIT; + + default: + throw new TypeError('wrong state value'); } - }); - } catch (e) { - return false; - } + } + }], [{ + key: "C", + get: + /** + * Expose C object. + */ + function get() { + return C; + } + }]); - return true; -}; -},{"./Grammar":7,"./Logger":9,"./Utils":27}],22:[function(require,module,exports){ + return Subscriber; +}(EventEmitter); +},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ "use strict"; var T1 = 500, @@ -22343,7 +23248,7 @@ module.exports = { PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 }; -},{}],23:[function(require,module,exports){ +},{}],24:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -22364,25 +23269,28 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; -var Logger = require('./Logger'); - var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); var Timers = require('./Timers'); -var loggernict = new Logger('NonInviteClientTransaction'); -var loggerict = new Logger('InviteClientTransaction'); -var loggeract = new Logger('AckClientTransaction'); -var loggernist = new Logger('NonInviteServerTransaction'); -var loggerist = new Logger('InviteServerTransaction'); +var debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); + +var debugict = require('debug')('JsSIP:InviteClientTransaction'); + +var debugact = require('debug')('JsSIP:AckClientTransaction'); + +var debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); + +var debugist = require('debug')('JsSIP:InviteServerTransaction'); + var C = { // Transaction states. STATUS_TRYING: 1, @@ -22427,6 +23335,11 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } _createClass(NonInviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22449,7 +23362,7 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { }, { key: "onTransportError", value: function onTransportError() { - loggernict.debug("transport error occurred, deleting transaction ".concat(this.id)); + debugnict("transport error occurred, deleting transaction ".concat(this.id)); clearTimeout(this.F); clearTimeout(this.K); this.stateChanged(C.STATUS_TERMINATED); @@ -22459,7 +23372,7 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { }, { key: "timer_F", value: function timer_F() { - loggernict.debug("Timer F expired for transaction ".concat(this.id)); + debugnict("Timer F expired for transaction ".concat(this.id)); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); this.eventHandlers.onRequestTimeout(); @@ -22508,11 +23421,6 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return NonInviteClientTransaction; @@ -22547,6 +23455,11 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } _createClass(InviteClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22574,7 +23487,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { clearTimeout(this.M); if (this.state !== C.STATUS_ACCEPTED) { - loggerict.debug("transport error occurred, deleting transaction ".concat(this.id)); + debugict("transport error occurred, deleting transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } @@ -22585,7 +23498,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_M", value: function timer_M() { - loggerict.debug("Timer M expired for transaction ".concat(this.id)); + debugict("Timer M expired for transaction ".concat(this.id)); if (this.state === C.STATUS_ACCEPTED) { clearTimeout(this.B); @@ -22597,7 +23510,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_B", value: function timer_B() { - loggerict.debug("Timer B expired for transaction ".concat(this.id)); + debugict("Timer B expired for transaction ".concat(this.id)); if (this.state === C.STATUS_CALLING) { this.stateChanged(C.STATUS_TERMINATED); @@ -22608,7 +23521,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_D", value: function timer_D() { - loggerict.debug("Timer D expired for transaction ".concat(this.id)); + debugict("Timer D expired for transaction ".concat(this.id)); clearTimeout(this.B); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -22702,11 +23615,6 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return InviteClientTransaction; @@ -22736,6 +23644,11 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { } _createClass(AckClientTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "send", value: function send() { if (!this.transport.send(this.request)) { @@ -22745,14 +23658,9 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { }, { key: "onTransportError", value: function onTransportError() { - loggeract.debug("transport error occurred for transaction ".concat(this.id)); + debugact("transport error occurred for transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } - }, { - key: "C", - get: function get() { - return C; - } }]); return AckClientTransaction; @@ -22782,6 +23690,11 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } _createClass(NonInviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22790,7 +23703,7 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { }, { key: "timer_J", value: function timer_J() { - loggernist.debug("Timer J expired for transaction ".concat(this.id)); + debugnist("Timer J expired for transaction ".concat(this.id)); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); } @@ -22799,7 +23712,7 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { value: function onTransportError() { if (!this.transportError) { this.transportError = true; - loggernist.debug("transport error occurred, deleting transaction ".concat(this.id)); + debugnist("transport error occurred, deleting transaction ".concat(this.id)); clearTimeout(this.J); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -22868,11 +23781,6 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return NonInviteServerTransaction; @@ -22904,6 +23812,11 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } _createClass(InviteServerTransaction, [{ + key: "C", + get: function get() { + return C; + } + }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -22912,10 +23825,10 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { }, { key: "timer_H", value: function timer_H() { - loggerist.debug("Timer H expired for transaction ".concat(this.id)); + debugist("Timer H expired for transaction ".concat(this.id)); if (this.state === C.STATUS_COMPLETED) { - loggerist.debug('ACK not received, dialog will be terminated'); + debugist('ACK not received, dialog will be terminated'); } this.stateChanged(C.STATUS_TERMINATED); @@ -22931,7 +23844,7 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { }, { key: "timer_L", value: function timer_L() { - loggerist.debug("Timer L expired for transaction ".concat(this.id)); + debugist("Timer L expired for transaction ".concat(this.id)); if (this.state === C.STATUS_ACCEPTED) { this.stateChanged(C.STATUS_TERMINATED); @@ -22943,7 +23856,7 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { value: function onTransportError() { if (!this.transportError) { this.transportError = true; - loggerist.debug("transport error occurred, deleting transaction ".concat(this.id)); + debugist("transport error occurred, deleting transaction ".concat(this.id)); if (this.resendProvisionalTimer !== null) { clearInterval(this.resendProvisionalTimer); @@ -23048,11 +23961,6 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } } } - }, { - key: "C", - get: function get() { - return C; - } }]); return InviteServerTransaction; @@ -23169,7 +24077,7 @@ module.exports = { InviteServerTransaction: InviteServerTransaction, checkTransaction: checkTransaction }; -},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Timers":22,"events":30}],24:[function(require,module,exports){ +},{"./Constants":2,"./SIPMessage":20,"./Timers":23,"debug":32,"events":31}],25:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -23178,13 +24086,15 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Logger = require('./Logger'); - var Socket = require('./Socket'); +var debug = require('debug')('JsSIP:Transport'); + +var debugerror = require('debug')('JsSIP:ERROR:Transport'); + var JsSIP_C = require('./Constants'); -var logger = new Logger('Transport'); +debugerror.log = console.warn.bind(console); /** * Constants */ @@ -23218,7 +24128,7 @@ module.exports = /*#__PURE__*/function () { _classCallCheck(this, Transport); - logger.debug('new()'); + debug('new()'); this.status = C.STATUS_DISCONNECTED; // Current socket. this.socket = null; // Socket collection. @@ -23233,7 +24143,7 @@ module.exports = /*#__PURE__*/function () { try { this.textDecoder = new TextDecoder('utf8'); } catch (error) { - logger.warn("cannot use TextDecoder: ".concat(error)); + debugerror("cannot use TextDecoder: ".concat(error)); } if (typeof sockets === 'undefined') { @@ -23268,15 +24178,30 @@ module.exports = /*#__PURE__*/function () { _createClass(Transport, [{ + key: "via_transport", + get: function get() { + return this.socket.via_transport; + } + }, { + key: "url", + get: function get() { + return this.socket.url; + } + }, { + key: "sip_uri", + get: function get() { + return this.socket.sip_uri; + } + }, { key: "connect", value: function connect() { - logger.debug('connect()'); + debug('connect()'); if (this.isConnected()) { - logger.debug('Transport is already connected'); + debug('Transport is already connected'); return; } else if (this.isConnecting()) { - logger.debug('Transport is connecting'); + debug('Transport is connecting'); return; } @@ -23300,7 +24225,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "disconnect", value: function disconnect() { - logger.debug('close()'); + debug('close()'); this.close_requested = true; this.recover_attempts = 0; this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer. @@ -23326,15 +24251,15 @@ module.exports = /*#__PURE__*/function () { }, { key: "send", value: function send(data) { - logger.debug('send()'); + debug('send()'); if (!this.isConnected()) { - logger.warn('unable to send message, transport is not connected'); + debugerror('unable to send message, transport is not connected'); return false; } var message = data.toString(); - logger.debug("sending message:\n\n".concat(message, "\n")); + debug("sending message:\n\n".concat(message, "\n")); return this.socket.send(message); } }, { @@ -23365,7 +24290,7 @@ module.exports = /*#__PURE__*/function () { k = this.recovery_options.max_interval; } - logger.debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); + debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); this.recovery_timer = setTimeout(function () { if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) { // Get the next available socket with higher weight. @@ -23458,21 +24383,21 @@ module.exports = /*#__PURE__*/function () { value: function _onData(data) { // CRLF Keep Alive response from server. Ignore it. if (data === '\r\n') { - logger.debug('received message with CRLF Keep Alive response'); + debug('received message with CRLF Keep Alive response'); return; } // Binary message. else if (typeof data !== 'string') { try { if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data)); } catch (evt) { - logger.debug('received binary message failed to be converted into string,' + ' message discarded'); + debug('received binary message failed to be converted into string,' + ' message discarded'); return; } - logger.debug("received binary message:\n\n".concat(data, "\n")); + debug("received binary message:\n\n".concat(data, "\n")); } // Text message. else { - logger.debug("received text message:\n\n".concat(data, "\n")); + debug("received text message:\n\n".concat(data, "\n")); } this.ondata({ @@ -23480,26 +24405,11 @@ module.exports = /*#__PURE__*/function () { message: data }); } - }, { - key: "via_transport", - get: function get() { - return this.socket.via_transport; - } - }, { - key: "url", - get: function get() { - return this.socket.url; - } - }, { - key: "sip_uri", - get: function get() { - return this.socket.sip_uri; - } }]); return Transport; }(); -},{"./Constants":2,"./Logger":9,"./Socket":21}],25:[function(require,module,exports){ +},{"./Constants":2,"./Socket":21,"debug":32}],26:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -23520,20 +24430,22 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; -var Logger = require('./Logger'); - var JsSIP_C = require('./Constants'); var Registrator = require('./Registrator'); var RTCSession = require('./RTCSession'); +var Subscriber = require('./Subscriber'); + +var Notifier = require('./Notifier'); + var Message = require('./Message'); var Transactions = require('./Transactions'); @@ -23554,7 +24466,11 @@ var sanityCheck = require('./sanityCheck'); var config = require('./Config'); -var logger = new Logger('UA'); +var debug = require('debug')('JsSIP:UA'); + +var debugerror = require('debug')('JsSIP:ERROR:UA'); + +debugerror.log = console.warn.bind(console); var C = { // UA status codes. STATUS_INIT: 0, @@ -23578,20 +24494,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(UA); - _createClass(UA, null, [{ - key: "C", - // Expose C object. - get: function get() { - return C; - } - }]); - function UA(configuration) { var _this; _classCallCheck(this, UA); - logger.debug('new() [configuration:%o]', configuration); + debug('new() [configuration:%o]', configuration); _this = _super.call(this); _this._cache = { credentials: {} @@ -23635,8 +24543,30 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(UA, [{ - key: "start", - // ================= + key: "C", + get: function get() { + return C; + } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "configuration", + get: function get() { + return this._configuration; + } + }, { + key: "transport", + get: function get() { + return this._transport; + } // ================= // High Level API // ================= @@ -23644,13 +24574,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * Connect to the server if status = STATUS_INIT. * Resume UA after being closed. */ + + }, { + key: "start", value: function start() { - logger.debug('start()'); + debug('start()'); if (this._status === C.STATUS_INIT) { this._transport.connect(); } else if (this._status === C.STATUS_USER_CLOSED) { - logger.debug('restarting UA'); // Disconnect. + debug('restarting UA'); // Disconnect. if (this._closeTimer !== null) { clearTimeout(this._closeTimer); @@ -23664,9 +24597,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._transport.connect(); } else if (this._status === C.STATUS_READY) { - logger.debug('UA is in READY status, not restarted'); + debug('UA is in READY status, not restarted'); } else { - logger.debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); + debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); } // Set dynamic configuration. @@ -23679,7 +24612,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "register", value: function register() { - logger.debug('register()'); + debug('register()'); this._dynConfiguration.register = true; this._registrator.register(); @@ -23691,7 +24624,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "unregister", value: function unregister(options) { - logger.debug('unregister()'); + debug('unregister()'); this._dynConfiguration.register = false; this._registrator.unregister(options); @@ -23736,7 +24669,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "call", value: function call(target, options) { - logger.debug('call()'); + debug('call()'); var session = new RTCSession(this); session.connect(target, options); return session; @@ -23755,11 +24688,31 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "sendMessage", value: function sendMessage(target, body, options) { - logger.debug('sendMessage()'); + debug('sendMessage()'); var message = new Message(this); message.send(target, body, options); return message; } + /** + * Create subscriber instance + */ + + }, { + key: "subscribe", + value: function subscribe(target, eventName, accept, options) { + debug('subscribe()'); + return new Subscriber(this, target, eventName, accept, options); + } + /** + * Create notifier instance + */ + + }, { + key: "notify", + value: function notify(subscribe, contentType, options) { + debug('notify()'); + return new Notifier(this, subscribe, contentType, options); + } /** * Terminate ongoing sessions. */ @@ -23767,7 +24720,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "terminateSessions", value: function terminateSessions(options) { - logger.debug('terminateSessions()'); + debug('terminateSessions()'); for (var idx in this._sessions) { if (!this._sessions[idx].isEnded()) { @@ -23785,12 +24738,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function stop() { var _this2 = this; - logger.debug('stop()'); // Remove dynamic settings. + debug('stop()'); // Remove dynamic settings. this._dynConfiguration = {}; if (this._status === C.STATUS_USER_CLOSED) { - logger.debug('UA already closed'); + debug('UA already closed'); return; } // Close registrator. @@ -23802,7 +24755,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { for (var session in this._sessions) { if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { - logger.debug("closing session ".concat(session)); + debug("closing session ".concat(session)); try { this._sessions[session].terminate(); @@ -23862,7 +24815,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return this._configuration.authorization_jwt; default: - logger.warn('get() | cannot get "%s" parameter in runtime', parameter); + debugerror('get() | cannot get "%s" parameter in runtime', parameter); return undefined; } } @@ -23914,7 +24867,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } default: - logger.warn('set() | cannot set "%s" parameter in runtime', parameter); + debugerror('set() | cannot set "%s" parameter in runtime', parameter); return false; } @@ -24043,7 +24996,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var method = request.method; // Check that request URI points to us. if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { - logger.debug('Request-URI does not point to us'); + debug('Request-URI does not point to us'); if (request.method !== JsSIP_C.ACK) { request.reply_sl(404); @@ -24090,6 +25043,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var message = new Message(this); message.init_incoming(request); + } else if (method === JsSIP_C.SUBSCRIBE) { + if (this.listeners('newSubscribe').length === 0) { + request.reply(405); + return; + } } else if (method === JsSIP_C.INVITE) { // Initial INVITE. if (!request.to_tag && this.listeners('newRTCSession').length === 0) { @@ -24126,7 +25084,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { session.init_incoming(request); } } else { - logger.warn('INVITE received but WebRTC is not supported'); + debugerror('INVITE received but WebRTC is not supported'); request.reply(488); } @@ -24143,7 +25101,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (session) { session.receiveRequest(request); } else { - logger.debug('received CANCEL request for a non existent session'); + debug('received CANCEL request for a non existent session'); } break; @@ -24164,6 +25122,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(200); break; + case JsSIP_C.SUBSCRIBE: + this.emit('newSubscribe', { + event: request.event, + request: request + }); + break; + default: request.reply(405); break; @@ -24180,7 +25145,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (session) { session.receiveRequest(request); } else { - logger.debug('received NOTIFY request for a non existent subscription'); + debug('received NOTIFY request for a non existent subscription'); request.reply(481, 'Subscription does not exist'); } } @@ -24284,7 +25249,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._transport.ondisconnect = onTransportDisconnect.bind(this); this._transport.ondata = onTransportData.bind(this); } catch (e) { - logger.warn(e); + debugerror(e); throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); } // Remove sockets instance from configuration object. @@ -24362,7 +25327,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } - logger.debug('configuration parameters after validation:'); + debug('configuration parameters after validation:'); for (var _parameter in this._configuration) { // Only show the user user configurable parameters. @@ -24370,48 +25335,29 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { switch (_parameter) { case 'uri': case 'registrar_server': - logger.debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); + debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); break; case 'password': case 'ha1': case 'authorization_jwt': - logger.debug("- ".concat(_parameter, ": NOT SHOWN")); + debug("- ".concat(_parameter, ": NOT SHOWN")); break; default: - logger.debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); + debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); } } } return; } - }, { + }], [{ key: "C", - get: function get() { + get: // Expose C object. + function get() { return C; } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "configuration", - get: function get() { - return this._configuration; - } - }, { - key: "transport", - get: function get() { - return this._transport; - } }]); return UA; @@ -24520,10 +25466,10 @@ function onTransportData(data) { } } } -},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Logger":9,"./Message":10,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Transactions":23,"./Transport":24,"./URI":26,"./Utils":27,"./sanityCheck":29,"events":30}],26:[function(require,module,exports){ +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"debug":32,"events":31}],27:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -24552,24 +25498,6 @@ var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { - _createClass(URI, null, [{ - key: "parse", - - /** - * Parse the given string and returns a JsSIP.URI instance or undefined if - * it is an invalid URI. - */ - value: function parse(uri) { - uri = Grammar.parse(uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } else { - return undefined; - } - } - }]); - function URI(scheme, user, host, port) { var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; @@ -24603,6 +25531,38 @@ module.exports = /*#__PURE__*/function () { } _createClass(URI, [{ + key: "scheme", + get: function get() { + return this._scheme; + }, + set: function set(value) { + this._scheme = value.toLowerCase(); + } + }, { + key: "user", + get: function get() { + return this._user; + }, + set: function set(value) { + this._user = value; + } + }, { + key: "host", + get: function get() { + return this._host; + }, + set: function set(value) { + this._host = value.toLowerCase(); + } + }, { + key: "port", + get: function get() { + return this._port; + }, + set: function set(value) { + this._port = value === 0 ? value : parseInt(value, 10) || null; + } + }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -24746,48 +25706,32 @@ module.exports = /*#__PURE__*/function () { return aor; } - }, { - key: "scheme", - get: function get() { - return this._scheme; - }, - set: function set(value) { - this._scheme = value.toLowerCase(); - } - }, { - key: "user", - get: function get() { - return this._user; - }, - set: function set(value) { - this._user = value; - } - }, { - key: "host", - get: function get() { - return this._host; - }, - set: function set(value) { - this._host = value.toLowerCase(); - } - }, { - key: "port", - get: function get() { - return this._port; - }, - set: function set(value) { - this._port = value === 0 ? value : parseInt(value, 10) || null; + }], [{ + key: "parse", + value: + /** + * Parse the given string and returns a JsSIP.URI instance or undefined if + * it is an invalid URI. + */ + function parse(uri) { + uri = Grammar.parse(uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } else { + return undefined; + } } }]); return URI; }(); -},{"./Constants":2,"./Grammar":7,"./Utils":27}],27:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -25315,7 +26259,7 @@ exports.cloneObject = function (obj) { var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return obj && Object.assign({}, obj) || fallback; }; -},{"./Constants":2,"./Grammar":7,"./URI":26}],28:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -25324,17 +26268,19 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Logger = require('./Logger'); - var Grammar = require('./Grammar'); -var logger = new Logger('WebSocketInterface'); +var debug = require('debug')('JsSIP:WebSocketInterface'); + +var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); + +debugerror.log = console.warn.bind(console); module.exports = /*#__PURE__*/function () { function WebSocketInterface(url) { _classCallCheck(this, WebSocketInterface); - logger.debug('new() [url:"%s"]', url); + debug('new() [url:"%s"]', url); this._url = url; this._sip_uri = null; this._via_transport = null; @@ -25342,10 +26288,10 @@ module.exports = /*#__PURE__*/function () { var parsed_url = Grammar.parse(url, 'absoluteURI'); if (parsed_url === -1) { - logger.warn("invalid WebSocket URI: ".concat(url)); + debugerror("invalid WebSocket URI: ".concat(url)); throw new TypeError("Invalid argument: ".concat(url)); } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { - logger.warn("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); + debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); throw new TypeError("Invalid argument: ".concat(url)); } else { this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws"); @@ -25354,15 +26300,33 @@ module.exports = /*#__PURE__*/function () { } _createClass(WebSocketInterface, [{ + key: "via_transport", + get: function get() { + return this._via_transport; + }, + set: function set(value) { + this._via_transport = value.toUpperCase(); + } + }, { + key: "sip_uri", + get: function get() { + return this._sip_uri; + } + }, { + key: "url", + get: function get() { + return this._url; + } + }, { key: "connect", value: function connect() { - logger.debug('connect()'); + debug('connect()'); if (this.isConnected()) { - logger.debug("WebSocket ".concat(this._url, " is already connected")); + debug("WebSocket ".concat(this._url, " is already connected")); return; } else if (this.isConnecting()) { - logger.debug("WebSocket ".concat(this._url, " is connecting")); + debug("WebSocket ".concat(this._url, " is connecting")); return; } @@ -25370,7 +26334,7 @@ module.exports = /*#__PURE__*/function () { this.disconnect(); } - logger.debug("connecting to WebSocket ".concat(this._url)); + debug("connecting to WebSocket ".concat(this._url)); try { this._ws = new WebSocket(this._url, 'sip'); @@ -25386,7 +26350,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "disconnect", value: function disconnect() { - logger.debug('disconnect()'); + debug('disconnect()'); if (this._ws) { // Unbind websocket event callbacks. @@ -25406,14 +26370,14 @@ module.exports = /*#__PURE__*/function () { }, { key: "send", value: function send(message) { - logger.debug('send()'); + debug('send()'); if (this.isConnected()) { this._ws.send(message); return true; } else { - logger.warn('unable to send message, WebSocket is not open'); + debugerror('unable to send message, WebSocket is not open'); return false; } } @@ -25434,7 +26398,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "_onOpen", value: function _onOpen() { - logger.debug("WebSocket ".concat(this._url, " connected")); + debug("WebSocket ".concat(this._url, " connected")); this.onconnect(); } }, { @@ -25443,10 +26407,10 @@ module.exports = /*#__PURE__*/function () { var wasClean = _ref.wasClean, code = _ref.code, reason = _ref.reason; - logger.debug("WebSocket ".concat(this._url, " closed")); + debug("WebSocket ".concat(this._url, " closed")); if (wasClean === false) { - logger.debug('WebSocket abrupt disconnection'); + debug('WebSocket abrupt disconnection'); } this.ondisconnect(!wasClean, code, reason); @@ -25455,54 +26419,35 @@ module.exports = /*#__PURE__*/function () { key: "_onMessage", value: function _onMessage(_ref2) { var data = _ref2.data; - logger.debug('received WebSocket message'); + debug('received WebSocket message'); this.ondata(data); } }, { key: "_onError", value: function _onError(e) { - logger.warn("WebSocket ".concat(this._url, " error: "), e); - } - }, { - key: "via_transport", - get: function get() { - return this._via_transport; - }, - set: function set(value) { - this._via_transport = value.toUpperCase(); - } - }, { - key: "sip_uri", - get: function get() { - return this._sip_uri; - } - }, { - key: "url", - get: function get() { - return this._url; + debugerror("WebSocket ".concat(this._url, " error: "), e); } }]); return WebSocketInterface; }(); -},{"./Grammar":7,"./Logger":9}],29:[function(require,module,exports){ +},{"./Grammar":7,"debug":32}],30:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } -var Logger = require('./Logger'); - var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); var Utils = require('./Utils'); -var logger = new Logger('sanityCheck'); // Checks for requests and responses. +var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses. + var all = [minimumHeaders]; // Checks for requests. @@ -25676,7 +26621,7 @@ function rfc3261_8_2_2_2() { function rfc3261_8_1_3_3() { if (message.getHeaders('via').length > 1) { - logger.debug('more than one Via header field present in the response, dropping the response'); + debug('more than one Via header field present in the response, dropping the response'); return false; } } @@ -25686,7 +26631,7 @@ function rfc3261_18_3_response() { contentLength = message.getHeader('content-length'); if (len < contentLength) { - logger.debug('message body length is lower than the value in Content-Length header field, dropping the response'); + debug('message body length is lower than the value in Content-Length header field, dropping the response'); return false; } } // Sanity Check functions for requests and responses. @@ -25699,7 +26644,7 @@ function minimumHeaders() { var header = _mandatoryHeaders[_i]; if (!message.hasHeader(header)) { - logger.debug("missing mandatory header field : ".concat(header, ", dropping the response")); + debug("missing mandatory header field : ".concat(header, ", dropping the response")); return false; } } @@ -25738,7 +26683,7 @@ function reply(status_code) { response += '\r\n'; transport.send(response); } -},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Utils":27}],30:[function(require,module,exports){ +},{"./Constants":2,"./SIPMessage":20,"./Utils":28,"debug":32}],31:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -26263,20 +27208,29 @@ function functionBindPolyfill(context) { }; } -},{}],31:[function(require,module,exports){ -(function (process){ +},{}],32:[function(require,module,exports){ +(function (process){(function (){ /* eslint-env browser */ /** * This is the web browser implementation of `debug()`. */ -exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.storage = localstorage(); +exports.destroy = (() => { + let warned = false; + + return () => { + if (!warned) { + warned = true; + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + }; +})(); /** * Colors. @@ -26437,18 +27391,14 @@ function formatArgs(args) { } /** - * Invokes `console.log()` when available. - * No-op when `console.log` is not a "function". + * Invokes `console.debug()` when available. + * No-op when `console.debug` is not a "function". + * If `console.debug` is not available, falls back + * to `console.log`. * * @api public */ -function log(...args) { - // This hackery is required for IE8/9, where - // the `console.log` function doesn't have 'apply' - return typeof console === 'object' && - console.log && - console.log(...args); -} +exports.log = console.debug || console.log || (() => {}); /** * Save `namespaces`. @@ -26530,8 +27480,8 @@ formatters.j = function (v) { } }; -}).call(this,require('_process')) -},{"./common":32,"_process":34}],32:[function(require,module,exports){ +}).call(this)}).call(this,require('_process')) +},{"./common":33,"_process":35}],33:[function(require,module,exports){ /** * This is the common logic for both the Node.js and web browser @@ -26546,16 +27496,12 @@ function setup(env) { createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = require('ms'); + createDebug.destroy = destroy; Object.keys(env).forEach(key => { createDebug[key] = env[key]; }); - /** - * Active `debug` instances. - */ - createDebug.instances = []; - /** * The currently active debug mode names, and names to skip. */ @@ -26597,6 +27543,7 @@ function setup(env) { */ function createDebug(namespace) { let prevTime; + let enableOverride = null; function debug(...args) { // Disabled? @@ -26626,7 +27573,7 @@ function setup(env) { args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { // If we encounter an escaped % then don't increase the array index if (match === '%%') { - return match; + return '%'; } index++; const formatter = createDebug.formatters[format]; @@ -26649,33 +27596,28 @@ function setup(env) { } debug.namespace = namespace; - debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); - debug.color = selectColor(namespace); - debug.destroy = destroy; + debug.color = createDebug.selectColor(namespace); debug.extend = extend; - // Debug.formatArgs = formatArgs; - // debug.rawLog = rawLog; + debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. + + Object.defineProperty(debug, 'enabled', { + enumerable: true, + configurable: false, + get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, + set: v => { + enableOverride = v; + } + }); - // env-specific initialization logic for debug instances + // Env-specific initialization logic for debug instances if (typeof createDebug.init === 'function') { createDebug.init(debug); } - createDebug.instances.push(debug); - return debug; } - function destroy() { - const index = createDebug.instances.indexOf(this); - if (index !== -1) { - createDebug.instances.splice(index, 1); - return true; - } - return false; - } - function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); newDebug.log = this.log; @@ -26713,11 +27655,6 @@ function setup(env) { createDebug.names.push(new RegExp('^' + namespaces + '$')); } } - - for (i = 0; i < createDebug.instances.length; i++) { - const instance = createDebug.instances[i]; - instance.enabled = createDebug.enabled(instance.namespace); - } } /** @@ -26792,6 +27729,14 @@ function setup(env) { return val; } + /** + * XXX DO NOT USE. This is a temporary stub function. + * XXX It WILL be removed in the next major release. + */ + function destroy() { + console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); + } + createDebug.enable(createDebug.load()); return createDebug; @@ -26799,7 +27744,7 @@ function setup(env) { module.exports = setup; -},{"ms":33}],33:[function(require,module,exports){ +},{"ms":34}],34:[function(require,module,exports){ /** * Helpers. */ @@ -26963,7 +27908,7 @@ function plural(ms, msAbs, n, name) { return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); } -},{}],34:[function(require,module,exports){ +},{}],35:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -27149,7 +28094,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],35:[function(require,module,exports){ +},{}],36:[function(require,module,exports){ var grammar = module.exports = { v: [{ name: 'version', @@ -27245,7 +28190,7 @@ var grammar = module.exports = { push: 'rtcpFbTrrInt', reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, names: ['payload', 'value'], - format: 'rtcp-fb:%d trr-int %d' + format: 'rtcp-fb:%s trr-int %d' }, { // a=rtcp-fb:98 nack rpsi @@ -27645,7 +28590,7 @@ Object.keys(grammar).forEach(function (key) { }); }); -},{}],36:[function(require,module,exports){ +},{}],37:[function(require,module,exports){ var parser = require('./parser'); var writer = require('./writer'); @@ -27658,7 +28603,7 @@ exports.parseRemoteCandidates = parser.parseRemoteCandidates; exports.parseImageAttributes = parser.parseImageAttributes; exports.parseSimulcastStreamList = parser.parseSimulcastStreamList; -},{"./parser":37,"./writer":38}],37:[function(require,module,exports){ +},{"./parser":38,"./writer":39}],38:[function(require,module,exports){ var toIntIfInt = function (v) { return String(Number(v)) === v ? Number(v) : v; }; @@ -27784,7 +28729,7 @@ exports.parseSimulcastStreamList = function (str) { }); }; -},{"./grammar":35}],38:[function(require,module,exports){ +},{"./grammar":36}],39:[function(require,module,exports){ var grammar = require('./grammar'); // customized util.format - discards excess arguments and can void middle ones @@ -27900,12 +28845,12 @@ module.exports = function (session, opts) { return sdp.join('\r\n') + '\r\n'; }; -},{"./grammar":35}],39:[function(require,module,exports){ +},{"./grammar":36}],40:[function(require,module,exports){ module.exports={ "name": "jssip", "title": "JsSIP", "description": "the Javascript SIP library", - "version": "3.7.11", + "version": "3.7.6", "homepage": "https://jssip.net", "contributors": [ "José Luis Millán (https://github.com/jmillan)", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index d5864aacb..b99c6a1ef 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -1,9 +1,9 @@ /* - * JsSIP v3.7.11 + * JsSIP v3.7.6 * the Javascript SIP library * Copyright: 2012-2021 * 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=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);n0)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":21,"./URI":26,"./Utils":27}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":39}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:d.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 o.IncomingResponse&&(s=n.status_code<200?d.STATUS_EARLY:d.STATUS_CONFIRMED);var i=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=i.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=i.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),h.debug("new ".concat(r," dialog created with status ").concat(this._state===d.STATUS_EARLY?"EARLY":"CONFIRMED"))}return s(e,null,[{key:"C",get:function(){return d}}]),s(e,[{key:"update",value:function(e,t){this._state=d.STATUS_CONFIRMED,h.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){h.debug("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=c.cloneArray(n.extraHeaders),s=c.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new a(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===l.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===l.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=c.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===l.CANCEL||e===l.ACK?this._local_seqnum:this._local_seqnum+=1;return new o.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===l.INVITE||e.method===l.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!==u.C.STATUS_ACCEPTED&&e.server_transaction.state!==u.C.STATUS_COMPLETED&&e.server_transaction.state!==u.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===u.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===l.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===u.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,"./Logger":9,"./SIPMessage":20,"./Transactions":23,"./Utils":27}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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":13,"../RequestSender":19,"../Transactions":23}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return o.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return o.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return o.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return o.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop)if(t.qop.indexOf("auth-int")>-1)this._qop="auth-int";else{if(!(t.qop.indexOf("auth")>-1))return o.warn('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=l||i.createRandomToken(12),this._nc+=1;var u,a,c=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-c.length)+c,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=i.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(a))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(i.calculateMD5(s||"")),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(a))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=null [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(a))),o.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Logger":9,"./Utils":27}],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 d=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}(),f=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:d,InvalidStateError:f,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:d,HEXDIG:f,WSP:_,OCTET:p,DQUOTE:m,SP:v,HTAB:g,alphanum:y,reserved:T,unreserved:C,mark:b,escaped:S,LWS:E,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,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:k,token_nodot:D,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:U,STAR:x,SLASH:P,EQUAL:M,LPAREN:L,RPAREN:q,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=L();if(null!==t){for(n=[],null===(r=K())&&null===(r=X())&&(r=e());null!==r;)n.push(r),null===(r=K())&&null===(r=X())&&(r=e());null!==n&&null!==(r=q())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:$,quoted_pair:X,SIP_URI_noparams:J,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:se,password:ie,hostport:oe,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:he,IPv6address:de,h16:fe,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:Ce,method_param:be,ttl_param:Se,maddr_param:Ee,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:De,hname:Ue,hvalue:xe,hnv_unreserved:Pe,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:Le,absoluteURI:qe,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:ze,scheme:$e,authority:Xe,srvr:Je,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:dt,extension_code:ft,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=qt())){for(t=[],o=i,null!==(n=j())&&null!==(r=qt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=qt())?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=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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;tl&&(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 d(){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 f(){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=b()),e}function b(){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 S(){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=f())&&null!==(r=f())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=e.join("")),null===e&&(i=s),e}function E(){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 A(){var e;return e=null!==(e=E())?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=A())?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=E();null!==s;)r.push(s),s=E();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],s=E();null!==s;)r.push(s),s=E();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 N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){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 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&&(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 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&&(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=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null!==t&&null!==(r=A())?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=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null!==t&&null!==(r=A())?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=A())?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=A())?(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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=A())?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=A())&&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=A())?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=E()))),e}function Y(){var e,t,r,s,o,l,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 z(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 $(){var e;return null===(e=E())&&(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 X(){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 J(){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,d;return h=i,d=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=ke())?c:"")?e=[e,t,s,l,u,c]:(e=null,i=d)):(e=null,i=d),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=S())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=S())&&(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=S())&&(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=S())&&(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=d())){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=de())?(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 de(){var e,t,r,s,l,u,c,h,d,f,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=fe())?(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,d,f,_,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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=fe())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,u,c,h,d,f,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(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=fe())?(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=fe())?e=[e,t]:(e=null,i=g),null===e&&(g=i,null!==(e=fe())?("::"===n.substr(i,2)?(t="::",i+=2):(t=null,0===o&&a('"::"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=_e())?e=[e,t,r,s,l,u,c,h,d,f,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?(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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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 fe(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,t,r,s;return s=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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,d,f;return h=i,d=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=d)):(e=null,i=d)):(e=null,i=d)):(e=null,i=d),null!==e&&(f=h,jn.host_type="IPv4",e=n.substring(i,f)),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=be())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ae())&&(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=k())))),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=k())),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 be(){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 Se(){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=An())?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 Ee(){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 Ae(){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=k())?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=Ne())&&null===(e=C())&&(e=S()),e}function Ne(){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 ke(){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=De())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?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=De())?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 De(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=Ue())?(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 Ue(){var e,t;if(null===(t=Pe())&&null===(t=C())&&(t=S()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());else e=null;return e}function xe(){var e,t;for(e=[],null===(t=Pe())&&null===(t=C())&&(t=S());null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());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=Le())&&null!==(r=v())&&null!==(s=et())?e=[e,t,n,r,s]:(e=null,i=o),e}function Le(){var e;return null===(e=Q())&&(e=qe()),e}function qe(){var e,t,r,s;return s=i,null!==(e=$e())?(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=Xe())&&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=S()),e}function Ve(){var e;return null===(e=C())&&null===(e=S())&&(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=ze();null!==t;)e.push(t),t=ze();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=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=S())&&(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 $e(){var e,t,r,s,l,u;if(s=i,l=i,null!==(e=d())){for(t=[],null===(r=d())&&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=d())&&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 Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){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=S())&&(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=S())&&(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,d,f;if(c=i,d=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=d)}else e=null,i=d;else e=null,i=d}else e=null,i=d;else e=null,i=d;return null!==e&&(f=c,e=void(jn.sip_version=n.substring(i,f))),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=k()),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=dt())&&null!==(r=v())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function dt(){var e,t,n;return t=i,null!==(e=ft())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function ft(){var e,t,n,r;return r=i,null!==(e=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=S())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=S())&&null===(t=O())&&null===(t=N())&&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=J())&&(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=k())){for(t=[],l=i,null!==(n=E())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=E())&&null!==(r=k())?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=z()),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=St()),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=bt())?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 bt(){var e,t,r,s,l,u,c,d,f;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&a('"0"')),null!==e?(d=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=d),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=c)):(e=null,i=c),null!==e&&(f=u,e=parseFloat(n.substring(i,f))),null===e&&(i=u),e}function St(){var e,t,n,r,s,o,l,u;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],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 Et(){var e;return null===(e=k())&&null===(e=le())&&(e=Y()),e}function At(){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=k())))),e}function Rt(){var e;return null===(e=wt())&&(e=St()),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=k())),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=Nt())&&(e=kt()),e}function Nt(){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=Dt()))))),e}function kt(){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=Dt())),e}function Dt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){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=k())?e=[e,t]:(e=null,i=r),e}function xt(){var e;return null===(e=Dt())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=Y()),e}function Lt(){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 qt(){var e,t,r,s,l,u;if(l=i,null!==(e=D())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?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=D())?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=St()),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=k())?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=E()))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=k()))if(null!==(t=E()))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=k())&&null!==(t=M())?(null===(n=k())&&(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=$t())&&null===(e=Jt())&&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=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,u,c,h,d;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=zt())){if(l=[],d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?u=[u,c]:(u=null,i=d);null!==u;){if(l.push(u),d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;null!==u&&null!==(c=zt())?u=[u,c]:(u=null,i=d)}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 zt(){var e;return null===(e=qe())&&(e=je()),e}function $t(){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=Xt())?e=[e,t,r]:(e=null,i=s),e}function Xt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Jt(){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=z())?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=k())),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,d,f;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(d=i,null!==(s=tn())){for(l=[],f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==u;)l.push(u),f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==l?s=[s,l]:(s=null,i=d)}else s=null,i=d;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=k())),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=St())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=St())?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=St()),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=St())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=St())?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=k()))),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=St()))),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=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=St()),e}function hn(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=bn())){for(r=[],u=i,null!==(s=G())&&null!==(o=dn())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=dn())?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 dn(){var e;return null===(e=fn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=St()),e}function fn(){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=An())?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=de()),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=k())?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=k())&&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=k()),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=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function bn(){var e,t,n,r,s;return r=i,null!==(e=Sn())?(s=i,null!==(t=W())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Sn(){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 En(){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 An(){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=St()),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=N())&&(t=E());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=E());return e}function Nn(){var e,t,r,s,l,u,c,h,d,f,_,p;return f=i,_=i,null!==(e=Dn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(d=Un())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=f,e[0],e=void(jn=n.substring(i+5,p))),null===e&&(i=f),e}function kn(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=f())&&null!==(n=f())&&null!==(r=f())?e=[e,t,n,r]:(e=null,i=s),e}function Dn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function xn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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=Ln())&&null===(e=qn())&&(e=St()),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=k())?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 Ln(){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=k())?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 qn(){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=Gn2&&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=d.cloneArray(r.extraHeaders),o=d.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 h.OutgoingRequest(c.MESSAGE,e,this._ua,null,i),t&&(this._request.body=t);var a=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),a.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=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.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=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.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=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.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){p.debug("MESSAGE failed"),this._close(),p.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){p.debug("MESSAGE succeeded"),this._close(),p.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27,events:30}],11:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),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":26}],12:[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=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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;w.debug("connect()");var r=e,s=v.cloneObject(t.eventHandlers),i=v.cloneArray(t.extraHeaders),o=v.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=v.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 p.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new p.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=v.newTag();var d=t.anonymous||!1,f={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:d,outbound:!0}),d?(f.from_display_name="Anonymous",f.from_uri=new R("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(f.from_uri=new R("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(f.from_display_name=t.fromDisplayName),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 y.InitialOutgoingInviteRequest(e,this._ua,f,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;w.debug("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=v.newTag(),this._createDialog(e,"UAS",!0)?(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,_.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,_.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("answer()");var n=this._request,r=v.cloneArray(t.extraHeaders),i=v.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=v.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=v.cloneObject(t.rtcOfferConstraints),h=!1,d=!1,f=!1,m=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new p.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new p.InvalidStateError(this._status);if(this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.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||(f=!0)),"video"===C.type&&(d=!0,C.direction&&"sendrecv"!==C.direction||(m=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var b,S=s(o.getAudioTracks());try{for(S.s();!(b=S.n()).done;){var E=b.value;o.removeTrack(E)}}catch(e){S.e(e)}finally{S.f()}}if(o&&!1===i.video){var A,R=s(o.getVideoTracks());try{for(R.s();!(A=R.n()).done;){var O=A.value;o.removeTrack(O)}}catch(e){R.e(e)}finally{R.f()}}o||void 0!==i.audio||(i.audio=f),o||void 0!==i.video||(i.video=m),o||h||c.offerToReceiveAudio||(i.audio=!1),o||d||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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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};w.debug('emit "sdp"'),e.emit("sdp",t);var r=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed("system",null,_.causes.WEBRTC_ERROR),w.warn('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,_.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&w.warn(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]:{};w.debug("terminate()");var n,r=t.cause||_.causes.BYE,s=v.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new p.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(w.debug("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||_.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,_.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(w.debug("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,_.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(w.debug("terminating session"),l=t.reason_phrase||_.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!==m.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===_.ACK&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===m.C.STATUS_TERMINATED&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(_.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]:{};w.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||_.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&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.InvalidStateError(this._status);if(i!==_.DTMF_TRANSPORT.INFO&&i!==_.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&&!v.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rb.C.MAX_DURATION?(w.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(b.C.MAX_DURATION," milliseconds")),r=b.C.MAX_DURATION):r=Math.abs(r):r=b.C.DEFAULT_DURATION,t.duration=r,s&&!v.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new b(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(w.debug("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.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};w.debug("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};w.debug("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(w.debug("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:_.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(w.debug("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:_.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;w.debug("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:_.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;w.debug("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 w.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(w.debug("receiveRequest()"),e.method===_.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,_.causes.CANCELED));else switch(e.method){case _.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:_.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",n);var r=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed("remote",e)}).catch(function(e){t.terminate({cause:_.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case _.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,_.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,_.causes.BYE)):e.reply(403,"Wrong Status");break;case _.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case _.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 b(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case _.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case _.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case _.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){w.warn("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.CONNECTION_ERROR,cause:_.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){w.warn("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:_.causes.REQUEST_TIMEOUT,cause:_.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){w.warn("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.DIALOG_ERROR,cause:_.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){w.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){w.debug("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(w.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(w.debug("_isReadyToReOffer() | session not established yet"),!1):(w.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(w.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(w.debug("close() | closing local MediaStream"),v.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){w.warn("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=g.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),ng.T2&&(n=g.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&&(w.debug("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(_.BYE),e._ended("remote",null,_.causes.NO_ACK))},g.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:_.causes.RTP_TIMEOUT,status_code:408,reason_phrase:_.causes.RTP_TIMEOUT})}),w.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(w.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return w.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return w.warn('emit "peerconnection:createanswerfailed" [error:%o]',e),n.emit("peerconnection:createanswerfailed",e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,w.warn('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 w.debug('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};w.debug('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()})})})}},{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 T(this,e,t,T.C.STATUS_EARLY)).error?(w.debug(o.error),this._failed("remote",e,_.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 T(this,e,t);return l.error?(w.debug(l.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;w.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("_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};w.debug('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.warn('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.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){w.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(w.debug("receiveRefer()"),!e.refer_to)return w.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==_.SIP)return w.debug("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);w.debug('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=v.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(w.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(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;w.debug("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(){w.debug("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new C(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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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,_.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,w.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&w.warn(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;w.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(w.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(_.ACK);var n=new T(this,e,"UAC");return void 0!==n.error?void w.debug(n.error):(this.sendRequest(_.ACK),void this.sendRequest(_.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){w.debug("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};w.debug('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.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=I.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,_.causes.MISSING_SDP),this._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};w.debug('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,_.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(_.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=v.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]:{};w.debug("sendReinvite()");var n=v.cloneArray(t.extraHeaders),r=v.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)};w.debug('emit "sdp"'),e.emit("sdp",s),e.sendRequest(_.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(_.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};w.debug('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.warn('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]:{};w.debug("sendUpdate()");var n=v.cloneArray(t.extraHeaders),r=v.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};w.debug('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.warn('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)};w.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(_.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(_.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){w.debug("acceptAndTerminate()");var r=[];t&&(n=n||_.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(_.ACK),this.sendRequest(_.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=d.parse(e),this._localHold&&!this._remoteHold){w.debug("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){w.debug("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){w.debug("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 d.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>=_.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>=_.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&&(w.debug("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===_.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w.warn("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:_.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){w.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){w.debug("session connecting"),w.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){w.debug("session progress"),w.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){w.debug("session accepted"),this._start_time=new Date,w.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){w.debug("session confirmed"),this._is_confirmed=!0,w.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){w.debug("session ended"),this._end_time=new Date,this._close(),w.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){w.debug("session failed"),w.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),w.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){w.debug("session onhold"),this._setLocalMediaStatus(),w.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){w.debug("session onunhold"),this._setLocalMediaStatus(),w.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onmute"),this._setLocalMediaStatus(),w.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onunmute"),this._setLocalMediaStatus(),w.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return I}},{key:"causes",get:function(){return _.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,"./Logger":9,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":22,"./Transactions":23,"./URI":26,"./Utils":27,events:30,"sdp-transform":36}],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;n1&&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 h.InvalidStateError(this._session.status);var r=d.cloneArray(n.extraHeaders);if(this.eventHandlers=d.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(c.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=_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):f.debug("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),a}(),t.exports.C=_},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":27,events:30}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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),d}()},{"../Constants":2,"../Exceptions":6,"../Utils":27,events:30}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(i.NOTIFY,{extraHeaders:["Event: ".concat(l.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(l.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"../Constants":2,"../Logger":9}],17:[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;n1&&void 0!==arguments[1]?arguments[1]:{};f.debug("sendRefer()");var r=d.cloneArray(n.extraHeaders),s=d.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):"",">");if(r.push(l),!r.some(function(e){return e.toLowerCase().startsWith("referred-by:")})){var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u)}r.push("Contact: ".concat(this._session.contact));var a=this._session.sendRequest(c.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,c.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,c.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,c.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,c.causes.DIALOG_ERROR)}}});this._id=a.cseq}},{key:"receiveNotify",value:function(e){if(f.debug("receiveNotify()"),e.body){var t=h.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.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){f.debug("REFER succeeded"),f.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){f.debug("REFER failed"),f.debug('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),a}()},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":27,events:30}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,s;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)a.debug("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var n=new l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new u(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,o.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")){a.debug("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a.debug("no Contact header pointing to us, response ignored");break}var s=r.getParam("expires");!s&&t.hasHeader("expires")&&(s=t.getHeader("expires")),s||(s=e._expires),(s=Number(s))<10&&(s=10);var l=s>64?1e3*s/2+Math.floor(1e3*(s/2-32)*Math.random()):1e3*s-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,o.causes.SIP_FAILURE_CODE));break;default:var u=i.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new u(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,o.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=i.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else a.debug("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}},{key:"_unregistered",value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:"registered",get:function(){return this._registered}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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")),this.setHeader("via",""),this.setHeader("max-forwards",p.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 v(l,a,u),this.setHeader("to",this.to.toString());var h,d=s.from_uri||r.configuration.uri,f={tag:s.from_tag||m.newTag()};h=void 0!==s.from_display_name?s.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new v(d,h,f),this.setHeader("from",this.from.toString());var _=s.call_id||r.configuration.jssip_id+m.createRandomToken(15);this.call_id=_,this.setHeader("call-id",_);var g=s.cseq||Math.floor(1e4*Math.random());this.cseq=g,this.setHeader("cseq","".concat(g," ").concat(t))}return d(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(e=m.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=g.parse(r,e.replace(/-/g,"_"));return-1===s?(this.headers[e].splice(t,1),void y.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=s,s)}y.debug('not so many "'.concat(e,'" headers present'))}else y.debug('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[m.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=f.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),e}(),S=function(e){s(n,b);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 d(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||p.REASON_PHRASE[e]||"",n=m.cloneArray(n);var a="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===p.INVITE&&e>100&&e<=200){var c,h=u(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var d=c.value;a+="Record-Route: ".concat(d,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var f,_=u(this.getHeaders("via"));try{for(_.s();!(f=_.n()).done;){var v=f.value;a+="Via: ".concat(v,"\r\n")}}catch(e){_.e(e)}finally{_.f()}!this.to_tag&&e>100?l+=";tag=".concat(m.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 p.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 p.UPDATE:this.ua.configuration.session_timers&&o.push("timer"),r&&o.push("ice"),o.push("replaces")}if(o.push("outbound"),this.method===p.OPTIONS?(a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(o,"\r\n"),r){var C=m.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||p.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(m.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,b);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:T,InitialOutgoingInviteRequest:C,IncomingRequest:S,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":27,"sdp-transform":36}],21:[function(e,t,n){"use strict";var r=e("./Logger"),s=e("./Utils"),i=e("./Grammar"),o=new r("Socket");n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return o.warn("undefined JsSIP.Socket instance"),!1;try{if(!s.isString(e.url))throw o.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!s.isString(e.via_transport))throw o.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===i.parse(e.sip_uri,"SIP_URI"))throw o.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!s.isFunction(e[t]))throw o.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch(e){return!1}return!0}},{"./Grammar":7,"./Logger":9,"./Utils":27}],22:[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}},{}],23:[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=100&&n<=199)switch(this.state){case b.STATUS_CALLING:this.stateChanged(b.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},m.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return b}}]),n}(),A=function(e){l(n,d);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(){y.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return b}}]),n}(),R=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){T.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,T.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case b.STATUS_TRYING:this.stateChanged(b.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case b.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 b.STATUS_TRYING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){s.timer_J()},m.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case b.STATUS_COMPLETED:}}},{key:"C",get:function(){return b}}]),n}(),w=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){C.debug("Timer H expired for transaction ".concat(this.id)),this.state===b.STATUS_COMPLETED&&C.debug("ACK not received, dialog will be terminated"),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){C.debug("Timer L expired for transaction ".concat(this.id)),this.state===b.STATUS_ACCEPTED&&(this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,C.debug("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(b.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 b.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===b.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){s.resend_provisional()},m.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){s.timer_L()},m.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case b.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case b.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(b.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},m.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:"C",get:function(){return b}}]),n}();t.exports={C:b,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:R,InviteServerTransaction:w,checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case _.INVITE:if(n=r.ist[t.via_branch]){switch(n.state){case b.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case b.STATUS_ACCEPTED:}return!0}break;case _.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===b.STATUS_ACCEPTED)return!1;if(n.state===b.STATUS_COMPLETED)return n.state=b.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},m.TIMER_I),!0;break;case _.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==b.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case b.STATUS_TRYING:break;case b.STATUS_PROCEEDING:case b.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Timers":22,events:30}],24:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),l.debug("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){l.warn("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!i.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,s;return t=e,(n=[{key:"connect",value:function(){l.debug("connect()"),this.isConnected()?l.debug("Transport is already connected"):this.isConnecting()?l.debug("Transport is connecting"):(this.close_requested=!1,this.status=u.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.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.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.debug("send()"),!this.isConnected())return l.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return l.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),l.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void l.debug("received binary message failed to be converted into string, message discarded")}l.debug("received binary message:\n\n".concat(e,"\n"))}else l.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else l.debug("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}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./Socket":21}],25:[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;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(E.settings,i))switch(i){case"uri":case"registrar_server":A.debug("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A.debug("- ".concat(i,": NOT SHOWN"));break;default:A.debug("- ".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,"./Logger":9,"./Message":10,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Transactions":23,"./Transport":24,"./URI":26,"./Utils":27,"./sanityCheck":29,events:30}],26:[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);n4&&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":27}],27:[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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,d,f,_,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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":26}],28:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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);n1)return d.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=h.str_utf8_length(i.body),t=i.getHeader("content-length");if(e0&&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 d(){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;t1&&(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=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=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):[]}},{}],31:[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":32,_process:34}],32:[function(e,t,n){t.exports=function(t){function n(e){let t=0;for(let n=0;n{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{r[e]=t[e]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}},{ms:33}],33:[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))}},{}],34:[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,d=-1;function f(){h&&a&&(h=!1,a.length?c=a.concat(c):d=-1,c.length&&_())}function _(){if(!h){var e=u(f);h=!0;for(var t=c.length;t;){for(a=c,c=[];++d1)for(var n=1;n1&&(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=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":35}],39:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.11",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag();var v=new f(l(s),t,"UAS");if(v.error)throw _(v.error),new Error("SUBSCRIBE missed Contact");return s._dialog=v,s._expires>0&&s._setExpiresTimer(),s}return t=m,r=[{key:"C",get:function(){return p}}],(n=[{key:"C",get:function(){return p}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&d("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),d('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(p.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){d("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){d("setActiveState()"),this._state===p.STATE_PENDING&&(this._state=p.STATE_ACTIVE)}},{key:"notify",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(d("notify()"),this._dialog){var n=this._stateNumberToString(this._state);if(this._state!==p.STATE_TERMINATED){var r=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);r<0&&(r=0),n+=";expires=".concat(r)}else this._terminated_reason&&(n+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(n+=";retry-after=".concat(this._terminated_retry_after));var s=this._headers.slice();s.push("Subscription-State: ".concat(n)),t&&s.push("Content-Type: ".concat(this._content_type)),this._dialog.sendRequest(c.NOTIFY,{body:t,extraHeaders:s,eventHandlers:{onRequestTimeout:function(){e._dialogTerminated(p.NOTIFY_RESPONSE_TIMEOUT)},onTransportError:function(){e._dialogTerminated(p.NOTIFY_TRANSPORT_ERROR)},onErrorResponse:function(t){401===t.status_code||407===t.status_code?e._dialogTerminated(p.NOTIFY_FAILED_AUTHENTICATION):e._dialogTerminated(p.NOTIFY_NON_OK_RESPONSE)},onDialogError:function(){e._dialogTerminated(p.NOTIFY_NON_OK_RESPONSE)}}})}else _("final notify has sent")}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;d("terminate()"),this._state=p.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._dialogTerminated(p.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_dialogTerminated",value:function(e){if(this._dialog){this._state=p.STATE_TERMINATED,clearTimeout(this._expires_timer),this._dialog&&(this._dialog.terminate(),this._dialog=null);var t=e===p.SUBSCRIPTION_EXPIRED;d('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._dialog&&(e._terminated_reason="timeout",e.notify(),e._dialogTerminated(p.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case p.STATE_PENDING:return"pending";case p.STATE_ACTIVE:return"active";case p.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),m}()},{"./Constants":2,"./Dialog":3,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e,this._headers)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._dialog?this._sendSubsequentSubscribe(t,n):this._sendInitialSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e,t){var n=this;if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}var r=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,r,{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onReceiveResponse:function(e){n._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return m(t.error),void this._dialogTerminated(v.SUBSCRIBE_BAD_OK_RESPONSE);this._dialog=t,p('emit "dialogCreated"'),this.emit("dialogCreated")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onSuccessResponse:function(e){n._receiveSubscribeResponse(e)},onErrorResponse:function(e){n._receiveSubscribeResponse(e)},onDialogError:function(e){n._receiveSubscribeResponse(e)}}})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._dialog&&(this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog.terminate(),this._dialog=null,p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file diff --git a/lib/Notifier.js b/lib/Notifier.js index e74bd0df5..5ade1c049 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -76,10 +76,6 @@ module.exports = class Notifier extends EventEmitter // Notifier state: pending, active, terminated. Not used: init, resp_wait. this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; - this._is_final_notify_sent = false; - - // To prevent duplicate emit 'terminated'. - this._is_terminated = false; // Optional. Used to build terminated Subscription-State. this._terminated_reason = null; @@ -114,7 +110,7 @@ module.exports = class Notifier extends EventEmitter this._target = subscribe.from.uri.user; subscribe.to_tag = Utils.newTag(); - // Create dialog for normal and fetch SUBSCRIBE + // Create dialog for normal and fetch-subscribe. const dialog = new Dialog(this, subscribe, 'UAS'); if (dialog.error) @@ -180,9 +176,8 @@ module.exports = class Notifier extends EventEmitter /** * User API */ - /** - * Should be called after creating the Notifier instance and setting the event handlers. + * Please call after creating the Notifier instance and setting the event handlers. */ start() { @@ -205,7 +200,7 @@ module.exports = class Notifier extends EventEmitter } /** - * Send the initial and subsequent NOTIFY request. + * Send the initial and subsequent notify request. * @param {string} body - notify request body. */ notify(body = null) @@ -213,7 +208,7 @@ module.exports = class Notifier extends EventEmitter debug('notify()'); // Prevent send notify after final notify. - if (this._is_final_notify_sent) + if (!this._dialog) { debugerror('final notify has sent'); @@ -254,11 +249,6 @@ module.exports = class Notifier extends EventEmitter headers.push(`Content-Type: ${this._content_type}`); } - if (!this._dialog) - { - throw new Error('no dialog'); - } - this._dialog.sendRequest(JsSIP_C.NOTIFY, { body, extraHeaders : headers, @@ -307,7 +297,6 @@ module.exports = class Notifier extends EventEmitter this.notify(body); - this._is_final_notify_sent = true; this._dialogTerminated(C.SEND_FINAL_NOTIFY); } @@ -332,18 +321,18 @@ module.exports = class Notifier extends EventEmitter */ _dialogTerminated(termination_code) { - if (this._is_terminated) + if (!this._dialog) { return; } - this._is_terminated = true; this._state = C.STATE_TERMINATED; clearTimeout(this._expires_timer); if (this._dialog) { this._dialog.terminate(); + this._dialog = null; } const send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; @@ -359,13 +348,12 @@ module.exports = class Notifier extends EventEmitter clearTimeout(this._expires_timer); this._expires_timer = setTimeout(() => { - if (this._is_final_notify_sent) + if (!this._dialog) { return; } this._terminated_reason = 'timeout'; - this._is_final_notify_sent = true; this.notify(); this._dialogTerminated(C.SUBSCRIPTION_EXPIRED); }, this._expires * 1000); diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 26c2f2e3b..dc050b228 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -18,10 +18,11 @@ const C = { SUBSCRIBE_RESPONSE_TIMEOUT : 0, SUBSCRIBE_TRANSPORT_ERROR : 1, SUBSCRIBE_NON_OK_RESPONSE : 2, - SUBSCRIBE_FAILED_AUTHENTICATION : 3, - UNSUBSCRIBE_TIMEOUT : 4, - RECEIVE_FINAL_NOTIFY : 5, - RECEIVE_BAD_NOTIFY : 6, + SUBSCRIBE_BAD_OK_RESPONSE : 3, + SUBSCRIBE_FAILED_AUTHENTICATION : 4, + UNSUBSCRIBE_TIMEOUT : 5, + RECEIVE_FINAL_NOTIFY : 6, + RECEIVE_BAD_NOTIFY : 7, // Subscriber states. STATE_PENDING : 0, @@ -88,7 +89,6 @@ module.exports = class Subscriber extends EventEmitter this._ua = ua; this._target = target; - this._accept = accept; if (expires !== 0 && !expires) { @@ -100,7 +100,7 @@ module.exports = class Subscriber extends EventEmitter // Used to subscribe with body. this._content_type = contentType; - // Set initial SUBSCRIBE parameters. + // Set initial subscribe parameters. this._params = Utils.cloneObject(params); if (!this._params.from_uri) @@ -112,7 +112,7 @@ module.exports = class Subscriber extends EventEmitter this._params.to_tag = null; this._params.call_id = Utils.createRandomToken(20); - // Create cseq if not defined custom cseq. + // Create subscribe cseq if not defined custom cseq. if (this._params.cseq === undefined) { this._params.cseq = Math.floor((Math.random() * 10000) + 1); @@ -121,8 +121,8 @@ module.exports = class Subscriber extends EventEmitter // Subscriber state. this._state = C.STATE_INIT; + // Dialog this._dialog = null; - this._request = null; // To refresh subscription. this._expires_timer = null; @@ -131,10 +131,7 @@ module.exports = class Subscriber extends EventEmitter // To prevent duplicate un-subscribe sending. this._send_unsubscribe = false; - // To prevent duplicate emit terminated event. - this._is_terminated = false; - - // After send un-subscribe wait final NOTIFY limited time. + // After send un-subscribe wait final notify limited time. this._unsubscribe_timeout_timer = null; // Custom session empty object for high level use. @@ -161,7 +158,7 @@ module.exports = class Subscriber extends EventEmitter this._headers = this._headers.concat([ `Event: ${eventValue}`, `Expires: ${this._expires}`, - `Accept: ${this._accept}` + `Accept: ${accept}` ]); if (!this._headers.find((header) => header.startsWith('Contact'))) @@ -275,10 +272,10 @@ module.exports = class Subscriber extends EventEmitter const body = request.body; - // Check if the NOTIFY is final. + // Check if the notify is final. const is_final = new_state === C.STATE_TERMINATED; - // Notify event fired for NOTIFY with body. + // Notify event fired only for notify with body. if (body) { const content_type = request.getHeader('content-type'); @@ -306,7 +303,7 @@ module.exports = class Subscriber extends EventEmitter */ /** - * Send the initial (non-fetch) and subsequent SUBSCRIBE. + * Send the initial (non-fetch) and subsequent subscribe. * @param {string} body - subscribe request body. */ subscribe(body = null) @@ -326,8 +323,8 @@ module.exports = class Subscriber extends EventEmitter /** * terminate. - * Send un-SUBSCRIBE or fetch-SUBSCRIBE (with Expires: 0). - * @param {string} body - Un-subscribe request body + * Send un-subscribe or fetch-subscribe (with Expires: 0). + * @param {string} body - un-subscribe request body */ terminate(body = null) { @@ -350,7 +347,7 @@ module.exports = class Subscriber extends EventEmitter if (!this._dialog) { - // Fetch-SUBSCRIBE is the first and last one. + // fetch-subscribe - initial subscribe with Expires: 0. this._sendInitialSubscribe(body, headers); } else @@ -399,10 +396,10 @@ module.exports = class Subscriber extends EventEmitter headers.push(`Content-Type: ${this._content_type}`); } - this._request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, + const request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); - const request_sender = new RequestSender(this._ua, this._request, { + const request_sender = new RequestSender(this._ua, request, { onRequestTimeout : () => { this.onRequestTimeout(); @@ -411,10 +408,6 @@ module.exports = class Subscriber extends EventEmitter { this.onTransportError(); }, - onAuthenticated : (request) => - { - this._request = request; - }, onReceiveResponse : (response) => { this._receiveSubscribeResponse(response); @@ -436,17 +429,16 @@ module.exports = class Subscriber extends EventEmitter if (dialog.error) { // OK response without Contact - debug(dialog.error); - this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); + debugerror(dialog.error); + this._dialogTerminated(C.SUBSCRIBE_BAD_OK_RESPONSE); return; } this._dialog = dialog; - // After the event dialog created. - debug('emit "initialSubscribeOK"'); - this.emit('initialSubscribeOK'); + debug('emit "dialogCreated"'); + this.emit('dialogCreated'); } // Check expires value. @@ -456,7 +448,7 @@ module.exports = class Subscriber extends EventEmitter { debugerror('response without Expires header'); - // RFC 6665 3.1.1 SUBSCRIBE OK must contain Expires header. + // RFC 6665 3.1.1 subscribe OK response must contain Expires header. // Use workaround expires value. expires_value = '900'; } @@ -528,22 +520,19 @@ module.exports = class Subscriber extends EventEmitter _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) { // To prevent duplicate emit terminated event. - if (this._is_terminated) + if (!this._dialog) { return; } - this._is_terminated = true; this._state = C.STATE_TERMINATED; // Clear timers. clearTimeout(this._expires_timer); clearTimeout(this._unsubscribe_timeout_timer); - if (this._dialog) - { - this._dialog.terminate(); - } + this._dialog.terminate(); + this._dialog = null; debug(`emit "terminated" code=${terminationCode}`); this.emit('terminated', terminationCode, reason, retryAfter); From 51348932eb8e6ffef9dcadb3edf43c4042f57135 Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 4 Jul 2021 11:07:15 +0300 Subject: [PATCH 50/70] updates jssip from master --- dist/jssip.js | 2847 ++++++++++++++++++--------------------------- dist/jssip.min.js | 4 +- 2 files changed, 1126 insertions(+), 1725 deletions(-) diff --git a/dist/jssip.js b/dist/jssip.js index 4dbcca163..b3db2d3ea 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -1,5 +1,5 @@ /* - * JsSIP v3.7.6 + * JsSIP v3.8.0 * the Javascript SIP library * Copyright: 2012-2021 * Homepage: https://jssip.net @@ -9,7 +9,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -294,7 +294,7 @@ exports.load = function (dst, src) { } } }; -},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],2:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":22,"./URI":27,"./Utils":28}],2:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -462,7 +462,7 @@ module.exports = { 604: 'Does Not Exist Anywhere', 606: 'Not Acceptable' }, - ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE', + 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, @@ -479,6 +479,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var SIPMessage = require('./SIPMessage'); var JsSIP_C = require('./Constants'); @@ -489,8 +491,7 @@ var Dialog_RequestSender = require('./Dialog/RequestSender'); var Utils = require('./Utils'); -var debug = require('debug')('JsSIP:Dialog'); - +var logger = new Logger('Dialog'); var C = { // Dialog states. STATUS_EARLY: 1, @@ -498,6 +499,14 @@ var C = { }; // RFC 3261 12.1. module.exports = /*#__PURE__*/function () { + _createClass(Dialog, null, [{ + key: "C", + // Expose C object. + get: function get() { + return C; + } + }]); + function Dialog(owner, message, type) { var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED; @@ -557,45 +566,14 @@ module.exports = /*#__PURE__*/function () { this._ua.newDialog(this); - debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); + logger.debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); } _createClass(Dialog, [{ - key: "id", - get: function get() { - return this._id; - } - }, { - key: "local_seqnum", - get: function get() { - return this._local_seqnum; - }, - set: function set(num) { - this._local_seqnum = num; - } - }, { - key: "owner", - get: function get() { - return this._owner; - } - }, { - key: "uac_pending_reply", - get: function get() { - return this._uac_pending_reply; - }, - set: function set(pending) { - this._uac_pending_reply = pending; - } - }, { - key: "uas_pending_reply", - get: function get() { - return this._uas_pending_reply; - } - }, { key: "update", value: function update(message, type) { this._state = C.STATUS_CONFIRMED; - debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); + logger.debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); if (type === 'UAC') { // RFC 3261 13.2.2.4. @@ -605,7 +583,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "terminate", value: function terminate() { - debug("dialog ".concat(this._id.toString(), " deleted")); + logger.debug("dialog ".concat(this._id.toString(), " deleted")); this._ua.destroyDialog(this); } @@ -736,17 +714,42 @@ module.exports = /*#__PURE__*/function () { return true; } - }], [{ - key: "C", - get: // Expose C object. - function get() { - return C; + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "local_seqnum", + get: function get() { + return this._local_seqnum; + }, + set: function set(num) { + this._local_seqnum = num; + } + }, { + key: "owner", + get: function get() { + return this._owner; + } + }, { + key: "uac_pending_reply", + get: function get() { + return this._uac_pending_reply; + }, + set: function set(pending) { + this._uac_pending_reply = pending; + } + }, { + key: "uas_pending_reply", + get: function get() { + return this._uas_pending_reply; } }]); return Dialog; }(); -},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,"debug":32}],4:[function(require,module,exports){ +},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":21,"./Transactions":24,"./Utils":28}],4:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -795,11 +798,6 @@ module.exports = /*#__PURE__*/function () { } _createClass(DialogRequestSender, [{ - key: "request", - get: function get() { - return this._request; - } - }, { key: "send", value: function send() { var _this = this; @@ -865,11 +863,16 @@ module.exports = /*#__PURE__*/function () { this._eventHandlers.onErrorResponse(response); } } + }, { + key: "request", + get: function get() { + return this._request; + } }]); return DialogRequestSender; }(); -},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(require,module,exports){ +},{"../Constants":2,"../RTCSession":14,"../RequestSender":20,"../Transactions":24}],5:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -878,13 +881,11 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Utils = require('./Utils'); - -var debug = require('debug')('JsSIP:DigestAuthentication'); +var Logger = require('./Logger'); -var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); +var Utils = require('./Utils'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('DigestAuthentication'); module.exports = /*#__PURE__*/function () { function DigestAuthentication(credentials) { @@ -917,7 +918,7 @@ module.exports = /*#__PURE__*/function () { return this._ha1; default: - debugerror('get() | cannot get "%s" parameter', parameter); + logger.warn('get() | cannot get "%s" parameter', parameter); return undefined; } } @@ -944,7 +945,7 @@ module.exports = /*#__PURE__*/function () { if (this._algorithm) { if (this._algorithm !== 'MD5') { - debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); + logger.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); return false; } } else { @@ -952,12 +953,12 @@ module.exports = /*#__PURE__*/function () { } if (!this._nonce) { - debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); + logger.warn('authenticate() | challenge without Digest nonce, authentication aborted'); return false; } if (!this._realm) { - debugerror('authenticate() | challenge without Digest realm, authentication aborted'); + logger.warn('authenticate() | challenge without Digest realm, authentication aborted'); return false; } // If no plain SIP password is provided. @@ -965,13 +966,13 @@ module.exports = /*#__PURE__*/function () { if (!this._credentials.password) { // If ha1 is not provided we cannot authenticate. if (!this._credentials.ha1) { - debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); + logger.warn('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); return false; } // If the realm does not match the stored realm we cannot authenticate. if (this._credentials.realm !== this._realm) { - debugerror('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); + logger.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm); return false; } } // 'qop' can contain a list of values (Array). Let's choose just one. @@ -984,7 +985,7 @@ module.exports = /*#__PURE__*/function () { this._qop = 'auth'; } else { // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. - debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); + logger.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); return false; } } else { @@ -1021,26 +1022,26 @@ module.exports = /*#__PURE__*/function () { // HA2 = MD5(A2) = MD5(method:digestURI). a2 = "".concat(this._method, ":").concat(this._uri); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + logger.debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2)); } else if (this._qop === 'auth-int') { // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)). a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : '')); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + logger.debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2)); } else if (this._qop === null) { // HA2 = MD5(A2) = MD5(method:digestURI). a2 = "".concat(this._method, ":").concat(this._uri); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). + logger.debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2)); } - debug('authenticate() | response generated'); + logger.debug('authenticate() | response generated'); return true; } /** @@ -1079,7 +1080,7 @@ module.exports = /*#__PURE__*/function () { return DigestAuthentication; }(); -},{"./Utils":28,"debug":32}],6:[function(require,module,exports){ +},{"./Logger":9,"./Utils":28}],6:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -1098,7 +1099,7 @@ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } @@ -16096,7 +16097,7 @@ module.exports = function () { result.SyntaxError.prototype = Error.prototype; return result; }(); -},{"./NameAddrHeader":10,"./URI":27}],8:[function(require,module,exports){ +},{"./NameAddrHeader":11,"./URI":27}],8:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -16145,7 +16146,61 @@ module.exports = { } }; -},{"../package.json":40,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":26,"./URI":27,"./Utils":28,"./WebSocketInterface":29,"debug":32}],9:[function(require,module,exports){ +},{"../package.json":40,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":11,"./UA":26,"./URI":27,"./Utils":28,"./WebSocketInterface":29,"debug":32}],9:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var debug = require('debug'); + +var APP_NAME = 'JsSIP'; + +module.exports = /*#__PURE__*/function () { + function Logger(prefix) { + _classCallCheck(this, Logger); + + if (prefix) { + this._debug = debug["default"]("".concat(APP_NAME, ":").concat(prefix)); + this._warn = debug["default"]("".concat(APP_NAME, ":WARN:").concat(prefix)); + this._error = debug["default"]("".concat(APP_NAME, ":ERROR:").concat(prefix)); + } else { + this._debug = debug["default"](APP_NAME); + this._warn = debug["default"]("".concat(APP_NAME, ":WARN")); + this._error = debug["default"]("".concat(APP_NAME, ":ERROR")); + } + /* eslint-disable no-console */ + + + this._debug.log = console.info.bind(console); + this._warn.log = console.warn.bind(console); + this._error.log = console.error.bind(console); + /* eslint-enable no-console */ + } + + _createClass(Logger, [{ + key: "debug", + get: function get() { + return this._debug; + } + }, { + key: "warn", + get: function get() { + return this._warn; + } + }, { + key: "error", + get: function get() { + return this._error; + } + }]); + + return Logger; +}(); +},{"debug":32}],10:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -16166,12 +16221,14 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); @@ -16182,7 +16239,7 @@ var RequestSender = require('./RequestSender'); var Exceptions = require('./Exceptions'); -var debug = require('debug')('JsSIP:Message'); +var logger = new Logger('Message'); module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(Message, _EventEmitter); @@ -16209,21 +16266,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Message, [{ - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { key: "send", value: function send(target, body) { var _this2 = this; @@ -16423,11 +16465,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_failed", value: function _failed(originator, response, cause) { - debug('MESSAGE failed'); + logger.debug('MESSAGE failed'); this._close(); - debug('emit "failed"'); + logger.debug('emit "failed"'); this.emit('failed', { originator: originator, response: response || null, @@ -16437,21 +16479,36 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_succeeded", value: function _succeeded(originator, response) { - debug('MESSAGE succeeded'); + logger.debug('MESSAGE succeeded'); this._close(); - debug('emit "succeeded"'); + logger.debug('emit "succeeded"'); this.emit('succeeded', { originator: originator, response: response }); } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } }]); return Message; }(EventEmitter); -},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],10:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28,"events":31}],11:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -16465,6 +16522,24 @@ var URI = require('./URI'); var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { + _createClass(NameAddrHeader, null, [{ + key: "parse", + + /** + * Parse the given string and returns a NameAddrHeader instance or undefined if + * it is an invalid NameAddrHeader. + */ + value: function parse(name_addr_header) { + name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); + + if (name_addr_header !== -1) { + return name_addr_header; + } else { + return undefined; + } + } + }]); + function NameAddrHeader(uri, display_name, parameters) { _classCallCheck(this, NameAddrHeader); @@ -16486,19 +16561,6 @@ module.exports = /*#__PURE__*/function () { } _createClass(NameAddrHeader, [{ - key: "uri", - get: function get() { - return this._uri; - } - }, { - key: "display_name", - get: function get() { - return this._display_name; - }, - set: function set(value) { - this._display_name = value === 0 ? '0' : value; - } - }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -16563,27 +16625,24 @@ module.exports = /*#__PURE__*/function () { return body; } - }], [{ - key: "parse", - value: - /** - * Parse the given string and returns a NameAddrHeader instance or undefined if - * it is an invalid NameAddrHeader. - */ - function parse(name_addr_header) { - name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header'); - - if (name_addr_header !== -1) { - return name_addr_header; - } else { - return undefined; - } + }, { + key: "uri", + get: function get() { + return this._uri; + } + }, { + key: "display_name", + get: function get() { + return this._display_name; + }, + set: function set(value) { + this._display_name = value === 0 ? '0' : value; } }]); return NameAddrHeader; }(); -},{"./Grammar":7,"./URI":27}],11:[function(require,module,exports){ +},{"./Grammar":7,"./URI":27}],12:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -16604,402 +16663,309 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; -var JsSIP_C = require('./Constants'); +var Logger = require('./Logger'); -var Utils = require('./Utils'); +var JsSIP_C = require('./Constants'); -var Dialog = require('./Dialog'); +var SIPMessage = require('./SIPMessage'); -var debug = require('debug')('JsSIP:Notifier'); +var Utils = require('./Utils'); -var debugerror = require('debug')('JsSIP:ERROR:Notifier'); +var RequestSender = require('./RequestSender'); -debugerror.log = console.warn.bind(console); -/** - * Termination codes. - */ +var Exceptions = require('./Exceptions'); -var C = { - // Termination codes. - NOTIFY_RESPONSE_TIMEOUT: 0, - NOTIFY_TRANSPORT_ERROR: 1, - NOTIFY_NON_OK_RESPONSE: 2, - NOTIFY_FAILED_AUTHENTICATION: 3, - SEND_FINAL_NOTIFY: 4, - RECEIVE_UNSUBSCRIBE: 5, - SUBSCRIPTION_EXPIRED: 6, - // Notifer states - STATE_PENDING: 0, - STATE_ACTIVE: 1, - STATE_TERMINATED: 2 -}; -/** - * RFC 6665 Notifier implementation. - */ +var logger = new Logger('Options'); module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(Notifier, _EventEmitter); + _inherits(Options, _EventEmitter); - var _super = _createSuper(Notifier); + var _super = _createSuper(Options); - /** - * @param {UA} ua - JsSIP User Agent instance. - * @param {IncomingRequest} subscribe - Subscribe request. - * @param {string} contentType - Content-Type header value. - * @param {NotifierOptions} options - Optional parameters. - * @param {Array} extraHeaders - Additional SIP headers. - * @param {string} allowEvents - Allow-Events header value. - * @param {boolean} pending - Set initial dialog state as "pending". - */ - function Notifier(ua, subscribe, contentType, _ref) { + function Options(ua) { var _this; - var extraHeaders = _ref.extraHeaders, - allowEvents = _ref.allowEvents, - pending = _ref.pending; - - _classCallCheck(this, Notifier); + _classCallCheck(this, Options); - debug('new'); _this = _super.call(this); - - if (!subscribe) { - throw new TypeError('subscribe is undefined'); - } - - if (!contentType) { - throw new TypeError('contentType is undefined'); - } - _this._ua = ua; - _this._initial_subscribe = subscribe; - _this._expires_timestamp = null; - _this._expires_timer = null; // Notifier state: pending, active, terminated. Not used: init, resp_wait. + _this._request = null; + _this._closed = false; + _this._direction = null; + _this._local_identity = null; + _this._remote_identity = null; // Whether an incoming message has been replied. - _this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; // Optional. Used to build terminated Subscription-State. + _this._is_replied = false; // Custom message empty object for high level use. - _this._terminated_reason = null; - _this._terminated_retry_after = null; // Custom session empty object for high level use. + _this._data = {}; + return _this; + } - _this.data = {}; - _this._dialog = null; - var eventName = subscribe.getHeader('event'); - _this._content_type = contentType; - _this._expires = parseInt(subscribe.getHeader('expires')); - _this._headers = Utils.cloneArray(extraHeaders); + _createClass(Options, [{ + key: "send", + value: function send(target, body) { + var _this2 = this; - _this._headers.push("Event: ".concat(eventName)); // Use contact from extraHeaders or create it. + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + var originalTarget = target; + if (target === undefined) { + throw new TypeError('A target is required for OPTIONS'); + } // Check target validity. - _this._contact = _this._headers.find(function (header) { - return header.startsWith('Contact'); - }); - if (!_this._contact) { - _this._contact = "Contact: "); + target = this._ua.normalizeTarget(target); - _this._headers.push(_this._contact); - } + if (!target) { + throw new TypeError("Invalid target: ".concat(originalTarget)); + } // Get call options. - if (allowEvents) { - _this._headers.push("Allow-Events: ".concat(allowEvents)); - } - _this._target = subscribe.from.uri.user; - subscribe.to_tag = Utils.newTag(); // Create dialog for normal and fetch-subscribe. + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var eventHandlers = Utils.cloneObject(options.eventHandlers); + var contentType = options.contentType || 'application/sdp'; // Set event handlers. - var dialog = new Dialog(_assertThisInitialized(_this), subscribe, 'UAS'); + for (var event in eventHandlers) { + if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) { + this.on(event, eventHandlers[event]); + } + } - if (dialog.error) { - debugerror(dialog.error); - throw new Error('SUBSCRIBE missed Contact'); - } + extraHeaders.push("Content-Type: ".concat(contentType)); + this._request = new SIPMessage.OutgoingRequest(JsSIP_C.OPTIONS, target, this._ua, null, extraHeaders); - _this._dialog = dialog; + if (body) { + this._request.body = body; + } - if (_this._expires > 0) { - // Set expires timer and time-stamp. - _this._setExpiresTimer(); - } - - return _this; - } - /** - * Dialog callback. - * Called also for initial subscribe. - * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). - */ + var request_sender = new RequestSender(this._ua, this._request, { + onRequestTimeout: function onRequestTimeout() { + _this2._onRequestTimeout(); + }, + onTransportError: function onTransportError() { + _this2._onTransportError(); + }, + onReceiveResponse: function onReceiveResponse(response) { + _this2._receiveResponse(response); + } + }); + this._newOptions('local', this._request); - _createClass(Notifier, [{ - key: "C", - get: function get() { - return C; + request_sender.send(); } }, { - key: "receiveRequest", - value: function receiveRequest(request) { - if (request.method !== JsSIP_C.SUBSCRIBE) { - request.reply(405); - return; - } - - var expiresValue = request.getHeader('expires'); + key: "init_incoming", + value: function init_incoming(request) { + this._request = request; - if (expiresValue === undefined || expiresValue === null) { - // Missed header Expires. RFC 6665 3.1.1. Set default expires value. - expiresValue = '900'; - debug("Missed expires header. Set by default ".concat(expiresValue)); - } + this._newOptions('remote', request); // Reply with a 200 OK if the user didn't reply. - this._expires = parseInt(expiresValue); - request.reply(200, null, ["Expires: ".concat(this._expires), "".concat(this._contact)]); - var body = request.body; - var content_type = request.getHeader('content-type'); - var is_unsubscribe = this._expires === 0; - if (!is_unsubscribe) { - this._setExpiresTimer(); + if (!this._is_replied) { + this._is_replied = true; + request.reply(200); } - debug('emit "subscribe"'); - this.emit('subscribe', is_unsubscribe, request, body, content_type); - - if (is_unsubscribe) { - this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); - } + this._close(); } /** - * User API - */ - - /** - * Please call after creating the Notifier instance and setting the event handlers. + * Accept the incoming Options + * Only valid for incoming Options */ }, { - key: "start", - value: function start() { - debug('start()'); - this.receiveRequest(this._initial_subscribe); - } - /** - * Switch pending dialog state to active. - */ + key: "accept", + value: function accept() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var body = options.body; - }, { - key: "setActiveState", - value: function setActiveState() { - debug('setActiveState()'); + if (this._direction !== 'incoming') { + throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Options'); + } - if (this._state === C.STATE_PENDING) { - this._state = C.STATE_ACTIVE; + if (this._is_replied) { + throw new Error('incoming Options already replied'); } + + this._is_replied = true; + + this._request.reply(200, null, extraHeaders, body); } /** - * Send the initial and subsequent notify request. - * @param {string} body - notify request body. + * Reject the incoming Options + * Only valid for incoming Options */ }, { - key: "notify", - value: function notify() { - var _this2 = this; + key: "reject", + value: function reject() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var status_code = options.status_code || 480; + var reason_phrase = options.reason_phrase; + var extraHeaders = Utils.cloneArray(options.extraHeaders); + var body = options.body; - var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('notify()'); // Prevent send notify after final notify. + if (this._direction !== 'incoming') { + throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Options'); + } - if (!this._dialog) { - debugerror('final notify has sent'); - return; + if (this._is_replied) { + throw new Error('incoming Options already replied'); } - var subs_state = this._stateNumberToString(this._state); + if (status_code < 300 || status_code >= 700) { + throw new TypeError("Invalid status_code: ".concat(status_code)); + } - if (this._state !== C.STATE_TERMINATED) { - var expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); + this._is_replied = true; - if (expires < 0) { - expires = 0; - } + this._request.reply(status_code, reason_phrase, extraHeaders, body); + } + }, { + key: "_receiveResponse", + value: function _receiveResponse(response) { + if (this._closed) { + return; + } - subs_state += ";expires=".concat(expires); - } else { - if (this._terminated_reason) { - subs_state += ";reason=".concat(this._terminated_reason); - } + switch (true) { + case /^1[0-9]{2}$/.test(response.status_code): + // Ignore provisional responses. + break; - if (this._terminated_retry_after !== null) { - subs_state += ";retry-after=".concat(this._terminated_retry_after); - } - } + case /^2[0-9]{2}$/.test(response.status_code): + this._succeeded('remote', response); - var headers = this._headers.slice(); + break; - headers.push("Subscription-State: ".concat(subs_state)); + default: + { + var cause = Utils.sipErrorCause(response.status_code); - if (body) { - headers.push("Content-Type: ".concat(this._content_type)); - } + this._failed('remote', response, cause); - this._dialog.sendRequest(JsSIP_C.NOTIFY, { - body: body, - extraHeaders: headers, - eventHandlers: { - onRequestTimeout: function onRequestTimeout() { - _this2._dialogTerminated(C.NOTIFY_RESPONSE_TIMEOUT); - }, - onTransportError: function onTransportError() { - _this2._dialogTerminated(C.NOTIFY_TRANSPORT_ERROR); - }, - onErrorResponse: function onErrorResponse(response) { - if (response.status_code === 401 || response.status_code === 407) { - _this2._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); - } else { - _this2._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); - } - }, - onDialogError: function onDialogError() { - _this2._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); + break; } - } - }); + } } - /** - * Terminate. (Send the final NOTIFY request). - * - * @param {string} body - Notify message body. - * @param {string} reason - Set Subscription-State reason parameter. - * @param {number} retryAfter - Set Subscription-State retry-after parameter. - */ - }, { - key: "terminate", - value: function terminate() { - var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - debug('terminate()'); - this._state = C.STATE_TERMINATED; - this._terminated_reason = reason; - this._terminated_retry_after = retryAfter; - this.notify(body); + key: "_onRequestTimeout", + value: function _onRequestTimeout() { + if (this._closed) { + return; + } - this._dialogTerminated(C.SEND_FINAL_NOTIFY); + this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT); } - /** - * Get dialog state. - */ - }, { - key: "state", - get: function get() { - return this._state; - } - /** - * Get dialog id. - */ + key: "_onTransportError", + value: function _onTransportError() { + if (this._closed) { + return; + } + this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR); + } }, { - key: "id", - get: function get() { - return this._dialog ? this._dialog.id : null; + key: "_close", + value: function _close() { + this._closed = true; + + this._ua.destroyMessage(this); } /** - * Private API + * Internal Callbacks */ }, { - key: "_dialogTerminated", - value: function _dialogTerminated(termination_code) { - if (!this._dialog) { - return; - } - - this._state = C.STATE_TERMINATED; - clearTimeout(this._expires_timer); - - if (this._dialog) { - this._dialog.terminate(); - - this._dialog = null; + key: "_newOptions", + value: function _newOptions(originator, request) { + if (originator === 'remote') { + this._direction = 'incoming'; + this._local_identity = request.to; + this._remote_identity = request.from; + } else if (originator === 'local') { + this._direction = 'outgoing'; + this._local_identity = request.from; + this._remote_identity = request.to; } - var send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; - debug("emit \"terminated\" code=".concat(termination_code, ", send final notify=").concat(send_final_notify)); - this.emit('terminated', termination_code, send_final_notify); + this._ua.newOptions(this, { + originator: originator, + message: this, + request: request + }); } }, { - key: "_setExpiresTimer", - value: function _setExpiresTimer() { - var _this3 = this; - - this._expires_timestamp = new Date().getTime() + this._expires * 1000; - clearTimeout(this._expires_timer); - this._expires_timer = setTimeout(function () { - if (!_this3._dialog) { - return; - } - - _this3._terminated_reason = 'timeout'; + key: "_failed", + value: function _failed(originator, response, cause) { + logger.debug('OPTIONS failed'); - _this3.notify(); + this._close(); - _this3._dialogTerminated(C.SUBSCRIPTION_EXPIRED); - }, this._expires * 1000); + logger.debug('emit "failed"'); + this.emit('failed', { + originator: originator, + response: response || null, + cause: cause + }); } }, { - key: "_stateNumberToString", - value: function _stateNumberToString(state) { - switch (state) { - case C.STATE_PENDING: - return 'pending'; - - case C.STATE_ACTIVE: - return 'active'; + key: "_succeeded", + value: function _succeeded(originator, response) { + logger.debug('OPTIONS succeeded'); - case C.STATE_TERMINATED: - return 'terminated'; + this._close(); - default: - throw new TypeError('wrong state value'); - } + logger.debug('emit "succeeded"'); + this.emit('succeeded', { + originator: originator, + response: response + }); } - }], [{ - key: "C", - get: - /** - * Expose C object. - */ - function get() { - return C; + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; } }]); - return Notifier; + return Options; }(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./Utils":28,"debug":32,"events":31}],12:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28,"events":31}],13:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } +var Logger = require('./Logger'); + var Grammar = require('./Grammar'); var SIPMessage = require('./SIPMessage'); -var debugerror = require('debug')('JsSIP:ERROR:Parser'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('Parser'); /** * Parse SIP Message */ @@ -17010,7 +16976,7 @@ exports.parseMessage = function (data, ua) { var headerEnd = data.indexOf('\r\n'); if (headerEnd === -1) { - debugerror('parseMessage() | no CRLF found, not a SIP message'); + logger.warn('parseMessage() | no CRLF found, not a SIP message'); return; } // Parse first line. Check if it is a Request or a Reply. @@ -17019,7 +16985,7 @@ exports.parseMessage = function (data, ua) { var parsed = Grammar.parse(firstLine, 'Request_Response'); if (parsed === -1) { - debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); + logger.warn("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); return; } else if (!parsed.status_code) { message = new SIPMessage.IncomingRequest(ua); @@ -17045,14 +17011,14 @@ exports.parseMessage = function (data, ua) { break; } // Data.indexOf returned -1 due to a malformed message. else if (headerEnd === -1) { - debugerror('parseMessage() | malformed message'); + logger.warn('parseMessage() | malformed message'); return; } parsed = parseHeader(message, data, headerStart, headerEnd); if (parsed !== true) { - debugerror('parseMessage() |', parsed.error); + logger.warn('parseMessage() |', parsed.error); return; } @@ -17316,12 +17282,12 @@ function parseHeader(message, data, headerStart, headerEnd) { return true; } } -},{"./Grammar":7,"./SIPMessage":20,"debug":32}],13:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9,"./SIPMessage":21}],14:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -17343,7 +17309,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } @@ -17352,6 +17318,8 @@ var EventEmitter = require('events').EventEmitter; var sdp_transform = require('sdp-transform'); +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Exceptions = require('./Exceptions'); @@ -17378,11 +17346,7 @@ var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); var URI = require('./URI'); -var debug = require('debug')('JsSIP:RTCSession'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('RTCSession'); var C = { // RTCSession states. STATUS_NULL: 0, @@ -17407,12 +17371,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(RTCSession); + _createClass(RTCSession, null, [{ + key: "C", + + /** + * Expose C object. + */ + get: function get() { + return C; + } + }]); + function RTCSession(ua) { var _this; _classCallCheck(this, RTCSession); - debug('new'); + logger.debug('new'); _this = _super.call(this); _this._id = null; _this._ua = ua; @@ -17486,96 +17461,32 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _createClass(RTCSession, [{ - key: "C", - get: function get() { - return C; - } // Expose session failed/ended causes as a property of the RTCSession instance. + key: "isInProgress", + value: function isInProgress() { + switch (this._status) { + case C.STATUS_NULL: + case C.STATUS_INVITE_SENT: + case C.STATUS_1XX_RECEIVED: + case C.STATUS_INVITE_RECEIVED: + case C.STATUS_WAITING_FOR_ANSWER: + return true; + default: + return false; + } + } }, { - key: "causes", - get: function get() { - return JsSIP_C.causes; - } - }, { - key: "id", - get: function get() { - return this._id; - } - }, { - key: "connection", - get: function get() { - return this._connection; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "direction", - get: function get() { - return this._direction; - } - }, { - key: "local_identity", - get: function get() { - return this._local_identity; - } - }, { - key: "remote_identity", - get: function get() { - return this._remote_identity; - } - }, { - key: "start_time", - get: function get() { - return this._start_time; - } - }, { - key: "end_time", - get: function get() { - return this._end_time; - } - }, { - key: "data", - get: function get() { - return this._data; - }, - set: function set(_data) { - this._data = _data; - } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "isInProgress", - value: function isInProgress() { - switch (this._status) { - case C.STATUS_NULL: - case C.STATUS_INVITE_SENT: - case C.STATUS_1XX_RECEIVED: - case C.STATUS_INVITE_RECEIVED: - case C.STATUS_WAITING_FOR_ANSWER: - return true; - - default: - return false; - } - } - }, { - key: "isEstablished", - value: function isEstablished() { - switch (this._status) { - case C.STATUS_ANSWERED: - case C.STATUS_WAITING_FOR_ACK: - case C.STATUS_CONFIRMED: - return true; - - default: - return false; - } + key: "isEstablished", + value: function isEstablished() { + switch (this._status) { + case C.STATUS_ANSWERED: + case C.STATUS_WAITING_FOR_ACK: + case C.STATUS_CONFIRMED: + return true; + + default: + return false; + } } }, { key: "isEnded", @@ -17610,7 +17521,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function connect(target) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var initCallback = arguments.length > 2 ? arguments[2] : undefined; - debug('connect()'); + logger.debug('connect()'); var originalTarget = target; var eventHandlers = Utils.cloneObject(options.eventHandlers); var extraHeaders = Utils.cloneArray(options.extraHeaders); @@ -17723,7 +17634,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function init_incoming(request, initCallback) { var _this2 = this; - debug('init_incoming()'); + logger.debug('init_incoming()'); var expires; var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type. @@ -17814,7 +17725,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this3 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('answer()'); + logger.debug('answer()'); var request = this._request; var extraHeaders = Utils.cloneArray(options.extraHeaders); var mediaConstraints = Utils.cloneObject(options.mediaConstraints); @@ -17979,7 +17890,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - debugerror('emit "getusermediafailed" [error:%o]', error); + logger.warn('emit "getusermediafailed" [error:%o]', error); _this3.emit('getusermediafailed', error); @@ -18010,7 +17921,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this3.emit('sdp', e); @@ -18025,7 +17936,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this3.emit('peerconnection:setremotedescriptionfailed', error); @@ -18076,7 +17987,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror(error); + logger.warn(error); }); } /** @@ -18089,7 +18000,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this4 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('terminate()'); + logger.debug('terminate()'); var cause = options.cause || JsSIP_C.causes.BYE; var extraHeaders = Utils.cloneArray(options.extraHeaders); var body = options.body; @@ -18106,7 +18017,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_NULL: case C.STATUS_INVITE_SENT: case C.STATUS_1XX_RECEIVED: - debug('canceling session'); + logger.debug('canceling session'); if (status_code && (status_code < 200 || status_code >= 700)) { throw new TypeError("Invalid status_code: ".concat(status_code)); @@ -18132,7 +18043,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_WAITING_FOR_ANSWER: case C.STATUS_ANSWERED: - debug('rejecting session'); + logger.debug('rejecting session'); status_code = status_code || 480; if (status_code < 300 || status_code >= 700) { @@ -18147,7 +18058,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_WAITING_FOR_ACK: case C.STATUS_CONFIRMED: - debug('terminating session'); + logger.debug('terminating session'); reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; if (status_code && (status_code < 200 || status_code >= 700)) { @@ -18213,7 +18124,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendDTMF", value: function sendDTMF(tones) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendDTMF() | tones: %s', tones); + logger.debug('sendDTMF() | tones: %s', tones); var position = 0; var duration = options.duration || null; var interToneGap = options.interToneGap || null; @@ -18224,7 +18135,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } // Check Session Status. - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_1XX_RECEIVED) { throw new Exceptions.InvalidStateError(this._status); } // Check Transport type. @@ -18249,10 +18160,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } else if (!duration) { duration = RTCSession_DTMF.C.DEFAULT_DURATION; } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { - debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); + logger.debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); duration = RTCSession_DTMF.C.MIN_DURATION; } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { - debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); + logger.debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); duration = RTCSession_DTMF.C.MAX_DURATION; } else { duration = Math.abs(duration); @@ -18265,7 +18176,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } else if (!interToneGap) { interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP; } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { - debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); + logger.debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; } else { interToneGap = Math.abs(interToneGap); @@ -18332,9 +18243,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendInfo", value: function sendInfo(contentType, body) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - debug('sendInfo()'); // Check Session Status. + logger.debug('sendInfo()'); // Check Session Status. - if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { + if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_1XX_RECEIVED) { throw new Exceptions.InvalidStateError(this._status); } @@ -18352,7 +18263,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { audio: true, video: false }; - debug('mute()'); + logger.debug('mute()'); var audioMuted = false, videoMuted = false; @@ -18388,7 +18299,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { audio: true, video: true }; - debug('unmute()'); + logger.debug('unmute()'); var audioUnMuted = false, videoUnMuted = false; @@ -18428,7 +18339,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('hold()'); + logger.debug('hold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { return false; @@ -18483,7 +18394,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('unhold()'); + logger.debug('unhold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { return false; @@ -18538,7 +18449,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('renegotiate()'); + logger.debug('renegotiate()'); var rtcOfferConstraints = options.rtcOfferConstraints || null; if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -18592,7 +18503,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function refer(target, options) { var _this9 = this; - debug('refer()'); + logger.debug('refer()'); var originalTarget = target; if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -18630,7 +18541,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "sendRequest", value: function sendRequest(method, options) { - debug('sendRequest()'); + logger.debug('sendRequest()'); return this._dialog.sendRequest(method, options); } /** @@ -18642,7 +18553,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function receiveRequest(request) { var _this10 = this; - debug('receiveRequest()'); + logger.debug('receiveRequest()'); if (request.method === JsSIP_C.CANCEL) { /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL @@ -18690,7 +18601,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -18708,7 +18619,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { status_code: 488 }); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this10.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -18804,7 +18715,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onTransportError", value: function onTransportError() { - debugerror('onTransportError()'); + logger.warn('onTransportError()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18817,7 +18728,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onRequestTimeout", value: function onRequestTimeout() { - debugerror('onRequestTimeout()'); + logger.warn('onRequestTimeout()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18830,7 +18741,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onDialogError", value: function onDialogError() { - debugerror('onDialogError()'); + logger.warn('onDialogError()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18844,14 +18755,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "newDTMF", value: function newDTMF(data) { - debug('newDTMF()'); + logger.debug('newDTMF()'); this.emit('newDTMF', data); } // Called from Info handler. }, { key: "newInfo", value: function newInfo(data) { - debug('newInfo()'); + logger.debug('newInfo()'); this.emit('newInfo', data); } /** @@ -18862,19 +18773,19 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "_isReadyToReOffer", value: function _isReadyToReOffer() { if (!this._rtcReady) { - debug('_isReadyToReOffer() | internal WebRTC status not ready'); + logger.debug('_isReadyToReOffer() | internal WebRTC status not ready'); return false; } // No established yet. if (!this._dialog) { - debug('_isReadyToReOffer() | session not established yet'); + logger.debug('_isReadyToReOffer() | session not established yet'); return false; } // Another INVITE transaction is in progress. if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { - debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); + logger.debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); return false; } @@ -18883,10 +18794,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_close", value: function _close() { - debug('close()'); // Close local MediaStream if it was not given by the user. + logger.debug('close()'); // Close local MediaStream if it was not given by the user. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { - debug('close() | closing local MediaStream'); + logger.debug('close() | closing local MediaStream'); Utils.closeMediaStream(this._localMediaStream); } @@ -18900,7 +18811,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { try { this._connection.close(); } catch (error) { - debugerror('close() | error closing the RTCPeerConnection: %o', error); + logger.warn('close() | error closing the RTCPeerConnection: %o', error); } } // Terminate signaling. // Clear SIP timers. @@ -18987,7 +18898,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._timers.ackTimer = setTimeout(function () { if (_this11._status === C.STATUS_WAITING_FOR_ACK) { - debug('no ACK received, terminating the session'); + logger.debug('no ACK received, terminating the session'); clearTimeout(_this11._timers.invite2xxTimer); _this11.sendRequest(JsSIP_C.BYE); @@ -19015,7 +18926,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }); - debug('emit "peerconnection"'); + logger.debug('emit "peerconnection"'); this.emit('peerconnection', { peerconnection: this._connection }); @@ -19025,7 +18936,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _createLocalDescription(type, constraints) { var _this13 = this; - debug('createLocalDescription()'); + logger.debug('createLocalDescription()'); if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\"")); var connection = this._connection; this._rtcReady = false; @@ -19033,7 +18944,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { .then(function () { if (type === 'offer') { return connection.createOffer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createofferfailed" [error:%o]', error); _this13.emit('peerconnection:createofferfailed', error); @@ -19041,7 +18952,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } else { return connection.createAnswer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createanswerfailed" [error:%o]', error); _this13.emit('peerconnection:createanswerfailed', error); @@ -19052,7 +18963,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { .then(function (desc) { return connection.setLocalDescription(desc)["catch"](function (error) { _this13._rtcReady = true; - debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); _this13.emit('peerconnection:setlocaldescriptionfailed', error); @@ -19067,7 +18978,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: type, sdp: connection.localDescription.sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this13.emit('sdp', e); @@ -19090,7 +19001,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: type, sdp: connection.localDescription.sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this13.emit('sdp', e); @@ -19136,7 +19047,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created. if (early_dialog.error) { - debug(early_dialog.error); + logger.debug(early_dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); @@ -19162,7 +19073,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var dialog = new Dialog(this, message, type); if (dialog.error) { - debug(dialog.error); + logger.debug(dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); @@ -19182,7 +19093,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveReinvite(request) { var _this14 = this; - debug('receiveReinvite()'); + logger.debug('receiveReinvite()'); var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; var data = { request: request, @@ -19239,7 +19150,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); + logger.debug('invalid Content-Type'); request.reply(415); return; } @@ -19252,7 +19163,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sendAnswer.call(_this14, desc); })["catch"](function (error) { - debugerror(error); + logger.warn(error); }); function sendAnswer(desc) { @@ -19288,7 +19199,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveUpdate(request) { var _this16 = this; - debug('receiveUpdate()'); + logger.debug('receiveUpdate()'); var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; var data = { request: request, @@ -19328,7 +19239,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); + logger.debug('invalid Content-Type'); request.reply(415); return; } @@ -19341,7 +19252,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sendAnswer.call(_this16, desc); })["catch"](function (error) { - debugerror(error); + logger.warn(error); }); function sendAnswer(desc) { @@ -19361,7 +19272,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _processInDialogSdpOffer(request) { var _this17 = this; - debug('_processInDialogSdpOffer()'); + logger.debug('_processInDialogSdpOffer()'); var sdp = request.parseSDP(); var hold = false; @@ -19397,7 +19308,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var offer = new RTCSessionDescription({ type: 'offer', @@ -19411,7 +19322,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this17._connection.setRemoteDescription(offer)["catch"](function (error) { request.reply(488); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this17.emit('peerconnection:setremotedescriptionfailed', error); @@ -19439,11 +19350,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) { request.reply(500); - debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); throw error; }); })["catch"](function (error) { - debugerror('_processInDialogSdpOffer() failed [error: %o]', error); + logger.warn('_processInDialogSdpOffer() failed [error: %o]', error); }); return this._connectionPromiseQueue; } @@ -19456,16 +19367,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveRefer(request) { var _this18 = this; - debug('receiveRefer()'); + logger.debug('receiveRefer()'); if (!request.refer_to) { - debug('no Refer-To header field present in REFER'); + logger.debug('no Refer-To header field present in REFER'); request.reply(400); return; } if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { - debug('Refer-To header field points to a non-SIP URI scheme'); + logger.debug('Refer-To header field points to a non-SIP URI scheme'); request.reply(416); return; } // Reply before the transaction timer expires. @@ -19473,7 +19384,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(202); var notifier = new RTCSession_ReferNotifier(this, request.cseq); - debug('emit "refer"'); // Emit 'refer'. + logger.debug('emit "refer"'); // Emit 'refer'. this.emit('refer', { request: request, @@ -19533,7 +19444,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_receiveNotify", value: function _receiveNotify(request) { - debug('receiveNotify()'); + logger.debug('receiveNotify()'); if (!request.event) { request.reply(400); @@ -19580,7 +19491,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveReplaces(request) { var _this20 = this; - debug('receiveReplaces()'); + logger.debug('receiveReplaces()'); function _accept2(initCallback) { var _this19 = this; @@ -19598,7 +19509,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } function _reject2() { - debug('Replaced INVITE rejected by the user'); + logger.debug('Replaced INVITE rejected by the user'); request.reply(486); } // Emit 'replace'. @@ -19654,7 +19565,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - debugerror('emit "getusermediafailed" [error:%o]', error); + logger.warn('emit "getusermediafailed" [error:%o]', error); _this21.emit('getusermediafailed', error); @@ -19689,7 +19600,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this21._request.body = desc; _this21._status = C.STATUS_INVITE_SENT; - debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. + logger.debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. _this21.emit('sending', { request: _this21._request @@ -19701,7 +19612,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror(error); + logger.warn(error); }); } /** @@ -19716,7 +19627,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); if (!(sender && sender.dtmf)) { - debugerror('sendDTMF() | no local audio track to send DTMF with'); + logger.warn('sendDTMF() | no local audio track to send DTMF with'); return; } @@ -19731,7 +19642,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveInviteResponse(response) { var _this22 = this; - debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. + logger.debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. if (this._dialog && response.status_code >= 200 && response.status_code <= 299) { /* @@ -19746,7 +19657,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var dialog = new Dialog(this, response, 'UAC'); if (dialog.error !== undefined) { - debug(dialog.error); + logger.debug(dialog.error); return; } @@ -19780,7 +19691,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { { // Do nothing with 1xx responses without To tag. if (!response.to_tag) { - debug('1xx response received without to tag'); + logger.debug('1xx response received without to tag'); break; } // Create Early Dialog if 1XX comes with contact. @@ -19805,7 +19716,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -19816,7 +19727,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }).then(function () { return _this22._progress('remote', response); })["catch"](function (error) { - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this22.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19845,7 +19756,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', _e); var _answer = new RTCSessionDescription({ @@ -19880,7 +19791,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this22.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19906,7 +19817,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this23 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendReinvite()'); + logger.debug('sendReinvite()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; @@ -19927,7 +19838,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this23.emit('sdp', e); @@ -19990,7 +19901,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -20004,7 +19915,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } })["catch"](function (error) { onFailed.call(_this24); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this24.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -20026,7 +19937,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this25 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendUpdate()'); + logger.debug('sendUpdate()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; @@ -20049,7 +19960,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this25.emit('sdp', e); @@ -20138,7 +20049,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -20152,7 +20063,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } })["catch"](function (error) { onFailed.call(_this26); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this26.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -20171,7 +20082,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_acceptAndTerminate", value: function _acceptAndTerminate(response, status_code, reason_phrase) { - debug('acceptAndTerminate()'); + logger.debug('acceptAndTerminate()'); var extraHeaders = []; if (status_code) { @@ -20204,7 +20115,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sdp = sdp_transform.parse(sdp); // Local hold. if (this._localHold && !this._remoteHold) { - debug('mangleOffer() | me on hold, mangling offer'); + logger.debug('mangleOffer() | me on hold, mangling offer'); var _iterator5 = _createForOfIteratorHelper(sdp.media), _step5; @@ -20232,7 +20143,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } // Local and remote hold. else if (this._localHold && this._remoteHold) { - debug('mangleOffer() | both on hold, mangling offer'); + logger.debug('mangleOffer() | both on hold, mangling offer'); var _iterator6 = _createForOfIteratorHelper(sdp.media), _step6; @@ -20254,7 +20165,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } // Remote hold. else if (this._remoteHold) { - debug('mangleOffer() | remote on hold, mangling offer'); + logger.debug('mangleOffer() | remote on hold, mangling offer'); var _iterator7 = _createForOfIteratorHelper(sdp.media), _step7; @@ -20376,7 +20287,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debug('runSessionTimer() | sending session refresh request'); + logger.debug('runSessionTimer() | sending session refresh request'); if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { _this27._sendUpdate(); @@ -20391,7 +20302,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror('runSessionTimer() | timer expired, terminating the session'); + logger.warn('runSessionTimer() | timer expired, terminating the session'); _this27.terminate({ cause: JsSIP_C.causes.REQUEST_TIMEOUT, @@ -20446,7 +20357,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_newRTCSession", value: function _newRTCSession(originator, request) { - debug('newRTCSession()'); + logger.debug('newRTCSession()'); this._ua.newRTCSession(this, { originator: originator, @@ -20457,8 +20368,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_connecting", value: function _connecting(request) { - debug('session connecting'); - debug('emit "connecting"'); + logger.debug('session connecting'); + logger.debug('emit "connecting"'); this.emit('connecting', { request: request }); @@ -20466,8 +20377,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_progress", value: function _progress(originator, response) { - debug('session progress'); - debug('emit "progress"'); + logger.debug('session progress'); + logger.debug('emit "progress"'); this.emit('progress', { originator: originator, response: response || null @@ -20476,9 +20387,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_accepted", value: function _accepted(originator, message) { - debug('session accepted'); + logger.debug('session accepted'); this._start_time = new Date(); - debug('emit "accepted"'); + logger.debug('emit "accepted"'); this.emit('accepted', { originator: originator, response: message || null @@ -20487,9 +20398,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_confirmed", value: function _confirmed(originator, ack) { - debug('session confirmed'); + logger.debug('session confirmed'); this._is_confirmed = true; - debug('emit "confirmed"'); + logger.debug('emit "confirmed"'); this.emit('confirmed', { originator: originator, ack: ack || null @@ -20498,12 +20409,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_ended", value: function _ended(originator, message, cause) { - debug('session ended'); + logger.debug('session ended'); this._end_time = new Date(); this._close(); - debug('emit "ended"'); + logger.debug('emit "ended"'); this.emit('ended', { originator: originator, message: message || null, @@ -20513,9 +20424,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_failed", value: function _failed(originator, message, cause) { - debug('session failed'); // Emit private '_failed' event first. + logger.debug('session failed'); // Emit private '_failed' event first. - debug('emit "_failed"'); + logger.debug('emit "_failed"'); this.emit('_failed', { originator: originator, message: message || null, @@ -20524,7 +20435,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._close(); - debug('emit "failed"'); + logger.debug('emit "failed"'); this.emit('failed', { originator: originator, message: message || null, @@ -20534,11 +20445,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_onhold", value: function _onhold(originator) { - debug('session onhold'); + logger.debug('session onhold'); this._setLocalMediaStatus(); - debug('emit "hold"'); + logger.debug('emit "hold"'); this.emit('hold', { originator: originator }); @@ -20546,11 +20457,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_onunhold", value: function _onunhold(originator) { - debug('session onunhold'); + logger.debug('session onunhold'); this._setLocalMediaStatus(); - debug('emit "unhold"'); + logger.debug('emit "unhold"'); this.emit('unhold', { originator: originator }); @@ -20560,11 +20471,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _onmute(_ref5) { var audio = _ref5.audio, video = _ref5.video; - debug('session onmute'); + logger.debug('session onmute'); this._setLocalMediaStatus(); - debug('emit "muted"'); + logger.debug('emit "muted"'); this.emit('muted', { audio: audio, video: video @@ -20575,30 +20486,85 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _onunmute(_ref6) { var audio = _ref6.audio, video = _ref6.video; - debug('session onunmute'); + logger.debug('session onunmute'); this._setLocalMediaStatus(); - debug('emit "unmuted"'); + logger.debug('emit "unmuted"'); this.emit('unmuted', { audio: audio, video: video }); } - }], [{ + }, { key: "C", - get: - /** - * Expose C object. - */ - function get() { + get: function get() { return C; + } // Expose session failed/ended causes as a property of the RTCSession instance. + + }, { + key: "causes", + get: function get() { + return JsSIP_C.causes; + } + }, { + key: "id", + get: function get() { + return this._id; + } + }, { + key: "connection", + get: function get() { + return this._connection; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "direction", + get: function get() { + return this._direction; + } + }, { + key: "local_identity", + get: function get() { + return this._local_identity; + } + }, { + key: "remote_identity", + get: function get() { + return this._remote_identity; + } + }, { + key: "start_time", + get: function get() { + return this._start_time; + } + }, { + key: "end_time", + get: function get() { + return this._end_time; + } + }, { + key: "data", + get: function get() { + return this._data; + }, + set: function set(_data) { + this._data = _data; + } + }, { + key: "status", + get: function get() { + return this._status; } }]); return RTCSession; }(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,"debug":32,"events":31,"sdp-transform":37}],14:[function(require,module,exports){ +},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./Logger":9,"./RTCSession/DTMF":15,"./RTCSession/Info":16,"./RTCSession/ReferNotifier":17,"./RTCSession/ReferSubscriber":18,"./RequestSender":20,"./SIPMessage":21,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,"events":31,"sdp-transform":37}],15:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20619,23 +20585,21 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('../Logger'); + var JsSIP_C = require('../Constants'); var Exceptions = require('../Exceptions'); var Utils = require('../Utils'); -var debug = require('debug')('JsSIP:RTCSession:DTMF'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('RTCSession:DTMF'); var C = { MIN_DURATION: 70, MAX_DURATION: 6000, @@ -20664,16 +20628,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(DTMF, [{ - key: "tone", - get: function get() { - return this._tone; - } - }, { - key: "duration", - get: function get() { - return this._duration; - } - }, { key: "send", value: function send(tone) { var _this2 = this; @@ -20782,7 +20736,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (!this._tone) { - debug('invalid INFO DTMF received, discarded'); + logger.debug('invalid INFO DTMF received, discarded'); } else { this._session.newDTMF({ originator: 'remote', @@ -20791,6 +20745,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } } + }, { + key: "tone", + get: function get() { + return this._tone; + } + }, { + key: "duration", + get: function get() { + return this._duration; + } }]); return DTMF; @@ -20801,7 +20765,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { module.exports.C = C; -},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],15:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":28,"events":31}],16:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20822,16 +20786,12 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); - -debugerror.log = console.warn.bind(console); - var JsSIP_C = require('../Constants'); var Exceptions = require('../Exceptions'); @@ -20857,16 +20817,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(Info, [{ - key: "contentType", - get: function get() { - return this._contentType; - } - }, { - key: "body", - get: function get() { - return this._body; - } - }, { key: "send", value: function send(contentType, body) { var _this2 = this; @@ -20937,11 +20887,21 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request: request }); } + }, { + key: "contentType", + get: function get() { + return this._contentType; + } + }, { + key: "body", + get: function get() { + return this._body; + } }]); return Info; }(EventEmitter); -},{"../Constants":2,"../Exceptions":6,"../Utils":28,"debug":32,"events":31}],16:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Utils":28,"events":31}],17:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -20950,10 +20910,11 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var JsSIP_C = require('../Constants'); +var Logger = require('../Logger'); -var debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); +var JsSIP_C = require('../Constants'); +var logger = new Logger('RTCSession:ReferNotifier'); var C = { event_type: 'refer', body_type: 'message/sipfrag;version=2.0', @@ -20975,7 +20936,7 @@ module.exports = /*#__PURE__*/function () { _createClass(ReferNotifier, [{ key: "notify", value: function notify(code, reason) { - debug('notify()'); + logger.debug('notify()'); if (this._active === false) { return; @@ -21006,7 +20967,7 @@ module.exports = /*#__PURE__*/function () { return ReferNotifier; }(); -},{"../Constants":2,"debug":32}],17:[function(require,module,exports){ +},{"../Constants":2,"../Logger":9}],18:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -21027,19 +20988,21 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('../Logger'); + var JsSIP_C = require('../Constants'); var Grammar = require('../Grammar'); var Utils = require('../Utils'); -var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); +var logger = new Logger('RTCSession:ReferSubscriber'); module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(ReferSubscriber, _EventEmitter); @@ -21058,17 +21021,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(ReferSubscriber, [{ - key: "id", - get: function get() { - return this._id; - } - }, { key: "sendRefer", value: function sendRefer(target) { var _this2 = this; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendRefer()'); + logger.debug('sendRefer()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers. @@ -21090,10 +21048,15 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">"); - extraHeaders.push(referTo); // Referred-By header field. + extraHeaders.push(referTo); // Referred-By header field (if not already present). + + if (!extraHeaders.some(function (header) { + return header.toLowerCase().startsWith('referred-by:'); + })) { + var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); + extraHeaders.push(referredBy); + } - var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">"); - extraHeaders.push(referredBy); extraHeaders.push("Contact: ".concat(this._session.contact)); var request = this._session.sendRequest(JsSIP_C.REFER, { @@ -21122,7 +21085,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "receiveNotify", value: function receiveNotify(request) { - debug('receiveNotify()'); + logger.debug('receiveNotify()'); if (!request.body) { return; @@ -21131,7 +21094,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var status_line = Grammar.parse(request.body.trim(), 'Status_Line'); if (status_line === -1) { - debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); + logger.debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); return; } @@ -21168,8 +21131,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_requestSucceeded", value: function _requestSucceeded(response) { - debug('REFER succeeded'); - debug('emit "requestSucceeded"'); + logger.debug('REFER succeeded'); + logger.debug('emit "requestSucceeded"'); this.emit('requestSucceeded', { response: response }); @@ -21177,18 +21140,23 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_requestFailed", value: function _requestFailed(response, cause) { - debug('REFER failed'); - debug('emit "requestFailed"'); + logger.debug('REFER failed'); + logger.debug('emit "requestFailed"'); this.emit('requestFailed', { response: response || null, cause: cause }); } + }, { + key: "id", + get: function get() { + return this._id; + } }]); return ReferSubscriber; }(EventEmitter); -},{"../Constants":2,"../Grammar":7,"../Utils":28,"debug":32,"events":31}],18:[function(require,module,exports){ +},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":28,"events":31}],19:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -21197,6 +21165,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var Utils = require('./Utils'); var JsSIP_C = require('./Constants'); @@ -21205,8 +21175,7 @@ var SIPMessage = require('./SIPMessage'); var RequestSender = require('./RequestSender'); -var debug = require('debug')('JsSIP:Registrator'); - +var logger = new Logger('Registrator'); var MIN_REGISTER_EXPIRES = 10; // In seconds. module.exports = /*#__PURE__*/function () { @@ -21243,11 +21212,6 @@ module.exports = /*#__PURE__*/function () { } _createClass(Registrator, [{ - key: "registered", - get: function get() { - return this._registered; - } - }, { key: "setExtraHeaders", value: function setExtraHeaders(extraHeaders) { if (!Array.isArray(extraHeaders)) { @@ -21283,7 +21247,7 @@ module.exports = /*#__PURE__*/function () { var _this = this; if (this._registering) { - debug('Register request in progress...'); + logger.debug('Register request in progress...'); return; } @@ -21331,7 +21295,7 @@ module.exports = /*#__PURE__*/function () { _this._registering = false; if (!response.hasHeader('Contact')) { - debug('no Contact header in response to REGISTER, response ignored'); + logger.debug('no Contact header in response to REGISTER, response ignored'); break; } @@ -21351,7 +21315,7 @@ module.exports = /*#__PURE__*/function () { } if (!contact) { - debug('no Contact header pointing to us, response ignored'); + logger.debug('no Contact header pointing to us, response ignored'); break; } @@ -21411,7 +21375,7 @@ module.exports = /*#__PURE__*/function () { _this.register(); } else { // This response MUST contain a Min-Expires header field. - debug('423 response received for REGISTER without Min-Expires'); + logger.debug('423 response received for REGISTER without Min-Expires'); _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); } @@ -21439,7 +21403,7 @@ module.exports = /*#__PURE__*/function () { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (!this._registered) { - debug('already unregistered'); + logger.debug('already unregistered'); return; } @@ -21550,11 +21514,16 @@ module.exports = /*#__PURE__*/function () { cause: cause || null }); } + }, { + key: "registered", + get: function get() { + return this._registered; + } }]); return Registrator; }(); -},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32}],19:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28}],20:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -21563,14 +21532,15 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var DigestAuthentication = require('./DigestAuthentication'); var Transactions = require('./Transactions'); -var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers. - +var logger = new Logger('RequestSender'); // Default event handlers. var EventHandlers = { onRequestTimeout: function onRequestTimeout() {}, @@ -21674,7 +21644,7 @@ module.exports = /*#__PURE__*/function () { if (!challenge) { - debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); + logger.debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); this._eventHandlers.onReceiveResponse(response); @@ -21729,7 +21699,7 @@ module.exports = /*#__PURE__*/function () { return RequestSender; }(); -},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":24,"debug":32}],20:[function(require,module,exports){ +},{"./Constants":2,"./DigestAuthentication":5,"./Logger":9,"./Transactions":24}],21:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -21744,11 +21714,11 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -21762,6 +21732,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d var sdp_transform = require('sdp-transform'); +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Utils = require('./Utils'); @@ -21770,7 +21742,7 @@ var NameAddrHeader = require('./NameAddrHeader'); var Grammar = require('./Grammar'); -var debug = require('debug')('JsSIP:SIPMessage'); +var logger = new Logger('SIPMessage'); /** * -param {String} method request method * -param {String} ruri request uri @@ -21782,7 +21754,6 @@ var debug = require('debug')('JsSIP:SIPMessage'); * -param {String} [body] */ - var OutgoingRequest = /*#__PURE__*/function () { function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) { _classCallCheck(this, OutgoingRequest); @@ -22261,10 +22232,10 @@ var IncomingMessage = /*#__PURE__*/function () { name = Utils.headerize(name); if (!this.headers[name]) { - debug("header \"".concat(name, "\" not present")); + logger.debug("header \"".concat(name, "\" not present")); return; } else if (idx >= this.headers[name].length) { - debug("not so many \"".concat(name, "\" headers present")); + logger.debug("not so many \"".concat(name, "\" headers present")); return; } @@ -22281,7 +22252,7 @@ var IncomingMessage = /*#__PURE__*/function () { if (parsed === -1) { this.headers[name].splice(idx, 1); // delete from headers - debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); + logger.debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); return; } else { header.parsed = parsed; @@ -22500,733 +22471,165 @@ var IncomingRequest = /*#__PURE__*/function (_IncomingMessage) { response += "Content-Length: ".concat(0, "\r\n\r\n"); } - this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); - } - /** - * Stateless reply. - * -param {Number} code status code - * -param {String} reason reason phrase - */ - - }, { - key: "reply_sl", - value: function reply_sl() { - var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var vias = this.getHeaders('via'); // Validate code and reason values. - - if (!code || code < 100 || code > 699) { - throw new TypeError("Invalid status_code: ".concat(code)); - } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { - throw new TypeError("Invalid reason_phrase: ".concat(reason)); - } - - reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; - var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); - - var _iterator11 = _createForOfIteratorHelper(vias), - _step11; - - try { - for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { - var via = _step11.value; - response += "Via: ".concat(via, "\r\n"); - } - } catch (err) { - _iterator11.e(err); - } finally { - _iterator11.f(); - } - - var to = this.getHeader('To'); - - if (!this.to_tag && code > 100) { - to += ";tag=".concat(Utils.newTag()); - } else if (this.to_tag && !this.s('to').hasParam('tag')) { - to += ";tag=".concat(this.to_tag); - } - - response += "To: ".concat(to, "\r\n"); - response += "From: ".concat(this.getHeader('From'), "\r\n"); - response += "Call-ID: ".concat(this.call_id, "\r\n"); - response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); - response += "Content-Length: ".concat(0, "\r\n\r\n"); - this.transport.send(response); - } - }]); - - return IncomingRequest; -}(IncomingMessage); - -var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { - _inherits(IncomingResponse, _IncomingMessage2); - - var _super3 = _createSuper(IncomingResponse); - - function IncomingResponse() { - var _this3; - - _classCallCheck(this, IncomingResponse); - - _this3 = _super3.call(this); - _this3.headers = {}; - _this3.status_code = null; - _this3.reason_phrase = null; - return _this3; - } - - return IncomingResponse; -}(IncomingMessage); - -module.exports = { - OutgoingRequest: OutgoingRequest, - InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, - IncomingRequest: IncomingRequest, - IncomingResponse: IncomingResponse -}; -},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,"debug":32,"sdp-transform":37}],21:[function(require,module,exports){ -"use strict"; - -var Utils = require('./Utils'); - -var Grammar = require('./Grammar'); - -var debugerror = require('debug')('JsSIP:ERROR:Socket'); - -debugerror.log = console.warn.bind(console); -/** - * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ - * - * interface Socket { - * attribute String via_transport - * attribute String url - * attribute String sip_uri - * - * method connect(); - * method disconnect(); - * method send(data); - * - * attribute EventHandler onconnect - * attribute EventHandler ondisconnect - * attribute EventHandler ondata - * } - * - */ - -exports.isSocket = function (socket) { - // Ignore if an array is given. - if (Array.isArray(socket)) { - return false; - } - - if (typeof socket === 'undefined') { - debugerror('undefined JsSIP.Socket instance'); - return false; - } // Check Properties. - - - try { - if (!Utils.isString(socket.url)) { - debugerror('missing or invalid JsSIP.Socket url property'); - throw new Error(); - } - - if (!Utils.isString(socket.via_transport)) { - debugerror('missing or invalid JsSIP.Socket via_transport property'); - throw new Error(); - } - - if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { - debugerror('missing or invalid JsSIP.Socket sip_uri property'); - throw new Error(); - } - } catch (e) { - return false; - } // Check Methods. - - - try { - ['connect', 'disconnect', 'send'].forEach(function (method) { - if (!Utils.isFunction(socket[method])) { - debugerror("missing or invalid JsSIP.Socket method: ".concat(method)); - throw new Error(); - } - }); - } catch (e) { - return false; - } - - return true; -}; -},{"./Grammar":7,"./Utils":28,"debug":32}],22:[function(require,module,exports){ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } - -function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } - -function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } - -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - -var EventEmitter = require('events').EventEmitter; - -var JsSIP_C = require('./Constants'); - -var Utils = require('./Utils'); - -var Grammar = require('./Grammar'); - -var SIPMessage = require('./SIPMessage'); - -var RequestSender = require('./RequestSender'); - -var Dialog = require('./Dialog'); - -var debug = require('debug')('JsSIP:Subscriber'); - -var debugerror = require('debug')('JsSIP:ERROR:Subscriber'); - -debugerror.log = console.warn.bind(console); -/** - * Termination codes. - */ - -var C = { - // Termination codes. - SUBSCRIBE_RESPONSE_TIMEOUT: 0, - SUBSCRIBE_TRANSPORT_ERROR: 1, - SUBSCRIBE_NON_OK_RESPONSE: 2, - SUBSCRIBE_BAD_OK_RESPONSE: 3, - SUBSCRIBE_FAILED_AUTHENTICATION: 4, - UNSUBSCRIBE_TIMEOUT: 5, - RECEIVE_FINAL_NOTIFY: 6, - RECEIVE_BAD_NOTIFY: 7, - // Subscriber states. - STATE_PENDING: 0, - STATE_ACTIVE: 1, - STATE_TERMINATED: 2, - STATE_INIT: 3, - STATE_NOTIFY_WAIT: 4 -}; -/** - * RFC 6665 Subscriber implementation. - */ - -module.exports = /*#__PURE__*/function (_EventEmitter) { - _inherits(Subscriber, _EventEmitter); - - var _super = _createSuper(Subscriber); - - /** - * @param {UA} ua - reference to JsSIP.UA - * @param {string} target - * @param {string} eventName - Event header value. May end with optional ;id=xxx - * @param {string} accept - Accept header value. - * - * @param {SubscriberOption} options - optional parameters. - * @param {number} expires - Expires header value. Default is 900. - * @param {string} contentType - Content-Type header value. Used for SUBSCRIBE with body - * @param {string} allowEvents - Allow-Events header value. - * @param {RequestParams} params - Will have priority over ua.configuration. - * If set please define: to_uri, to_display_name, from_uri, from_display_name - * @param {Array} extraHeaders - Additional SIP headers. - */ - function Subscriber(ua, target, eventName, accept, _ref) { - var _this; - - var expires = _ref.expires, - contentType = _ref.contentType, - allowEvents = _ref.allowEvents, - params = _ref.params, - extraHeaders = _ref.extraHeaders; - - _classCallCheck(this, Subscriber); - - debug('new'); - _this = _super.call(this); // Check that arguments are defined - - if (!target) { - throw new TypeError('target is undefined'); - } - - if (!eventName) { - throw new TypeError('eventName is undefined'); - } - - if (!accept) { - throw new TypeError('accept is undefined'); - } - - _this._ua = ua; - _this._target = target; - - if (expires !== 0 && !expires) { - expires = 900; - } - - _this._expires = expires; // Used to subscribe with body. - - _this._content_type = contentType; // Set initial subscribe parameters. - - _this._params = Utils.cloneObject(params); - - if (!_this._params.from_uri) { - _this._params.from_uri = _this._ua.configuration.uri; - } - - _this._params.from_tag = Utils.newTag(); - _this._params.to_tag = null; - _this._params.call_id = Utils.createRandomToken(20); // Create subscribe cseq if not defined custom cseq. - - if (_this._params.cseq === undefined) { - _this._params.cseq = Math.floor(Math.random() * 10000 + 1); - } // Subscriber state. - - - _this._state = C.STATE_INIT; // Dialog - - _this._dialog = null; // To refresh subscription. - - _this._expires_timer = null; - _this._expires_timestamp = null; // To prevent duplicate un-subscribe sending. - - _this._send_unsubscribe = false; // After send un-subscribe wait final notify limited time. - - _this._unsubscribe_timeout_timer = null; // Custom session empty object for high level use. - - _this.data = {}; - var parsed = Grammar.parse(eventName, 'Event'); - - if (parsed === -1) { - throw new TypeError('eventName - wrong format'); - } - - _this._event_name = parsed.event; - _this._event_id = parsed.params && parsed.params.id; - var eventValue = _this._event_name; - - if (_this._event_id) { - eventValue += ";id=".concat(_this._event_id); - } - - _this._headers = Utils.cloneArray(extraHeaders); - _this._headers = _this._headers.concat(["Event: ".concat(eventValue), "Expires: ".concat(_this._expires), "Accept: ".concat(accept)]); - - if (!_this._headers.find(function (header) { - return header.startsWith('Contact'); - })) { - var contact = "Contact: "); - contact += ";+sip.instance=\"\""); - - _this._headers.push(contact); - } - - if (allowEvents) { - _this._headers.push("Allow-Events: ".concat(allowEvents)); - } - - return _this; - } - - _createClass(Subscriber, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "onRequestTimeout", - value: function onRequestTimeout() { - this._dialogTerminated(C.SUBSCRIBE_RESPONSE_TIMEOUT); - } - }, { - key: "onTransportError", - value: function onTransportError() { - this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); - } - /** - * Dialog callback. - */ - - }, { - key: "receiveRequest", - value: function receiveRequest(request) { - if (request.method !== JsSIP_C.NOTIFY) { - debugerror('received non-NOTIFY request'); - request.reply(405); - return; - } // RFC 6665 8.2.1. Check if event header matches. - - - var event_header = request.parseHeader('Event'); - - if (!event_header) { - debugerror('missed Event header'); - request.reply(400); - - this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); - - return; - } - - var event_name = event_header.event; - var event_id = event_header.params && event_header.params.id; - - if (event_name !== this._event_name || event_id !== this._event_id) { - debugerror('Event header does not match SUBSCRIBE'); - request.reply(489); - - this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); - - return; - } // Process Subscription-State header. - - - var subs_state = request.parseHeader('subscription-state'); - - if (!subs_state) { - debugerror('missed Subscription-State header'); - request.reply(400); - - this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); - - return; - } - - request.reply(200); - - var new_state = this._stateStringToNumber(subs_state.state); - - var prev_state = this._state; - - if (prev_state !== C.STATE_TERMINATED && new_state !== C.STATE_TERMINATED) { - this._state = new_state; - - if (subs_state.expires !== undefined) { - var expires = subs_state.expires; - var expires_timestamp = new Date().getTime() + expires * 1000; - var max_time_deviation = 2000; // Expiration time is shorter and the difference is not too small. - - if (this._expires_timestamp - expires_timestamp > max_time_deviation) { - debug('update sending re-SUBSCRIBE time'); - - this._scheduleSubscribe(expires); - } - } - } - - if (prev_state !== C.STATE_PENDING && new_state === C.STATE_PENDING) { - debug('emit "pending"'); - this.emit('pending'); - } else if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { - debug('emit "active"'); - this.emit('active'); - } - - var body = request.body; // Check if the notify is final. - - var is_final = new_state === C.STATE_TERMINATED; // Notify event fired only for notify with body. - - if (body) { - var content_type = request.getHeader('content-type'); - debug('emit "notify"'); - this.emit('notify', is_final, request, body, content_type); - } - - if (is_final) { - var reason = subs_state.reason; - var retry_after = undefined; - - if (subs_state.params && subs_state.params['retry-after'] !== undefined) { - retry_after = parseInt(subs_state.params['retry-after']); - } - - this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason, retry_after); - } - } - /** - * User API - */ - - /** - * Send the initial (non-fetch) and subsequent subscribe. - * @param {string} body - subscribe request body. - */ - - }, { - key: "subscribe", - value: function subscribe() { - var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('subscribe()'); - - if (this._state === C.STATE_INIT) { - this._state = C.STATE_NOTIFY_WAIT; - - this._sendInitialSubscribe(body, this._headers); - } else { - this._sendSubsequentSubscribe(body, this._headers); - } - } - /** - * terminate. - * Send un-subscribe or fetch-subscribe (with Expires: 0). - * @param {string} body - un-subscribe request body - */ - - }, { - key: "terminate", - value: function terminate() { - var _this2 = this; - - var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - debug('terminate()'); // Prevent duplication un-subscribe sending. - - if (this._send_unsubscribe) { - debugerror('unsubscribe has already been sent'); - return; - } - - this._send_unsubscribe = true; // Set header Expires: 0. - - var headers = this._headers.map(function (s) { - return s.startsWith('Expires') ? 'Expires: 0' : s; - }); - - if (!this._dialog) { - // fetch-subscribe - initial subscribe with Expires: 0. - this._sendInitialSubscribe(body, headers); - } else { - this._sendSubsequentSubscribe(body, headers); - } // Waiting for the final notify for a while. - - - var final_notify_timeout = 30000; - this._unsubscribe_timeout_timer = setTimeout(function () { - _this2._dialogTerminated(C.UNSUBSCRIBE_TIMEOUT); - }, final_notify_timeout); - } - /** - * Get dialog state. - */ - - }, { - key: "state", - get: function get() { - return this._state; - } - /** - * Get dialog id. - */ - - }, { - key: "id", - get: function get() { - return this._dialog ? this._dialog.id : null; + this.server_transaction.receiveResponse(code, response, onSuccess, onFailure); } /** - * Private API. - */ + * Stateless reply. + * -param {Number} code status code + * -param {String} reason reason phrase + */ }, { - key: "_sendInitialSubscribe", - value: function _sendInitialSubscribe(body, headers) { - var _this3 = this; - - if (body) { - if (!this._content_type) { - throw new TypeError('content_type is undefined'); - } + key: "reply_sl", + value: function reply_sl() { + var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var vias = this.getHeaders('via'); // Validate code and reason values. - headers = headers.slice(); - headers.push("Content-Type: ".concat(this._content_type)); + if (!code || code < 100 || code > 699) { + throw new TypeError("Invalid status_code: ".concat(code)); + } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) { + throw new TypeError("Invalid reason_phrase: ".concat(reason)); } - var request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); - var request_sender = new RequestSender(this._ua, request, { - onRequestTimeout: function onRequestTimeout() { - _this3.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this3.onTransportError(); - }, - onReceiveResponse: function onReceiveResponse(response) { - _this3._receiveSubscribeResponse(response); - } - }); - request_sender.send(); - } - }, { - key: "_receiveSubscribeResponse", - value: function _receiveSubscribeResponse(response) { - if (response.status_code >= 200 && response.status_code < 300) { - // Create dialog - if (this._dialog === null) { - var dialog = new Dialog(this, response, 'UAC'); + reason = reason || JsSIP_C.REASON_PHRASE[code] || ''; + var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n"); - if (dialog.error) { - // OK response without Contact - debugerror(dialog.error); + var _iterator11 = _createForOfIteratorHelper(vias), + _step11; - this._dialogTerminated(C.SUBSCRIBE_BAD_OK_RESPONSE); + try { + for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { + var via = _step11.value; + response += "Via: ".concat(via, "\r\n"); + } + } catch (err) { + _iterator11.e(err); + } finally { + _iterator11.f(); + } - return; - } + var to = this.getHeader('To'); - this._dialog = dialog; - debug('emit "dialogCreated"'); - this.emit('dialogCreated'); - } // Check expires value. + if (!this.to_tag && code > 100) { + to += ";tag=".concat(Utils.newTag()); + } else if (this.to_tag && !this.s('to').hasParam('tag')) { + to += ";tag=".concat(this.to_tag); + } + response += "To: ".concat(to, "\r\n"); + response += "From: ".concat(this.getHeader('From'), "\r\n"); + response += "Call-ID: ".concat(this.call_id, "\r\n"); + response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n"); + response += "Content-Length: ".concat(0, "\r\n\r\n"); + this.transport.send(response); + } + }]); - var expires_value = response.getHeader('expires'); + return IncomingRequest; +}(IncomingMessage); - if (expires_value !== 0 && !expires_value) { - debugerror('response without Expires header'); // RFC 6665 3.1.1 subscribe OK response must contain Expires header. - // Use workaround expires value. +var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) { + _inherits(IncomingResponse, _IncomingMessage2); - expires_value = '900'; - } + var _super3 = _createSuper(IncomingResponse); - var expires = parseInt(expires_value); + function IncomingResponse() { + var _this3; - if (expires > 0) { - this._scheduleSubscribe(expires); - } - } else if (response.status_code === 401 || response.status_code === 407) { - this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); - } else if (response.status_code >= 300) { - this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); - } - } - }, { - key: "_sendSubsequentSubscribe", - value: function _sendSubsequentSubscribe(body, headers) { - var _this4 = this; + _classCallCheck(this, IncomingResponse); - if (!this._dialog) { - debugerror('sending subsequent subscribe before OK response to initial subscribe'); - throw new Error('not received final response to initial SUBSCRIBE'); - } + _this3 = _super3.call(this); + _this3.headers = {}; + _this3.status_code = null; + _this3.reason_phrase = null; + return _this3; + } - if (body) { - if (!this._content_type) { - throw new TypeError('content_type is undefined'); - } + return IncomingResponse; +}(IncomingMessage); - headers = headers.slice(); - headers.push("Content-Type: ".concat(this._content_type)); - } +module.exports = { + OutgoingRequest: OutgoingRequest, + InitialOutgoingInviteRequest: InitialOutgoingInviteRequest, + IncomingRequest: IncomingRequest, + IncomingResponse: IncomingResponse +}; +},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":28,"sdp-transform":37}],22:[function(require,module,exports){ +"use strict"; - this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { - body: body, - extraHeaders: headers, - eventHandlers: { - onRequestTimeout: function onRequestTimeout() { - _this4.onRequestTimeout(); - }, - onTransportError: function onTransportError() { - _this4.onTransportError(); - }, - onSuccessResponse: function onSuccessResponse(response) { - _this4._receiveSubscribeResponse(response); - }, - onErrorResponse: function onErrorResponse(response) { - _this4._receiveSubscribeResponse(response); - }, - onDialogError: function onDialogError(response) { - _this4._receiveSubscribeResponse(response); - } - } - }); - } - }, { - key: "_dialogTerminated", - value: function _dialogTerminated(terminationCode) { - var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; - var retryAfter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; +var Logger = require('./Logger'); - // To prevent duplicate emit terminated event. - if (!this._dialog) { - return; - } +var Utils = require('./Utils'); - this._state = C.STATE_TERMINATED; // Clear timers. +var Grammar = require('./Grammar'); - clearTimeout(this._expires_timer); - clearTimeout(this._unsubscribe_timeout_timer); +var logger = new Logger('Socket'); +/** + * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ + * + * interface Socket { + * attribute String via_transport + * attribute String url + * attribute String sip_uri + * + * method connect(); + * method disconnect(); + * method send(data); + * + * attribute EventHandler onconnect + * attribute EventHandler ondisconnect + * attribute EventHandler ondata + * } + * + */ - this._dialog.terminate(); +exports.isSocket = function (socket) { + // Ignore if an array is given. + if (Array.isArray(socket)) { + return false; + } - this._dialog = null; - debug("emit \"terminated\" code=".concat(terminationCode)); - this.emit('terminated', terminationCode, reason, retryAfter); - } - }, { - key: "_scheduleSubscribe", - value: function _scheduleSubscribe(expires) { - var _this5 = this; + if (typeof socket === 'undefined') { + logger.warn('undefined JsSIP.Socket instance'); + return false; + } // Check Properties. - var timeout = expires >= 140 ? expires * 1000 / 2 + Math.floor((expires / 2 - 70) * 1000 * Math.random()) : expires * 1000 - 5000; - this._expires_timestamp = new Date().getTime() + expires * 1000; - debug("next SUBSCRIBE will be sent in ".concat(Math.floor(timeout / 1000), " sec")); - clearTimeout(this._expires_timer); - this._expires_timer = setTimeout(function () { - _this5._expires_timer = null; - _this5._sendSubsequentSubscribe(null, _this5._headers); - }, timeout); + try { + if (!Utils.isString(socket.url)) { + logger.warn('missing or invalid JsSIP.Socket url property'); + throw new Error('Missing or invalid JsSIP.Socket url property'); } - }, { - key: "_stateStringToNumber", - value: function _stateStringToNumber(strState) { - switch (strState) { - case 'pending': - return C.STATE_PENDING; - case 'active': - return C.STATE_ACTIVE; - - case 'terminated': - return C.STATE_TERMINATED; + if (!Utils.isString(socket.via_transport)) { + logger.warn('missing or invalid JsSIP.Socket via_transport property'); + throw new Error('Missing or invalid JsSIP.Socket via_transport property'); + } - case 'init': - return C.STATE_INIT; + if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { + logger.warn('missing or invalid JsSIP.Socket sip_uri property'); + throw new Error('missing or invalid JsSIP.Socket sip_uri property'); + } + } catch (e) { + return false; + } // Check Methods. - case 'notify_wait': - return C.STATE_NOTIFY_WAIT; - default: - throw new TypeError('wrong state value'); + try { + ['connect', 'disconnect', 'send'].forEach(function (method) { + if (!Utils.isFunction(socket[method])) { + logger.warn("missing or invalid JsSIP.Socket method: ".concat(method)); + throw new Error("Missing or invalid JsSIP.Socket method: ".concat(method)); } - } - }], [{ - key: "C", - get: - /** - * Expose C object. - */ - function get() { - return C; - } - }]); + }); + } catch (e) { + return false; + } - return Subscriber; -}(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,"debug":32,"events":31}],23:[function(require,module,exports){ + return true; +}; +},{"./Grammar":7,"./Logger":9,"./Utils":28}],23:[function(require,module,exports){ "use strict"; var T1 = 500, @@ -23269,28 +22672,25 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); var Timers = require('./Timers'); -var debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); - -var debugict = require('debug')('JsSIP:InviteClientTransaction'); - -var debugact = require('debug')('JsSIP:AckClientTransaction'); - -var debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); - -var debugist = require('debug')('JsSIP:InviteServerTransaction'); - +var loggernict = new Logger('NonInviteClientTransaction'); +var loggerict = new Logger('InviteClientTransaction'); +var loggeract = new Logger('AckClientTransaction'); +var loggernist = new Logger('NonInviteServerTransaction'); +var loggerist = new Logger('InviteServerTransaction'); var C = { // Transaction states. STATUS_TRYING: 1, @@ -23335,11 +22735,6 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } _createClass(NonInviteClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -23362,7 +22757,7 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { }, { key: "onTransportError", value: function onTransportError() { - debugnict("transport error occurred, deleting transaction ".concat(this.id)); + loggernict.debug("transport error occurred, deleting transaction ".concat(this.id)); clearTimeout(this.F); clearTimeout(this.K); this.stateChanged(C.STATUS_TERMINATED); @@ -23372,7 +22767,7 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { }, { key: "timer_F", value: function timer_F() { - debugnict("Timer F expired for transaction ".concat(this.id)); + loggernict.debug("Timer F expired for transaction ".concat(this.id)); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); this.eventHandlers.onRequestTimeout(); @@ -23421,6 +22816,11 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { } } } + }, { + key: "C", + get: function get() { + return C; + } }]); return NonInviteClientTransaction; @@ -23455,11 +22855,6 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } _createClass(InviteClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -23487,7 +22882,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { clearTimeout(this.M); if (this.state !== C.STATUS_ACCEPTED) { - debugict("transport error occurred, deleting transaction ".concat(this.id)); + loggerict.debug("transport error occurred, deleting transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } @@ -23498,7 +22893,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_M", value: function timer_M() { - debugict("Timer M expired for transaction ".concat(this.id)); + loggerict.debug("Timer M expired for transaction ".concat(this.id)); if (this.state === C.STATUS_ACCEPTED) { clearTimeout(this.B); @@ -23510,7 +22905,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_B", value: function timer_B() { - debugict("Timer B expired for transaction ".concat(this.id)); + loggerict.debug("Timer B expired for transaction ".concat(this.id)); if (this.state === C.STATUS_CALLING) { this.stateChanged(C.STATUS_TERMINATED); @@ -23521,7 +22916,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_D", value: function timer_D() { - debugict("Timer D expired for transaction ".concat(this.id)); + loggerict.debug("Timer D expired for transaction ".concat(this.id)); clearTimeout(this.B); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -23615,6 +23010,11 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { } } } + }, { + key: "C", + get: function get() { + return C; + } }]); return InviteClientTransaction; @@ -23644,11 +23044,6 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { } _createClass(AckClientTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "send", value: function send() { if (!this.transport.send(this.request)) { @@ -23658,9 +23053,14 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { }, { key: "onTransportError", value: function onTransportError() { - debugact("transport error occurred for transaction ".concat(this.id)); + loggeract.debug("transport error occurred for transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } + }, { + key: "C", + get: function get() { + return C; + } }]); return AckClientTransaction; @@ -23690,11 +23090,6 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } _createClass(NonInviteServerTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -23703,7 +23098,7 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { }, { key: "timer_J", value: function timer_J() { - debugnist("Timer J expired for transaction ".concat(this.id)); + loggernist.debug("Timer J expired for transaction ".concat(this.id)); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); } @@ -23712,7 +23107,7 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { value: function onTransportError() { if (!this.transportError) { this.transportError = true; - debugnist("transport error occurred, deleting transaction ".concat(this.id)); + loggernist.debug("transport error occurred, deleting transaction ".concat(this.id)); clearTimeout(this.J); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -23781,6 +23176,11 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { } } } + }, { + key: "C", + get: function get() { + return C; + } }]); return NonInviteServerTransaction; @@ -23812,11 +23212,6 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } _createClass(InviteServerTransaction, [{ - key: "C", - get: function get() { - return C; - } - }, { key: "stateChanged", value: function stateChanged(state) { this.state = state; @@ -23825,10 +23220,10 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { }, { key: "timer_H", value: function timer_H() { - debugist("Timer H expired for transaction ".concat(this.id)); + loggerist.debug("Timer H expired for transaction ".concat(this.id)); if (this.state === C.STATUS_COMPLETED) { - debugist('ACK not received, dialog will be terminated'); + loggerist.debug('ACK not received, dialog will be terminated'); } this.stateChanged(C.STATUS_TERMINATED); @@ -23844,7 +23239,7 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { }, { key: "timer_L", value: function timer_L() { - debugist("Timer L expired for transaction ".concat(this.id)); + loggerist.debug("Timer L expired for transaction ".concat(this.id)); if (this.state === C.STATUS_ACCEPTED) { this.stateChanged(C.STATUS_TERMINATED); @@ -23856,7 +23251,7 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { value: function onTransportError() { if (!this.transportError) { this.transportError = true; - debugist("transport error occurred, deleting transaction ".concat(this.id)); + loggerist.debug("transport error occurred, deleting transaction ".concat(this.id)); if (this.resendProvisionalTimer !== null) { clearInterval(this.resendProvisionalTimer); @@ -23961,6 +23356,11 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { } } } + }, { + key: "C", + get: function get() { + return C; + } }]); return InviteServerTransaction; @@ -24077,7 +23477,7 @@ module.exports = { InviteServerTransaction: InviteServerTransaction, checkTransaction: checkTransaction }; -},{"./Constants":2,"./SIPMessage":20,"./Timers":23,"debug":32,"events":31}],25:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Timers":23,"events":31}],25:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -24086,15 +23486,13 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Socket = require('./Socket'); - -var debug = require('debug')('JsSIP:Transport'); +var Logger = require('./Logger'); -var debugerror = require('debug')('JsSIP:ERROR:Transport'); +var Socket = require('./Socket'); var JsSIP_C = require('./Constants'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('Transport'); /** * Constants */ @@ -24128,7 +23526,7 @@ module.exports = /*#__PURE__*/function () { _classCallCheck(this, Transport); - debug('new()'); + logger.debug('new()'); this.status = C.STATUS_DISCONNECTED; // Current socket. this.socket = null; // Socket collection. @@ -24143,7 +23541,7 @@ module.exports = /*#__PURE__*/function () { try { this.textDecoder = new TextDecoder('utf8'); } catch (error) { - debugerror("cannot use TextDecoder: ".concat(error)); + logger.warn("cannot use TextDecoder: ".concat(error)); } if (typeof sockets === 'undefined') { @@ -24178,30 +23576,15 @@ module.exports = /*#__PURE__*/function () { _createClass(Transport, [{ - key: "via_transport", - get: function get() { - return this.socket.via_transport; - } - }, { - key: "url", - get: function get() { - return this.socket.url; - } - }, { - key: "sip_uri", - get: function get() { - return this.socket.sip_uri; - } - }, { key: "connect", value: function connect() { - debug('connect()'); + logger.debug('connect()'); if (this.isConnected()) { - debug('Transport is already connected'); + logger.debug('Transport is already connected'); return; } else if (this.isConnecting()) { - debug('Transport is connecting'); + logger.debug('Transport is connecting'); return; } @@ -24225,7 +23608,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "disconnect", value: function disconnect() { - debug('close()'); + logger.debug('close()'); this.close_requested = true; this.recover_attempts = 0; this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer. @@ -24251,15 +23634,15 @@ module.exports = /*#__PURE__*/function () { }, { key: "send", value: function send(data) { - debug('send()'); + logger.debug('send()'); if (!this.isConnected()) { - debugerror('unable to send message, transport is not connected'); + logger.warn('unable to send message, transport is not connected'); return false; } var message = data.toString(); - debug("sending message:\n\n".concat(message, "\n")); + logger.debug("sending message:\n\n".concat(message, "\n")); return this.socket.send(message); } }, { @@ -24290,7 +23673,7 @@ module.exports = /*#__PURE__*/function () { k = this.recovery_options.max_interval; } - debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); + logger.debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); this.recovery_timer = setTimeout(function () { if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) { // Get the next available socket with higher weight. @@ -24383,21 +23766,21 @@ module.exports = /*#__PURE__*/function () { value: function _onData(data) { // CRLF Keep Alive response from server. Ignore it. if (data === '\r\n') { - debug('received message with CRLF Keep Alive response'); + logger.debug('received message with CRLF Keep Alive response'); return; } // Binary message. else if (typeof data !== 'string') { try { if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data)); } catch (evt) { - debug('received binary message failed to be converted into string,' + ' message discarded'); + logger.debug('received binary message failed to be converted into string,' + ' message discarded'); return; } - debug("received binary message:\n\n".concat(data, "\n")); + logger.debug("received binary message:\n\n".concat(data, "\n")); } // Text message. else { - debug("received text message:\n\n".concat(data, "\n")); + logger.debug("received text message:\n\n".concat(data, "\n")); } this.ondata({ @@ -24405,11 +23788,26 @@ module.exports = /*#__PURE__*/function () { message: data }); } + }, { + key: "via_transport", + get: function get() { + return this.socket.via_transport; + } + }, { + key: "url", + get: function get() { + return this.socket.url; + } + }, { + key: "sip_uri", + get: function get() { + return this.socket.sip_uri; + } }]); return Transport; }(); -},{"./Constants":2,"./Socket":21,"debug":32}],26:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./Socket":22}],26:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -24430,24 +23828,24 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Registrator = require('./Registrator'); var RTCSession = require('./RTCSession'); -var Subscriber = require('./Subscriber'); - -var Notifier = require('./Notifier'); - var Message = require('./Message'); +var Options = require('./Options'); + var Transactions = require('./Transactions'); var Transport = require('./Transport'); @@ -24466,11 +23864,7 @@ var sanityCheck = require('./sanityCheck'); var config = require('./Config'); -var debug = require('debug')('JsSIP:UA'); - -var debugerror = require('debug')('JsSIP:ERROR:UA'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('UA'); var C = { // UA status codes. STATUS_INIT: 0, @@ -24494,19 +23888,27 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _super = _createSuper(UA); + _createClass(UA, null, [{ + key: "C", + // Expose C object. + get: function get() { + return C; + } + }]); + function UA(configuration) { var _this; _classCallCheck(this, UA); - debug('new() [configuration:%o]', configuration); + logger.debug('new() [configuration:%o]', configuration); _this = _super.call(this); _this._cache = { credentials: {} }; _this._configuration = Object.assign({}, config.settings); _this._dynConfiguration = {}; - _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE). + _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE/OPTIONS). _this._applicants = {}; _this._sessions = {}; @@ -24543,30 +23945,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } _createClass(UA, [{ - key: "C", - get: function get() { - return C; - } - }, { - key: "status", - get: function get() { - return this._status; - } - }, { - key: "contact", - get: function get() { - return this._contact; - } - }, { - key: "configuration", - get: function get() { - return this._configuration; - } - }, { - key: "transport", - get: function get() { - return this._transport; - } // ================= + key: "start", + // ================= // High Level API // ================= @@ -24574,16 +23954,13 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * Connect to the server if status = STATUS_INIT. * Resume UA after being closed. */ - - }, { - key: "start", value: function start() { - debug('start()'); + logger.debug('start()'); if (this._status === C.STATUS_INIT) { this._transport.connect(); } else if (this._status === C.STATUS_USER_CLOSED) { - debug('restarting UA'); // Disconnect. + logger.debug('restarting UA'); // Disconnect. if (this._closeTimer !== null) { clearTimeout(this._closeTimer); @@ -24597,9 +23974,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._transport.connect(); } else if (this._status === C.STATUS_READY) { - debug('UA is in READY status, not restarted'); + logger.debug('UA is in READY status, not restarted'); } else { - debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); + logger.debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); } // Set dynamic configuration. @@ -24612,7 +23989,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "register", value: function register() { - debug('register()'); + logger.debug('register()'); this._dynConfiguration.register = true; this._registrator.register(); @@ -24624,7 +24001,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "unregister", value: function unregister(options) { - debug('unregister()'); + logger.debug('unregister()'); this._dynConfiguration.register = false; this._registrator.unregister(options); @@ -24669,7 +24046,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "call", value: function call(target, options) { - debug('call()'); + logger.debug('call()'); var session = new RTCSession(this); session.connect(target, options); return session; @@ -24688,30 +24065,29 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "sendMessage", value: function sendMessage(target, body, options) { - debug('sendMessage()'); + logger.debug('sendMessage()'); var message = new Message(this); message.send(target, body, options); return message; } - /** - * Create subscriber instance - */ - - }, { - key: "subscribe", - value: function subscribe(target, eventName, accept, options) { - debug('subscribe()'); - return new Subscriber(this, target, eventName, accept, options); - } /** - * Create notifier instance + * Send a SIP OPTIONS. + * + * -param {String} target + * -param {String} [body] + * -param {Object} [options] + * + * -throws {TypeError} + * */ }, { - key: "notify", - value: function notify(subscribe, contentType, options) { - debug('notify()'); - return new Notifier(this, subscribe, contentType, options); + key: "sendOptions", + value: function sendOptions(target, body, options) { + logger.debug('sendOptions()'); + var message = new Options(this); + message.send(target, body, options); + return message; } /** * Terminate ongoing sessions. @@ -24720,7 +24096,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "terminateSessions", value: function terminateSessions(options) { - debug('terminateSessions()'); + logger.debug('terminateSessions()'); for (var idx in this._sessions) { if (!this._sessions[idx].isEnded()) { @@ -24738,12 +24114,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function stop() { var _this2 = this; - debug('stop()'); // Remove dynamic settings. + logger.debug('stop()'); // Remove dynamic settings. this._dynConfiguration = {}; if (this._status === C.STATUS_USER_CLOSED) { - debug('UA already closed'); + logger.debug('UA already closed'); return; } // Close registrator. @@ -24755,7 +24131,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { for (var session in this._sessions) { if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { - debug("closing session ".concat(session)); + logger.debug("closing session ".concat(session)); try { this._sessions[session].terminate(); @@ -24815,7 +24191,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return this._configuration.authorization_jwt; default: - debugerror('get() | cannot get "%s" parameter in runtime', parameter); + logger.warn('get() | cannot get "%s" parameter in runtime', parameter); return undefined; } } @@ -24867,7 +24243,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } default: - debugerror('set() | cannot set "%s" parameter in runtime', parameter); + logger.warn('set() | cannot set "%s" parameter in runtime', parameter); return false; } @@ -24928,6 +24304,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._applicants[message] = message; this.emit('newMessage', data); } + /** + * new Options + */ + + }, { + key: "newOptions", + value: function newOptions(message, data) { + this._applicants[message] = message; + this.emit('newOptions', data); + } /** * Message destroyed. */ @@ -24996,7 +24382,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var method = request.method; // Check that request URI points to us. if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { - debug('Request-URI does not point to us'); + logger.debug('Request-URI does not point to us'); if (request.method !== JsSIP_C.ACK) { request.reply_sl(404); @@ -25034,20 +24420,22 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (method === JsSIP_C.OPTIONS) { - request.reply(200); - } else if (method === JsSIP_C.MESSAGE) { - if (this.listeners('newMessage').length === 0) { - request.reply(405); + if (this.listeners('newOptions').length === 0) { + request.reply(200); return; } - var message = new Message(this); + var message = new Options(this); message.init_incoming(request); - } else if (method === JsSIP_C.SUBSCRIBE) { - if (this.listeners('newSubscribe').length === 0) { + } else if (method === JsSIP_C.MESSAGE) { + if (this.listeners('newMessage').length === 0) { request.reply(405); return; } + + var _message = new Message(this); + + _message.init_incoming(request); } else if (method === JsSIP_C.INVITE) { // Initial INVITE. if (!request.to_tag && this.listeners('newRTCSession').length === 0) { @@ -25084,7 +24472,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { session.init_incoming(request); } } else { - debugerror('INVITE received but WebRTC is not supported'); + logger.warn('INVITE received but WebRTC is not supported'); request.reply(488); } @@ -25101,7 +24489,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (session) { session.receiveRequest(request); } else { - debug('received CANCEL request for a non existent session'); + logger.debug('received CANCEL request for a non existent session'); } break; @@ -25122,13 +24510,6 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(200); break; - case JsSIP_C.SUBSCRIBE: - this.emit('newSubscribe', { - event: request.event, - request: request - }); - break; - default: request.reply(405); break; @@ -25145,7 +24526,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (session) { session.receiveRequest(request); } else { - debug('received NOTIFY request for a non existent subscription'); + logger.debug('received NOTIFY request for a non existent subscription'); request.reply(481, 'Subscription does not exist'); } } @@ -25249,7 +24630,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._transport.ondisconnect = onTransportDisconnect.bind(this); this._transport.ondata = onTransportData.bind(this); } catch (e) { - debugerror(e); + logger.warn(e); throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); } // Remove sockets instance from configuration object. @@ -25327,7 +24708,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } - debug('configuration parameters after validation:'); + logger.debug('configuration parameters after validation:'); for (var _parameter in this._configuration) { // Only show the user user configurable parameters. @@ -25335,29 +24716,48 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { switch (_parameter) { case 'uri': case 'registrar_server': - debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); + logger.debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); break; case 'password': case 'ha1': case 'authorization_jwt': - debug("- ".concat(_parameter, ": NOT SHOWN")); + logger.debug("- ".concat(_parameter, ": NOT SHOWN")); break; default: - debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); + logger.debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); } } } return; } - }], [{ + }, { key: "C", - get: // Expose C object. - function get() { + get: function get() { return C; } + }, { + key: "status", + get: function get() { + return this._status; + } + }, { + key: "contact", + get: function get() { + return this._contact; + } + }, { + key: "configuration", + get: function get() { + return this._configuration; + } + }, { + key: "transport", + get: function get() { + return this._transport; + } }]); return UA; @@ -25466,10 +24866,10 @@ function onTransportData(data) { } } } -},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"debug":32,"events":31}],27:[function(require,module,exports){ +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Logger":9,"./Message":10,"./Options":12,"./Parser":13,"./RTCSession":14,"./Registrator":19,"./SIPMessage":21,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"events":31}],27:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -25498,6 +24898,24 @@ var Grammar = require('./Grammar'); module.exports = /*#__PURE__*/function () { + _createClass(URI, null, [{ + key: "parse", + + /** + * Parse the given string and returns a JsSIP.URI instance or undefined if + * it is an invalid URI. + */ + value: function parse(uri) { + uri = Grammar.parse(uri, 'SIP_URI'); + + if (uri !== -1) { + return uri; + } else { + return undefined; + } + } + }]); + function URI(scheme, user, host, port) { var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; @@ -25531,38 +24949,6 @@ module.exports = /*#__PURE__*/function () { } _createClass(URI, [{ - key: "scheme", - get: function get() { - return this._scheme; - }, - set: function set(value) { - this._scheme = value.toLowerCase(); - } - }, { - key: "user", - get: function get() { - return this._user; - }, - set: function set(value) { - this._user = value; - } - }, { - key: "host", - get: function get() { - return this._host; - }, - set: function set(value) { - this._host = value.toLowerCase(); - } - }, { - key: "port", - get: function get() { - return this._port; - }, - set: function set(value) { - this._port = value === 0 ? value : parseInt(value, 10) || null; - } - }, { key: "setParam", value: function setParam(key, value) { if (key) { @@ -25706,21 +25092,37 @@ module.exports = /*#__PURE__*/function () { return aor; } - }], [{ - key: "parse", - value: - /** - * Parse the given string and returns a JsSIP.URI instance or undefined if - * it is an invalid URI. - */ - function parse(uri) { - uri = Grammar.parse(uri, 'SIP_URI'); - - if (uri !== -1) { - return uri; - } else { - return undefined; - } + }, { + key: "scheme", + get: function get() { + return this._scheme; + }, + set: function set(value) { + this._scheme = value.toLowerCase(); + } + }, { + key: "user", + get: function get() { + return this._user; + }, + set: function set(value) { + this._user = value; + } + }, { + key: "host", + get: function get() { + return this._host; + }, + set: function set(value) { + this._host = value.toLowerCase(); + } + }, { + key: "port", + get: function get() { + return this._port; + }, + set: function set(value) { + this._port = value === 0 ? value : parseInt(value, 10) || null; } }]); @@ -25731,7 +25133,7 @@ module.exports = /*#__PURE__*/function () { function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } @@ -26268,19 +25670,17 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Grammar = require('./Grammar'); - -var debug = require('debug')('JsSIP:WebSocketInterface'); +var Logger = require('./Logger'); -var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); +var Grammar = require('./Grammar'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('WebSocketInterface'); module.exports = /*#__PURE__*/function () { function WebSocketInterface(url) { _classCallCheck(this, WebSocketInterface); - debug('new() [url:"%s"]', url); + logger.debug('new() [url:"%s"]', url); this._url = url; this._sip_uri = null; this._via_transport = null; @@ -26288,10 +25688,10 @@ module.exports = /*#__PURE__*/function () { var parsed_url = Grammar.parse(url, 'absoluteURI'); if (parsed_url === -1) { - debugerror("invalid WebSocket URI: ".concat(url)); + logger.warn("invalid WebSocket URI: ".concat(url)); throw new TypeError("Invalid argument: ".concat(url)); } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { - debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); + logger.warn("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); throw new TypeError("Invalid argument: ".concat(url)); } else { this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws"); @@ -26300,33 +25700,15 @@ module.exports = /*#__PURE__*/function () { } _createClass(WebSocketInterface, [{ - key: "via_transport", - get: function get() { - return this._via_transport; - }, - set: function set(value) { - this._via_transport = value.toUpperCase(); - } - }, { - key: "sip_uri", - get: function get() { - return this._sip_uri; - } - }, { - key: "url", - get: function get() { - return this._url; - } - }, { key: "connect", value: function connect() { - debug('connect()'); + logger.debug('connect()'); if (this.isConnected()) { - debug("WebSocket ".concat(this._url, " is already connected")); + logger.debug("WebSocket ".concat(this._url, " is already connected")); return; } else if (this.isConnecting()) { - debug("WebSocket ".concat(this._url, " is connecting")); + logger.debug("WebSocket ".concat(this._url, " is connecting")); return; } @@ -26334,7 +25716,7 @@ module.exports = /*#__PURE__*/function () { this.disconnect(); } - debug("connecting to WebSocket ".concat(this._url)); + logger.debug("connecting to WebSocket ".concat(this._url)); try { this._ws = new WebSocket(this._url, 'sip'); @@ -26350,7 +25732,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "disconnect", value: function disconnect() { - debug('disconnect()'); + logger.debug('disconnect()'); if (this._ws) { // Unbind websocket event callbacks. @@ -26370,14 +25752,14 @@ module.exports = /*#__PURE__*/function () { }, { key: "send", value: function send(message) { - debug('send()'); + logger.debug('send()'); if (this.isConnected()) { this._ws.send(message); return true; } else { - debugerror('unable to send message, WebSocket is not open'); + logger.warn('unable to send message, WebSocket is not open'); return false; } } @@ -26398,7 +25780,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "_onOpen", value: function _onOpen() { - debug("WebSocket ".concat(this._url, " connected")); + logger.debug("WebSocket ".concat(this._url, " connected")); this.onconnect(); } }, { @@ -26407,10 +25789,10 @@ module.exports = /*#__PURE__*/function () { var wasClean = _ref.wasClean, code = _ref.code, reason = _ref.reason; - debug("WebSocket ".concat(this._url, " closed")); + logger.debug("WebSocket ".concat(this._url, " closed")); if (wasClean === false) { - debug('WebSocket abrupt disconnection'); + logger.debug('WebSocket abrupt disconnection'); } this.ondisconnect(!wasClean, code, reason); @@ -26419,35 +25801,54 @@ module.exports = /*#__PURE__*/function () { key: "_onMessage", value: function _onMessage(_ref2) { var data = _ref2.data; - debug('received WebSocket message'); + logger.debug('received WebSocket message'); this.ondata(data); } }, { key: "_onError", value: function _onError(e) { - debugerror("WebSocket ".concat(this._url, " error: "), e); + logger.warn("WebSocket ".concat(this._url, " error: "), e); + } + }, { + key: "via_transport", + get: function get() { + return this._via_transport; + }, + set: function set(value) { + this._via_transport = value.toUpperCase(); + } + }, { + key: "sip_uri", + get: function get() { + return this._sip_uri; + } + }, { + key: "url", + get: function get() { + return this._url; } }]); return WebSocketInterface; }(); -},{"./Grammar":7,"debug":32}],30:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9}],30:[function(require,module,exports){ "use strict"; -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); var Utils = require('./Utils'); -var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses. - +var logger = new Logger('sanityCheck'); // Checks for requests and responses. var all = [minimumHeaders]; // Checks for requests. @@ -26621,7 +26022,7 @@ function rfc3261_8_2_2_2() { function rfc3261_8_1_3_3() { if (message.getHeaders('via').length > 1) { - debug('more than one Via header field present in the response, dropping the response'); + logger.debug('more than one Via header field present in the response, dropping the response'); return false; } } @@ -26631,7 +26032,7 @@ function rfc3261_18_3_response() { contentLength = message.getHeader('content-length'); if (len < contentLength) { - debug('message body length is lower than the value in Content-Length header field, dropping the response'); + logger.debug('message body length is lower than the value in Content-Length header field, dropping the response'); return false; } } // Sanity Check functions for requests and responses. @@ -26644,7 +26045,7 @@ function minimumHeaders() { var header = _mandatoryHeaders[_i]; if (!message.hasHeader(header)) { - debug("missing mandatory header field : ".concat(header, ", dropping the response")); + logger.debug("missing mandatory header field : ".concat(header, ", dropping the response")); return false; } } @@ -26683,7 +26084,7 @@ function reply(status_code) { response += '\r\n'; transport.send(response); } -},{"./Constants":2,"./SIPMessage":20,"./Utils":28,"debug":32}],31:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Utils":28}],31:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -27209,28 +26610,19 @@ function functionBindPolyfill(context) { } },{}],32:[function(require,module,exports){ -(function (process){(function (){ +(function (process){ /* eslint-env browser */ /** * This is the web browser implementation of `debug()`. */ +exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.storage = localstorage(); -exports.destroy = (() => { - let warned = false; - - return () => { - if (!warned) { - warned = true; - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); - } - }; -})(); /** * Colors. @@ -27391,14 +26783,18 @@ function formatArgs(args) { } /** - * Invokes `console.debug()` when available. - * No-op when `console.debug` is not a "function". - * If `console.debug` is not available, falls back - * to `console.log`. + * Invokes `console.log()` when available. + * No-op when `console.log` is not a "function". * * @api public */ -exports.log = console.debug || console.log || (() => {}); +function log(...args) { + // This hackery is required for IE8/9, where + // the `console.log` function doesn't have 'apply' + return typeof console === 'object' && + console.log && + console.log(...args); +} /** * Save `namespaces`. @@ -27480,7 +26876,7 @@ formatters.j = function (v) { } }; -}).call(this)}).call(this,require('_process')) +}).call(this,require('_process')) },{"./common":33,"_process":35}],33:[function(require,module,exports){ /** @@ -27496,12 +26892,16 @@ function setup(env) { createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = require('ms'); - createDebug.destroy = destroy; Object.keys(env).forEach(key => { createDebug[key] = env[key]; }); + /** + * Active `debug` instances. + */ + createDebug.instances = []; + /** * The currently active debug mode names, and names to skip. */ @@ -27543,7 +26943,6 @@ function setup(env) { */ function createDebug(namespace) { let prevTime; - let enableOverride = null; function debug(...args) { // Disabled? @@ -27573,7 +26972,7 @@ function setup(env) { args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { // If we encounter an escaped % then don't increase the array index if (match === '%%') { - return '%'; + return match; } index++; const formatter = createDebug.formatters[format]; @@ -27596,28 +26995,33 @@ function setup(env) { } debug.namespace = namespace; + debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); - debug.color = createDebug.selectColor(namespace); + debug.color = selectColor(namespace); + debug.destroy = destroy; debug.extend = extend; - debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. - - Object.defineProperty(debug, 'enabled', { - enumerable: true, - configurable: false, - get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride, - set: v => { - enableOverride = v; - } - }); + // Debug.formatArgs = formatArgs; + // debug.rawLog = rawLog; - // Env-specific initialization logic for debug instances + // env-specific initialization logic for debug instances if (typeof createDebug.init === 'function') { createDebug.init(debug); } + createDebug.instances.push(debug); + return debug; } + function destroy() { + const index = createDebug.instances.indexOf(this); + if (index !== -1) { + createDebug.instances.splice(index, 1); + return true; + } + return false; + } + function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); newDebug.log = this.log; @@ -27655,6 +27059,11 @@ function setup(env) { createDebug.names.push(new RegExp('^' + namespaces + '$')); } } + + for (i = 0; i < createDebug.instances.length; i++) { + const instance = createDebug.instances[i]; + instance.enabled = createDebug.enabled(instance.namespace); + } } /** @@ -27729,14 +27138,6 @@ function setup(env) { return val; } - /** - * XXX DO NOT USE. This is a temporary stub function. - * XXX It WILL be removed in the next major release. - */ - function destroy() { - console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); - } - createDebug.enable(createDebug.load()); return createDebug; @@ -28190,7 +27591,7 @@ var grammar = module.exports = { push: 'rtcpFbTrrInt', reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/, names: ['payload', 'value'], - format: 'rtcp-fb:%s trr-int %d' + format: 'rtcp-fb:%d trr-int %d' }, { // a=rtcp-fb:98 nack rpsi @@ -28850,7 +28251,7 @@ module.exports={ "name": "jssip", "title": "JsSIP", "description": "the Javascript SIP library", - "version": "3.7.6", + "version": "3.8.0", "homepage": "https://jssip.net", "contributors": [ "José Luis Millán (https://github.com/jmillan)", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index b99c6a1ef..36e41e4d5 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -1,9 +1,9 @@ /* - * JsSIP v3.7.6 + * JsSIP v3.8.0 * the Javascript SIP library * Copyright: 2012-2021 * 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 a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}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=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)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=a.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 a=h.optional[o](l);if(void 0===a)throw new c.ConfigurationError(o,l);e[o]=a}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:c.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 s.IncomingResponse&&(i=n.status_code<200?c.STATUS_EARLY:c.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=i,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=i,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),u("new ".concat(r," dialog created with status ").concat(this._state===c.STATUS_EARLY?"EARLY":"CONFIRMED"))}var t,n,h;return t=e,h=[{key:"C",get:function(){return c}}],(n=[{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}},{key:"update",value:function(e,t){this._state=c.STATUS_CONFIRMED,u("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){u("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 l(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===i.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===i.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===i.CANCEL||e===i.ACK?this._local_seqnum:this._local_seqnum+=1;return new s.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.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===i.INVITE||e.method===i.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==o.C.STATUS_ACCEPTED&&e.server_transaction.state!==o.C.STATUS_COMPLETED&&e.server_transaction.state!==o.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===o.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===i.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===o.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&r(t.prototype,n),h&&r(t,h),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":20,"./Transactions":24,"./Utils":28,debug:32}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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)}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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=a||s.createRandomToken(12),this._nc+=1;var u,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?(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=auth [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(u),i('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(u),i('authenticate() | using qop=null [a2:"%s"]',u),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":28,debug:32}],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=u();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 a(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 a(e,t,n){return(a=u()?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 u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],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:S,mark:E,escaped:C,LWS:b,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:I,TEXT_UTF8char:w,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-f]")));return e},token:k,token_nodot:U,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&u('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&u('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&u('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:x,STAR:P,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:H,RAQUOT:L,LAQUOT:F,COMMA:j,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=$())&&(r=e());null!==n&&null!==(r=H())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:Y,quoted_string:K,quoted_string_clean:z,qdtext:J,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:ae,domainlabel:ue,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:Se,method_param:Ee,ttl_param:Ce,maddr_param:be,lr_param:Ae,other_param:Re,pname:Ie,pvalue:we,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Ue,hname:xe,hvalue:Pe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:He,hier_part:Le,net_path:Fe,abs_path:je,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:Je,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:at,REFERm:ut,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=Ht())){for(t=[],o=i,null!==(n=j())&&null!==(r=Ht())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Ht())?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,a;s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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=P()))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;tl&&(l=i,a=[]),a.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&u('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[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&&u("[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&&u("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&u('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&u('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function S(){var e;return null===(e=y())&&(e=E()),e}function E(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&u('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&u('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&u('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&u('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&u('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&u('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&u('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&u('")"')))))))))),e}function C(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&u('"%"')),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 b(){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 A(){var e;return e=null!==(e=b())?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&&u('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function I(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(t=w()))for(e=[];null!==t;)e.push(t),t=w();else e=null;if(null!==e){for(t=[],a=i,r=[],s=b();null!==s;)r.push(s),s=b();for(null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a);null!==r;){for(t.push(r),a=i,r=[],s=b();null!==s;)r.push(s),s=b();null!==r&&null!==(s=w())?r=[r,s]:(r=null,i=a)}null!==t?e=[e,t]:(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 w(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-~]")),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&&u("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))));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&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')))))))))));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;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&u('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&u('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&u('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&u('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&u('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&u('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&u('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&u('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&u('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&u('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&u('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&u('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&u('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&u('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&u('"("')),null!==t&&null!==(r=A())?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,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&u('")"')),null!==t&&null!==(r=A())?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;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&u('">"')),null!==e&&null!==(t=A())?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=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&u('"<"')),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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function B(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=A())?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=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function W(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&null===(e=O())&&(e=b()))),e}function K(){var e,t,r,s,o,l,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,a,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(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&&(a=o,e=(u=n.substring(i,a).trim()).substring(1,u.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=b())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&u('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&u("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&u('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,a;return l=i,a=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=a)):(e=null,i=a),null!==e&&(e=function(e){try{jn.uri=new Ln(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,a,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(a=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,a,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Ln(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&&u('"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&&u('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=re())?(a=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=a),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&u('"@"')),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=S())&&null===(t=C())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')))))));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&&u('":"')),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=ae())&&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 ae(){var e,t,r,s,l,a,c;for(s=i,l=i,e=[],a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);null!==t;)e.push(t),a=i,null!==(t=ue())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r?t=[t,r]:(t=null,i=a)):(t=null,i=a);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),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 ue(){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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));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&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&u('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,a;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&u('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=s,jn.host_type="IPv6",e=n.substring(i,a)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,a,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&&u('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&u('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&u('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=_e())?e=[e,t,r,s,l,a]:(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&&u('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&u('":"')),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&&u('"::"')),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&&u('"::"')),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&&u('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&u('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&u('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&u('":"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&u('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&u('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('"::"')),null!==l&&null!==(a=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(a="::",i+=2):(a=null,0===o&&u('"::"')),null!==a&&null!==(c=_e())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&u('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,a,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&&u('":"')),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&&u('":"')),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&&u('":"')),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&&u('":"')),null!==l&&null!==(a=de())?l=[l,a]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(a=":",i++):(a=null,0===o&&u('":"')),null!==a&&null!==(c=de())?a=[a,c]:(a=null,i=y),null!==(a=null!==a?a:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&u('":"')),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&&u('"::"')),null!==h?e=[e,t,r,s,l,a,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&&u('":"')),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,a,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&u('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(a=".",i++):(a=null,0===o&&u('"."')),null!==a&&null!==(c=me())?e=[e,t,r,s,l,a,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&&u('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&u("[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&&u('"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&&u("[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,a;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&&(a=e,a=parseInt(a.join("")),jn.port=a,e=a),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&&u('";"')),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&&u('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=be())&&null===(e=Ae())&&(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&&u('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&u('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&u('"tls"')),null===t&&(t=k())))),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 Se(){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&&u('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&u('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&u('"ip"')),null===t&&(t=k())),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 Ee(){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&&u('"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 Ce(){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&&u('"ttl="')),null!==e&&null!==(t=An())?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 be(){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&&u('"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 Ae(){var e,t,r,s,l,a;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"lr"')),null!==e?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=a),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,a,c,h;return s=i,l=i,null!==(e=Ie())?(a=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=we())?t=[t,r]:(t=null,i=a),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 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 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 Oe(){var e;return null===(e=Ne())&&null===(e=S())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),e}function ke(){var e,t,r,s,l,a,c;if(a=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null!==e)if(null!==(t=Ue())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&u('"&"')),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&&u('"&"')),null!==s&&null!==(l=Ue())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=a)}else e=null,i=a;else e=null,i=a;return e}function Ue(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null!==t&&null!==(r=Pe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[0],c=e[2],a=a.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[a]?jn.uri_headers[a].push(c):jn.uri_headers[a]=[c])),null===e&&(i=s),e}function xe(){var e,t;if(null===(t=De())&&null===(t=S())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());else e=null;return e}function Pe(){var e,t;for(e=[],null===(t=De())&&null===(t=S())&&(t=C());null!==t;)e.push(t),null===(t=De())&&null===(t=S())&&(t=C());return e}function De(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&u('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&u('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&u('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')))))))),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=He()),e}function He(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null!==t?(null===(r=Le())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function Le(){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&&u('"?"')),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&&u('"//"')),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&&u('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,i=r),e}function Be(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=S())&&(e=C()),e}function Ve(){var e;return null===(e=S())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&u('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&u('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))))),e}function We(){var e,t,r,s,l,a;if(l=i,null!==(e=Ye())){for(t=[],a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&u('"/"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t,r,s,l,a;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&u('";"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=S())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&u('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&u('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&u('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&u('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&u('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&u('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&u('","'))))))))),e}function Je(){var e,t,r,s,l,a;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&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&u('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&u('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=void(jn.scheme=n.substring(i,a))),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&&u('"@"')),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=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=S())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&u('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&u('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&u('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&u('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&u('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&u('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&u('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=Ge();null!==t;)e.push(t),t=Ge();return e}function et(){var e,t,r,s,l,a,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&&u('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&u('"/"')),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&&u('"."')),null!==s){if(null!==(a=h()))for(l=[];null!==a;)l.push(a),a=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&&u('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&u('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&u('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&u('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&u('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&u('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&u('"SUBSCRIBE"')),e}function at(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&u('"NOTIFY"')),e}function ut(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&u('"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=at())&&null===(e=ut())&&(e=k()),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=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=S())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&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=B())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&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=L())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,a;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=b())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=b())&&null!==(r=k())?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=z()),null!==e&&(a=e,e=void(jn.display_name="string"==typeof a?a:a[1].reduce(function(e,t){return e+t[0]+t[1]},a[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,s,l,a;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&u('"q"')),null!==e&&null!==(t=M())&&null!==(r=Et())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.q=a)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,a;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=a)),null===e&&(i=s),e}function St(){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 Et(){var e,t,r,s,l,a,c,f,d;return a=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&u('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&u('"."')),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=a,e=parseFloat(n.substring(i,d))),null===e&&(i=a),e}function Ct(){var e,t,n,r,s,o,l,a;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=bt())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],a=e[1],jn.params||(jn.params={}),a=void 0===a?void 0:a[1],e=void(jn.params[l.toLowerCase()]=a)),null===e&&(i=r),e}function bt(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=It())&&(e=Ct()),e}function It(){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&&u('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function wt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=Pt())){for(r=[],a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=Dt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"application"')),null===e&&(e=Ut()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"multipart"')),null===e&&(e=Ut())),e}function Ut(){var e;return null===(e=k())&&(e=xt()),e}function xt(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&u('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Pt(){var e;return null===(e=Ut())&&(e=k()),e}function Dt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),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 Ht(){var e,t,r,s,l,a;if(l=i,null!==(e=U())){for(t=[],a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==r;)t.push(r),a=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&u('"."')),null!==r&&null!==(s=U())?r=[r,s]:(r=null,i=a);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Lt(){var e;return null===(e=Ft())&&(e=Ct()),e}function Ft(){var e,t,r,s,l,a;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.tag=a)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,a,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"Digest"')),null!==e)if(null!==(t=b()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(a=Vt())?l=[l,a]:(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=Bt()),e}function Bt(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=k()))if(null!==(t=b()))if(null!==(n=Gt())){for(r=[],a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=j())&&null!==(o=Gt())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Gt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){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&&u('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,i=s),e}function Yt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Kt(){var e,t,r,s,l,a,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;for(null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f);null!==a;){if(l.push(a),f=i,null!==(c=v()))for(a=[];null!==c;)a.push(c),c=v();else a=null;null!==a&&null!==(c=zt())?a=[a,c]:(a=null,i=f)}null!==l&&null!==(a=W())?e=[e,t,r,s,l,a]:(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 zt(){var e;return null===(e=He())&&(e=je()),e}function Jt(){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&&u('"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=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,a;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.opaque=a)),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&&u('"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&&u('"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&&u('"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,a;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&u('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.algorithm=a.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,a,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"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)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==a;)l.push(a),d=i,44===n.charCodeAt(i)?(a=",",i++):(a=null,0===o&&u('","')),null!==a&&null!==(c=tn())?a=[a,c]:(a=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=W())?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&&u('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"auth"')),null===e&&(e=k())),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=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Ct()),e}function sn(){var e,t,r,s,l,a,c;if(l=i,a=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"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=a)}else e=null,i=a;else e=null,i=a;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=B())&&null!==(r=Ct())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function an(){var e,t,r,s,l,a,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"reason"')),null!==e&&null!==(t=M())&&null!==(r=un())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(a=e[2])&&(jn.reason=a))),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&&u('"expires"')),null!==e&&null!==(t=M())&&null!==(r=St())?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&&u('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=St())?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=Ct()))),e}function un(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&u('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&u('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&u('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Ct()),e}function hn(){var e,t,n,r,s,o,l,a;if(l=i,null!==(e=yn()))if(null!==(t=b()))if(null!==(n=En())){for(r=[],a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==s;)r.push(s),a=i,null!==(s=B())&&null!==(o=fn())?s=[s,o]:(s=null,i=a);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Ct()),e}function dn(){var e,t,r,s,l,a;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.ttl=a)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,a;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&u('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.maddr=a)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,a;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&u('"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&&(a=e[2],e=void(jn.received=a)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,a;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&u('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.branch=a)),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&&u('"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,a;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&&(a=e,e=void(jn.rport=parseInt(a.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(s=Sn())?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&&u('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Sn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&u('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&u('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function En(){var e,t,n,r,s;return r=i,null!==(e=Cn())?(s=i,null!==(t=G())&&null!==(n=bn())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Cn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ae()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function bn(){var e,t,n,r,s,o,l,a;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&&(a=e,e=void(jn.port=parseInt(a.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=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=St())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function In(){var e;return null===(e=wn())&&(e=Ct()),e}function wn(){var e,t,r,s,l,a;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&u('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&u('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(a=e[2],e=void(jn.refresher=a.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=w())&&null===(t=N())&&(t=b());null!==t;)e.push(t),null===(t=w())&&null===(t=N())&&(t=b());return e}function Nn(){var e,t,r,s,l,a,c,h,f,d,_,p;return d=i,_=i,null!==(e=Un())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&u('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&u('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(a="-",i++):(a=null,0===o&&u('"-"')),null!==a&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&u('"-"')),null!==h&&null!==(f=xn())?e=[e,t,r,s,l,a,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 kn(){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=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function xn(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function Pn(){var e,t,r,s,l,a,c;return s=i,l=i,null!==(e=x())?(a=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&u('"@"')),null!==t&&null!==(r=x())?t=[t,r]:(t=null,i=a),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 Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Hn())&&(e=Ct()),e}function Mn(){var e,t,r,s,l,a;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&u('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.to_tag=a)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,a;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&u('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(a=e[2],e=void(jn.from_tag=a)),null===e&&(i=s),e}function Hn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&u('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Ln=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Bn=Math.max(i,l),Gn=Bn2&&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 a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(u.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,u.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}}])&&r(t.prototype,n),o&&r(t,o),e}()},{"./Grammar":7,"./URI":27}],11:[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"),s._headers.push(s._contact)),o&&s._headers.push("Allow-Events: ".concat(o)),s._target=t.from.uri.user,t.to_tag=h.newTag();var v=new f(l(s),t,"UAS");if(v.error)throw _(v.error),new Error("SUBSCRIBE missed Contact");return s._dialog=v,s._expires>0&&s._setExpiresTimer(),s}return t=m,r=[{key:"C",get:function(){return p}}],(n=[{key:"C",get:function(){return p}},{key:"receiveRequest",value:function(e){if(e.method===c.SUBSCRIBE){var t=e.getHeader("expires");null==t&&d("Missed expires header. Set by default ".concat(t="900")),this._expires=parseInt(t),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var n=e.body,r=e.getHeader("content-type"),s=0===this._expires;s||this._setExpiresTimer(),d('emit "subscribe"'),this.emit("subscribe",s,e,n,r),s&&this._dialogTerminated(p.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){d("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){d("setActiveState()"),this._state===p.STATE_PENDING&&(this._state=p.STATE_ACTIVE)}},{key:"notify",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(d("notify()"),this._dialog){var n=this._stateNumberToString(this._state);if(this._state!==p.STATE_TERMINATED){var r=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);r<0&&(r=0),n+=";expires=".concat(r)}else this._terminated_reason&&(n+=";reason=".concat(this._terminated_reason)),null!==this._terminated_retry_after&&(n+=";retry-after=".concat(this._terminated_retry_after));var s=this._headers.slice();s.push("Subscription-State: ".concat(n)),t&&s.push("Content-Type: ".concat(this._content_type)),this._dialog.sendRequest(c.NOTIFY,{body:t,extraHeaders:s,eventHandlers:{onRequestTimeout:function(){e._dialogTerminated(p.NOTIFY_RESPONSE_TIMEOUT)},onTransportError:function(){e._dialogTerminated(p.NOTIFY_TRANSPORT_ERROR)},onErrorResponse:function(t){401===t.status_code||407===t.status_code?e._dialogTerminated(p.NOTIFY_FAILED_AUTHENTICATION):e._dialogTerminated(p.NOTIFY_NON_OK_RESPONSE)},onDialogError:function(){e._dialogTerminated(p.NOTIFY_NON_OK_RESPONSE)}}})}else _("final notify has sent")}},{key:"terminate",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=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;d("terminate()"),this._state=p.STATE_TERMINATED,this._terminated_reason=t,this._terminated_retry_after=n,this.notify(e),this._dialogTerminated(p.SEND_FINAL_NOTIFY)}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_dialogTerminated",value:function(e){if(this._dialog){this._state=p.STATE_TERMINATED,clearTimeout(this._expires_timer),this._dialog&&(this._dialog.terminate(),this._dialog=null);var t=e===p.SUBSCRIPTION_EXPIRED;d('emit "terminated" code='.concat(e,", send final notify=").concat(t)),this.emit("terminated",e,t)}}},{key:"_setExpiresTimer",value:function(){var e=this;this._expires_timestamp=(new Date).getTime()+1e3*this._expires,clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){e._dialog&&(e._terminated_reason="timeout",e.notify(),e._dialogTerminated(p.SUBSCRIPTION_EXPIRED))},1e3*this._expires)}},{key:"_stateNumberToString",value:function(e){switch(e){case p.STATE_PENDING:return"pending";case p.STATE_ACTIVE:return"active";case p.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),m}()},{"./Constants":2,"./Dialog":3,"./Utils":28,debug:32,events:31}],12:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;A("connect()");var r=e,s=p.cloneObject(t.eventHandlers),i=p.cloneArray(t.extraHeaders),o=p.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,a=p.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new d.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new d.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=p.newTag();var _=t.anonymous||!1,m={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:_,outbound:!0}),_?(m.from_display_name="Anonymous",m.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(m.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(m.from_display_name=t.fromDisplayName),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 v.InitialOutgoingInviteRequest(e,this._ua,m,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(a,u),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;A("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=p.newTag(),this._createDialog(e,"UAS",!0)?(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,f.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,f.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("answer()");var n=this._request,r=p.cloneArray(t.extraHeaders),i=p.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=p.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,u=t.rtcAnswerConstraints||null,c=p.cloneObject(t.rtcOfferConstraints),h=!1,_=!1,m=!1,v=!1;if(this._rtcAnswerConstraints=u,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new d.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new d.InvalidStateError(this._status);if(this._sessionTimers.enabled&&p.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=f.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=f.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 S=y.value;"audio"===S.type&&(h=!0,S.direction&&"sendrecv"!==S.direction||(m=!0)),"video"===S.type&&(_=!0,S.direction&&"sendrecv"!==S.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var E,C=s(o.getAudioTracks());try{for(C.s();!(E=C.n()).done;){var b=E.value;o.removeTrack(b)}}catch(e){C.e(e)}finally{C.f()}}if(o&&!1===i.video){var w,O=s(o.getVideoTracks());try{for(O.s();!(w=O.n()).done;){var N=w.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=m),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||_||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,a),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,f.causes.USER_DENIED_MEDIA_ACCESS),R('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};A('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,f.causes.WEBRTC_ERROR),R('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",u).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,f.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&R(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]:{};A("terminate()");var n,r=t.cause||f.causes.BYE,s=p.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new d.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(A("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||f.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,f.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(A("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,f.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(A("terminating session"),l=t.reason_phrase||f.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!==_.C.STATUS_TERMINATED){var a=this._dialog;this.receiveRequest=function(t){t.method===f.ACK&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===_.C.STATUS_TERMINATED&&(e.sendRequest(f.BYE,{extraHeaders:s,body:i}),a.terminate())}),this._ended("local",null,r),this._dialog=a,this._ua.newDialog(a)}else this.sendRequest(f.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]:{};A("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||f.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 d.InvalidStateError(this._status);if(i!==f.DTMF_TRANSPORT.INFO&&i!==f.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&&!p.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rT.C.MAX_DURATION?(A('"duration" value is greater than the maximum allowed, setting it to '.concat(T.C.MAX_DURATION," milliseconds")),r=T.C.MAX_DURATION):r=Math.abs(r):r=T.C.DEFAULT_DURATION,t.duration=r,s&&!p.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var a=new T(this);t.eventHandlers={onFailed:function(){i._tones=null}},a.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(A("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new d.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};A("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};A("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(A("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:f.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;A("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:f.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;A("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 C(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 A("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(A("receiveRequest()"),e.method===f.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,f.causes.CANCELED));else switch(e.method){case f.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:f.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};A('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:f.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case f.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,f.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,f.causes.BYE)):e.reply(403,"Wrong Status");break;case f.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case f.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 T(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case f.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case f.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case f.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){R("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.CONNECTION_ERROR,cause:f.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){R("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:f.causes.REQUEST_TIMEOUT,cause:f.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){R("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:f.causes.DIALOG_ERROR,cause:f.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){A("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){A("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(A("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(A("_isReadyToReOffer() | session not established yet"),!1):(A("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(A("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(A("close() | closing local MediaStream"),p.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){R("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=m.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nm.T2&&(n=m.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(A("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(f.BYE),e._ended("remote",null,f.causes.NO_ACK))},m.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:f.causes.RTP_TIMEOUT,status_code:408,reason_phrase:f.causes.RTP_TIMEOUT})}),A('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(A("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 R('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R('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,R('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 A('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};A('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()})})})}},{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 g(this,e,t,g.C.STATUS_EARLY)).error?(A(o.error),this._failed("remote",e,f.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 g(this,e,t);return l.error?(A(l.error),this._failed("remote",e,f.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;A("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=p.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 A("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){R(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;A("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=p.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 A("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){R(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;A("_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!==w.indexOf(l.type)){var a=l.direction||r.direction||"sendrecv";if("sendonly"!==a&&"inactive"!==a){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var u={originator:"remote",type:"offer",sdp:e.body};A('emit "sdp"'),this.emit("sdp",u);var c=new RTCSessionDescription({type:"offer",sdp:u.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),R('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),R('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(A("receiveRefer()"),!e.refer_to)return A("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==f.SIP)return A("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var n=new E(this,e.cseq);A('emit "refer"'),this.emit("refer",{request:e,accept:function(r,s){(function(t){var r=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 s=new u(this._ua);if(s.on("progress",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("accepted",function(e){var t=e.response;n.notify(t.status_code,t.reason_phrase)}),s.on("_failed",function(e){var t=e.message,r=e.cause;t?n.notify(t.status_code,t.reason_phrase):n.notify(487,r)}),e.refer_to.uri.hasHeader("replaces")){var i=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));r.extraHeaders=p.cloneArray(r.extraHeaders),r.extraHeaders.push("Replaces: ".concat(i))}s.connect(e.refer_to.uri.toAor(),r,t)}).call(t,r,s)},reject:function(){(function(){n.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(A("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;A("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(n){(function(t){var n=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var r=new u(this._ua);r.on("confirmed",function(){n.terminate()}),r.init_incoming(e,t)}).call(t,n)},reject:function(){(function(){A("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new y(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,f.causes.USER_DENIED_MEDIA_ACCESS),R('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,f.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,A('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R(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;R("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(A("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(f.ACK);var n=new g(this,e,"UAC");return void 0!==n.error?void A(n.error):(this.sendRequest(f.ACK),void this.sendRequest(f.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){A("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};A('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){R('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,f.causes.MISSING_SDP),this._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};A('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,f.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(f.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,f.causes.BAD_MEDIA_DESCRIPTION),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=p.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};A("sendReinvite()");var n=p.cloneArray(t.extraHeaders),r=p.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)};A('emit "sdp"'),e.emit("sdp",s),e.sendRequest(f.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(f.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};A('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),R('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]:{};A("sendUpdate()");var n=p.cloneArray(t.extraHeaders),r=p.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 a.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void a.call(this);var n={originator:"remote",type:"answer",sdp:e.body};A('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){a.call(t),R('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function a(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),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)};A('emit "sdp"'),e.emit("sdp",r),e.sendRequest(f.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){a.call(e)})):this.sendRequest(f.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){a.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){A("acceptAndTerminate()");var r=[];t&&(n=n||f.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(f.ACK),this.sendRequest(f.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=h.parse(e),this._localHold&&!this._remoteHold){A("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!==w.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){A("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!==w.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){A("mangleOffer() | remote on hold, mangling offer");var a,u=s(e.media);try{for(u.s();!(a=u.n()).done;){var c=a.value;-1!==w.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){u.e(e)}finally{u.f()}}return h.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>=f.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>=f.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&&(A("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===f.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:f.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){A("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){A("session connecting"),A('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){A("session progress"),A('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){A("session accepted"),this._start_time=new Date,A('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){A("session confirmed"),this._is_confirmed=!0,A('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){A("session ended"),this._end_time=new Date,this._close(),A('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){A("session failed"),A('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),A('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){A("session onhold"),this._setLocalMediaStatus(),A('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){A("session onunhold"),this._setLocalMediaStatus(),A('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;A("session onmute"),this._setLocalMediaStatus(),A('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;A("session onunmute"),this._setLocalMediaStatus(),A('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&o(t.prototype,n),r&&o(t,r),u}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,debug:32,events:31,"sdp-transform":37}],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;n1&&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(u.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")}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],15:[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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(u.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})}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,debug:32,events:31}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),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}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:32}],17:[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;n1&&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 a="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(a),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(u.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,u.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,u.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,u.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,u.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})}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":28,debug:32,events:31}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,u;return t=e,(n=[{key:"registered",get:function(){return this._registered}},{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)a("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")){a("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a("no Contact header pointing to us, response ignored");break}var o=r.getParam("expires");!o&&t.hasHeader("expires")&&(o=t.getHeader("expires")),o||(o=e._expires),(o=Number(o))<10&&(o=10);var l=o>64?1e3*o/2+Math.floor(1e3*(o/2-32)*Math.random()):1e3*o-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var u=s.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 a("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})}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"./Constants":2,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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=n.call(e)},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 u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,a=s.to_tag?{tag:s.to_tag}:null,u=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,u,a),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;r1&&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}(),E=function(e){s(n,S);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 u="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=a(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;u+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=a(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;u+="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)),u+="To: ".concat(l,"\r\n"),u+="From: ".concat(this.getHeader("From"),"\r\n"),u+="Call-ID: ".concat(this.call_id,"\r\n"),u+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=a(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;u+="".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?(u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?u+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(u+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),u+="Supported: ".concat(o,"\r\n"),r){var S=p.str_utf8_length(r);u+="Content-Type: application/sdp\r\n",u+="Content-Length: ".concat(S,"\r\n\r\n"),u+=r}else u+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,u,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=a(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}(),C=function(e){s(n,S);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:E,IncomingResponse:C}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":28,debug:32,"sdp-transform":37}],21:[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":28,debug:32}],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){for(var n=0;n");y+=';+sip.instance=""'),i._headers.push(y)}return u&&i._headers.push("Allow-Events: ".concat(u)),i}return t=g,r=[{key:"C",get:function(){return v}}],(n=[{key:"C",get:function(){return v}},{key:"onRequestTimeout",value:function(){this._dialogTerminated(v.SUBSCRIBE_RESPONSE_TIMEOUT)}},{key:"onTransportError",value:function(){this._dialogTerminated(v.SUBSCRIBE_TRANSPORT_ERROR)}},{key:"receiveRequest",value:function(e){if(e.method!==u.NOTIFY)return m("received non-NOTIFY request"),void e.reply(405);var t=e.parseHeader("Event");if(!t)return m("missed Event header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var n=t.event,r=t.params&&t.params.id;if(n!==this._event_name||r!==this._event_id)return m("Event header does not match SUBSCRIBE"),e.reply(489),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);var s=e.parseHeader("subscription-state");if(!s)return m("missed Subscription-State header"),e.reply(400),void this._dialogTerminated(v.RECEIVE_BAD_NOTIFY);e.reply(200);var i=this._stateStringToNumber(s.state),o=this._state;if(o!==v.STATE_TERMINATED&&i!==v.STATE_TERMINATED&&(this._state=i,void 0!==s.expires)){var l=s.expires,a=(new Date).getTime()+1e3*l;this._expires_timestamp-a>2e3&&(p("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}o!==v.STATE_PENDING&&i===v.STATE_PENDING?(p('emit "pending"'),this.emit("pending")):o!==v.STATE_ACTIVE&&i===v.STATE_ACTIVE&&(p('emit "active"'),this.emit("active"));var c=e.body,h=i===v.STATE_TERMINATED;if(c){var f=e.getHeader("content-type");p('emit "notify"'),this.emit("notify",h,e,c,f)}if(h){var d=s.reason,_=void 0;s.params&&void 0!==s.params["retry-after"]&&(_=parseInt(s.params["retry-after"])),this._dialogTerminated(v.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;p("subscribe()"),this._state===v.STATE_INIT?(this._state=v.STATE_NOTIFY_WAIT,this._sendInitialSubscribe(e,this._headers)):this._sendSubsequentSubscribe(e,this._headers)}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(p("terminate()"),this._send_unsubscribe)m("unsubscribe has already been sent");else{this._send_unsubscribe=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._dialog?this._sendSubsequentSubscribe(t,n):this._sendInitialSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(v.UNSUBSCRIBE_TIMEOUT)},3e4)}}},{key:"state",get:function(){return this._state}},{key:"id",get:function(){return this._dialog?this._dialog.id:null}},{key:"_sendInitialSubscribe",value:function(e,t){var n=this;if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}var r=new f.OutgoingRequest(u.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new d(this._ua,r,{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onReceiveResponse:function(e){n._receiveSubscribeResponse(e)}}).send()}},{key:"_receiveSubscribeResponse",value:function(e){if(e.status_code>=200&&e.status_code<300){if(null===this._dialog){var t=new _(this,e,"UAC");if(t.error)return m(t.error),void this._dialogTerminated(v.SUBSCRIBE_BAD_OK_RESPONSE);this._dialog=t,p('emit "dialogCreated"'),this.emit("dialogCreated")}var n=e.getHeader("expires");0===n||n||(m("response without Expires header"),n="900");var r=parseInt(n);r>0&&this._scheduleSubscribe(r)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(v.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(v.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(!this._dialog)throw m("sending subsequent subscribe before OK response to initial subscribe"),new Error("not received final response to initial SUBSCRIBE");if(e){if(!this._content_type)throw new TypeError("content_type is undefined");(t=t.slice()).push("Content-Type: ".concat(this._content_type))}this._dialog.sendRequest(u.SUBSCRIBE,{body:e,extraHeaders:t,eventHandlers:{onRequestTimeout:function(){n.onRequestTimeout()},onTransportError:function(){n.onTransportError()},onSuccessResponse:function(e){n._receiveSubscribeResponse(e)},onErrorResponse:function(e){n._receiveSubscribeResponse(e)},onDialogError:function(e){n._receiveSubscribeResponse(e)}}})}},{key:"_dialogTerminated",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this._dialog&&(this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog.terminate(),this._dialog=null,p('emit "terminated" code='.concat(e)),this.emit("terminated",e,t,n))}},{key:"_scheduleSubscribe",value:function(e){var t=this,n=e>=140?1e3*e/2+Math.floor(1e3*(e/2-70)*Math.random()):1e3*e-5e3;this._expires_timestamp=(new Date).getTime()+1e3*e,p("next SUBSCRIBE will be sent in ".concat(Math.floor(n/1e3)," sec")),clearTimeout(this._expires_timer),this._expires_timer=setTimeout(function(){t._expires_timer=null,t._sendSubsequentSubscribe(null,t._headers)},n)}},{key:"_stateStringToNumber",value:function(e){switch(e){case"pending":return v.STATE_PENDING;case"active":return v.STATE_ACTIVE;case"terminated":return v.STATE_TERMINATED;case"init":return v.STATE_INIT;case"notify_wait":return v.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(t.prototype,n),r&&s(t,r),g}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./RequestSender":19,"./SIPMessage":20,"./Utils":28,debug:32,events:31}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case S.STATUS_CALLING:this.stateChanged(S.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case S.STATUS_CALLING:case S.STATUS_PROCEEDING:this.stateChanged(S.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case S.STATUS_COMPLETED:this.sendACK(e)}}}]),n}(),b=function(e){l(n,f);var t=u(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 a="SIP/2.0/".concat(r.via_transport);return a+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",a),l}return o(n,[{key:"C",get:function(){return S}},{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()}}]),n}(),A=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case S.STATUS_TRYING:this.stateChanged(S.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case S.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 S.STATUS_TRYING:case S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_COMPLETED:}}}]),n}(),R=function(e){l(n,f);var t=u(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=S.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=S.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"C",get:function(){return S}},{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===S.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(S.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===S.STATUS_ACCEPTED&&(this.stateChanged(S.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(S.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 S.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===S.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 S.STATUS_PROCEEDING:this.stateChanged(S.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 S.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case S.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(S.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}]),n}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:b,NonInviteServerTransaction:A,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===S.STATUS_ACCEPTED)return!1;if(n.state===S.STATUS_COMPLETED)return n.state=S.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!==S.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case S.STATUS_TRYING:break;case S.STATUS_PROCEEDING:case S.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":20,"./Timers":23,debug:32,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:a.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=a.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.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:a.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}},{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=a.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=a.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===a.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===a.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("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!==a.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=a.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=a.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=a.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=a.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":21,debug:32}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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(b.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}}])&&s(t.prototype,n),r&&s(t,r),w}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Notifier":11,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Subscriber":22,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,debug:32,events:31}],27:[function(e,t,n){"use strict";function r(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var a in this._parameters={},this._headers={},this._scheme=t||o.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,a)&&this.setParam(a,i[a]);for(var u in l)Object.prototype.hasOwnProperty.call(l,u)&&this.setHeader(u,l[u])}var t,n,s;return t=e,s=[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}],(n=[{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}},{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[l.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[l.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(l.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=l.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(l.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 a=i.value;e.push("".concat(s,"=").concat(a))}}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(l.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&i(t.prototype,n),s&&i(t,s),e}()},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,a){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),a)),n(t(e,l),r)}function s(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),a)),n(t(e,l),r)}function i(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),a)),n(t(e,l),r)}function o(e,r,s,i,o,l,a){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),a)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var a,u,c,h,f,d,_,p,m,v;for(a=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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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,u=0;u1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)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(e0&&l.length>i){l.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",a.name,a.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;t1&&(t=arguments[1]),t instanceof Error)throw t;var a=new Error('Unhandled "error" event. ('+t+")");throw a.context=t,a}if(!(n=o[e]))return!1;var u="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=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=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):[]}},{}],32:[function(e,t,n){(function(r){(function(){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.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),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"],n.log=console.debug||console.log||(()=>{}),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)}).call(this,e("_process"))},{"./common":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t,s=null;function i(...e){if(!i.enabled)return;const r=i,s=Number(new Date),o=s-(t||s);r.diff=o,r.prev=t,r.curr=s,t=s,e[0]=n.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"%";l++;const i=n.formatters[s];if("function"==typeof i){const n=e[l];t=i.call(r,n),e.splice(l,1),l--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return i.namespace=e,i.useColors=n.useColors(),i.color=n.selectColor(e),i.extend=r,i.destroy=n.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null===s?n.enabled(e):s,set:e=>{s=e}}),"function"==typeof n.init&&n.init(i),i}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(e){return e instanceof Error?e.stack||e.message:e},n.disable=function(){const e=[...n.names.map(s),...n.skips.map(s).map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){let t;n.save(e),n.names=[],n.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(t=0;t{n[e]=t[e]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n=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*a;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 u(e,t,o,"day");if(t>=i)return u(e,t,i,"hour");if(t>=s)return u(e,t,s,"minute");if(t>=r)return u(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))}},{}],35:[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 a(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 u,c=[],h=!1,f=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=a(d);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n1&&(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=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,a=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})}),e.media.forEach(function(e){a.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?a.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){a.push(i(t,n,e))})})})}),a.join("\r\n")+"\r\n"}},{"./grammar":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.6",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file +!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=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);n0)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":22,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:d.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 o.IncomingResponse&&(s=n.status_code<200?d.STATUS_EARLY:d.STATUS_CONFIRMED);var i=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=i.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=i.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),h.debug("new ".concat(r," dialog created with status ").concat(this._state===d.STATUS_EARLY?"EARLY":"CONFIRMED"))}return s(e,null,[{key:"C",get:function(){return d}}]),s(e,[{key:"update",value:function(e,t){this._state=d.STATUS_CONFIRMED,h.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){h.debug("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=c.cloneArray(n.extraHeaders),s=c.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new a(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===l.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===l.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=c.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===l.CANCEL||e===l.ACK?this._local_seqnum:this._local_seqnum+=1;return new o.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===l.INVITE||e.method===l.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!==u.C.STATUS_ACCEPTED&&e.server_transaction.state!==u.C.STATUS_COMPLETED&&e.server_transaction.state!==u.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===u.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===l.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===u.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,"./Logger":9,"./SIPMessage":21,"./Transactions":24,"./Utils":28}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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":14,"../RequestSender":20,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return o.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return o.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return o.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return o.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop)if(t.qop.indexOf("auth-int")>-1)this._qop="auth-int";else{if(!(t.qop.indexOf("auth")>-1))return o.warn('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=l||i.createRandomToken(12),this._nc+=1;var u,a,c=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-c.length)+c,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=i.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(a))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(i.calculateMD5(s||"")),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(a))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=null [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(a))),o.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Logger":9,"./Utils":28}],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 d=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}(),f=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:d,InvalidStateError:f,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:d,HEXDIG:f,WSP:_,OCTET:p,DQUOTE:m,SP:v,HTAB:g,alphanum:y,reserved:T,unreserved:C,mark:b,escaped:S,LWS:E,SWS:A,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:D,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:U,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=X())&&(r=e());null!==r;)n.push(r),null===(r=K())&&null===(r=X())&&(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:z,quoted_string_clean:Y,qdtext:$,quoted_pair:X,SIP_URI_noparams:J,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:se,password:ie,hostport:oe,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:he,IPv6address:de,h16:fe,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:Ce,method_param:be,ttl_param:Se,maddr_param:Ee,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:De,hname:Ue,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:ze,pchar:Ye,scheme:$e,authority:Xe,srvr:Je,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:dt,extension_code:ft,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Lt())){for(t=[],o=i,null!==(n=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=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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;tl&&(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 d(){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 f(){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=b()),e}function b(){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 S(){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=f())&&null!==(r=f())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=e.join("")),null===e&&(i=s),e}function E(){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 A(){var e;return e=null!==(e=E())?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=A())?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=E();null!==s;)r.push(s),s=E();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],s=E();null!==s;)r.push(s),s=E();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 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&&(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 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&&(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=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null!==t&&null!==(r=A())?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=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null!==t&&null!==(r=A())?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=A())?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=A())?(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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=A())?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=A())&&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=A())?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=E()))),e}function z(){var e,t,r,s,o,l,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 Y(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 $(){var e;return null===(e=E())&&(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 X(){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 J(){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,d;return h=i,d=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=d)):(e=null,i=d),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=S())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=S())&&(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=S())&&(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=S())&&(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=d())){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=de())?(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 de(){var e,t,r,s,l,u,c,h,d,f,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=fe())?(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,d,f,_,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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=fe())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,u,c,h,d,f,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(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=fe())?(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=fe())?e=[e,t]:(e=null,i=g),null===e&&(g=i,null!==(e=fe())?("::"===n.substr(i,2)?(t="::",i+=2):(t=null,0===o&&a('"::"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=_e())?e=[e,t,r,s,l,u,c,h,d,f,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?(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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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 fe(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,t,r,s;return s=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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,d,f;return h=i,d=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=d)):(e=null,i=d)):(e=null,i=d)):(e=null,i=d),null!==e&&(f=h,jn.host_type="IPv4",e=n.substring(i,f)),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=be())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ae())&&(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 be(){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 Se(){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=An())?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 Ee(){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 Ae(){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=S()),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=De())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?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=De())?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 De(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=Ue())?(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 Ue(){var e,t;if(null===(t=Pe())&&null===(t=C())&&(t=S()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());else e=null;return e}function xe(){var e,t;for(e=[],null===(t=Pe())&&null===(t=C())&&(t=S());null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());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=$e())?(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=Xe())&&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=S()),e}function Ve(){var e;return null===(e=C())&&null===(e=S())&&(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=Ye();null!==t;)e.push(t),t=Ye();if(null!==e){for(t=[],u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=ze())?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=ze())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function ze(){var e,t;for(e=[],t=Ye();null!==t;)e.push(t),t=Ye();return e}function Ye(){var e;return null===(e=C())&&null===(e=S())&&(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 $e(){var e,t,r,s,l,u;if(s=i,l=i,null!==(e=d())){for(t=[],null===(r=d())&&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=d())&&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 Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){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=S())&&(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=S())&&(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,d,f;if(c=i,d=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=d)}else e=null,i=d;else e=null,i=d}else e=null,i=d;else e=null,i=d;return null!==e&&(f=c,e=void(jn.sip_version=n.substring(i,f))),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=dt())&&null!==(r=v())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function dt(){var e,t,n;return t=i,null!==(e=ft())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function ft(){var e,t,n,r;return r=i,null!==(e=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=S())&&null===(t=O())&&null===(t=k())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=S())&&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=J())&&(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=E())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=E())&&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=Y()),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=St()),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=bt())?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 bt(){var e,t,r,s,l,u,c,d,f;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&a('"0"')),null!==e?(d=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=d),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=c)):(e=null,i=c),null!==e&&(f=u,e=parseFloat(n.substring(i,f))),null===e&&(i=u),e}function St(){var e,t,n,r,s,o,l,u;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],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 Et(){var e;return null===(e=N())&&null===(e=le())&&(e=z()),e}function At(){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=St()),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=Dt()))))),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=Dt())),e}function Dt(){var e;return null===(e=N())&&(e=Ut()),e}function Ut(){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=Dt())&&(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=z()),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=D())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?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=D())?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=St()),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=E()))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=E()))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=z()),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=zt())&&null===(e=$t())&&null===(e=Jt())&&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=Y())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function zt(){var e,t,r,s,l,u,c,h,d;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=Yt())){if(l=[],d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=Yt())?u=[u,c]:(u=null,i=d);null!==u;){if(l.push(u),d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;null!==u&&null!==(c=Yt())?u=[u,c]:(u=null,i=d)}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 Yt(){var e;return null===(e=Le())&&(e=je()),e}function $t(){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=Xt())?e=[e,t,r]:(e=null,i=s),e}function Xt(){var e,t,n;return t=i,null!==(e=Y())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Jt(){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=Y())?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,d,f;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(d=i,null!==(s=tn())){for(l=[],f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==u;)l.push(u),f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==l?s=[s,l]:(s=null,i=d)}else s=null,i=d;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=St())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=St())?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=St()),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=St())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=St())?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=St()))),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=St()),e}function hn(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=bn())){for(r=[],u=i,null!==(s=G())&&null!==(o=dn())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=dn())?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 dn(){var e;return null===(e=fn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=St()),e}function fn(){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=An())?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=de()),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 bn(){var e,t,n,r,s;return r=i,null!==(e=Sn())?(s=i,null!==(t=W())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Sn(){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 En(){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 An(){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=St()),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=E());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=E());return e}function kn(){var e,t,r,s,l,u,c,h,d,f,_,p;return f=i,_=i,null!==(e=Dn())?(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!==(d=Un())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=f,e[0],e=void(jn=n.substring(i+5,p))),null===e&&(i=f),e}function Nn(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=f())&&null!==(n=f())&&null!==(r=f())?e=[e,t,n,r]:(e=null,i=s),e}function Dn(){var e,t,n;return n=i,null!==(e=Nn())&&null!==(t=Nn())?e=[e,t]:(e=null,i=n),e}function Un(){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=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?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=St()),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=Gn2&&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=d.cloneArray(r.extraHeaders),o=d.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 h.OutgoingRequest(c.MESSAGE,e,this._ua,null,i),t&&(this._request.body=t);var a=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),a.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=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.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=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.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=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.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){p.debug("MESSAGE failed"),this._close(),p.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){p.debug("MESSAGE succeeded"),this._close(),p.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28,events:31}],11:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),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":27}],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){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:{},s=e;if(void 0===e)throw new TypeError("A target is required for OPTIONS");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(s));var i=d.cloneArray(r.extraHeaders),o=d.cloneObject(r.eventHandlers),l=r.contentType||"application/sdp";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 h.OutgoingRequest(c.OPTIONS,e,this._ua,null,i),t&&(this._request.body=t);var a=new f(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newOptions("local",this._request),a.send()}},{key:"init_incoming",value:function(e){this._request=e,this._newOptions("remote",e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:"accept",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,r,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=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){p.debug("OPTIONS failed"),this._close(),p.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){p.debug("OPTIONS succeeded"),this._close(),p.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28,events:31}],13:[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=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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;w.debug("connect()");var r=e,s=v.cloneObject(t.eventHandlers),i=v.cloneArray(t.extraHeaders),o=v.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=v.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 p.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new p.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=v.newTag();var d=t.anonymous||!1,f={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:d,outbound:!0}),d?(f.from_display_name="Anonymous",f.from_uri=new R("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(f.from_uri=new R("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(f.from_display_name=t.fromDisplayName),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 y.InitialOutgoingInviteRequest(e,this._ua,f,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;w.debug("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=v.newTag(),this._createDialog(e,"UAS",!0)?(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,_.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,_.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("answer()");var n=this._request,r=v.cloneArray(t.extraHeaders),i=v.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=v.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=v.cloneObject(t.rtcOfferConstraints),h=!1,d=!1,f=!1,m=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new p.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new p.InvalidStateError(this._status);if(this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.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||(f=!0)),"video"===C.type&&(d=!0,C.direction&&"sendrecv"!==C.direction||(m=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var b,S=s(o.getAudioTracks());try{for(S.s();!(b=S.n()).done;){var E=b.value;o.removeTrack(E)}}catch(e){S.e(e)}finally{S.f()}}if(o&&!1===i.video){var A,R=s(o.getVideoTracks());try{for(R.s();!(A=R.n()).done;){var O=A.value;o.removeTrack(O)}}catch(e){R.e(e)}finally{R.f()}}o||void 0!==i.audio||(i.audio=f),o||void 0!==i.video||(i.video=m),o||h||c.offerToReceiveAudio||(i.audio=!1),o||d||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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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};w.debug('emit "sdp"'),e.emit("sdp",t);var r=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed("system",null,_.causes.WEBRTC_ERROR),w.warn('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,_.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&w.warn(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]:{};w.debug("terminate()");var n,r=t.cause||_.causes.BYE,s=v.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new p.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(w.debug("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||_.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,_.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(w.debug("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,_.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(w.debug("terminating session"),l=t.reason_phrase||_.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!==m.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===_.ACK&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===m.C.STATUS_TERMINATED&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(_.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]:{};w.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||_.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&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.InvalidStateError(this._status);if(i!==_.DTMF_TRANSPORT.INFO&&i!==_.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&&!v.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rb.C.MAX_DURATION?(w.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(b.C.MAX_DURATION," milliseconds")),r=b.C.MAX_DURATION):r=Math.abs(r):r=b.C.DEFAULT_DURATION,t.duration=r,s&&!v.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new b(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(w.debug("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.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};w.debug("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};w.debug("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(w.debug("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:_.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(w.debug("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:_.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;w.debug("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:_.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;w.debug("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 w.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(w.debug("receiveRequest()"),e.method===_.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,_.causes.CANCELED));else switch(e.method){case _.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:_.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",n);var r=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed("remote",e)}).catch(function(e){t.terminate({cause:_.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case _.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,_.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,_.causes.BYE)):e.reply(403,"Wrong Status");break;case _.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case _.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 b(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case _.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case _.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case _.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){w.warn("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.CONNECTION_ERROR,cause:_.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){w.warn("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:_.causes.REQUEST_TIMEOUT,cause:_.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){w.warn("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.DIALOG_ERROR,cause:_.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){w.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){w.debug("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(w.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(w.debug("_isReadyToReOffer() | session not established yet"),!1):(w.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(w.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(w.debug("close() | closing local MediaStream"),v.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){w.warn("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=g.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),ng.T2&&(n=g.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&&(w.debug("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(_.BYE),e._ended("remote",null,_.causes.NO_ACK))},g.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:_.causes.RTP_TIMEOUT,status_code:408,reason_phrase:_.causes.RTP_TIMEOUT})}),w.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(w.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return w.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return w.warn('emit "peerconnection:createanswerfailed" [error:%o]',e),n.emit("peerconnection:createanswerfailed",e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,w.warn('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 w.debug('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};w.debug('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()})})})}},{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 T(this,e,t,T.C.STATUS_EARLY)).error?(w.debug(o.error),this._failed("remote",e,_.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 T(this,e,t);return l.error?(w.debug(l.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;w.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("_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};w.debug('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.warn('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.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){w.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(w.debug("receiveRefer()"),!e.refer_to)return w.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==_.SIP)return w.debug("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);w.debug('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=v.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(w.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(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;w.debug("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(){w.debug("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new C(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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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,_.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,w.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&w.warn(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;w.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(w.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(_.ACK);var n=new T(this,e,"UAC");return void 0!==n.error?void w.debug(n.error):(this.sendRequest(_.ACK),void this.sendRequest(_.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){w.debug("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};w.debug('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.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=I.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,_.causes.MISSING_SDP),this._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};w.debug('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,_.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(_.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=v.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]:{};w.debug("sendReinvite()");var n=v.cloneArray(t.extraHeaders),r=v.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)};w.debug('emit "sdp"'),e.emit("sdp",s),e.sendRequest(_.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(_.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};w.debug('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.warn('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]:{};w.debug("sendUpdate()");var n=v.cloneArray(t.extraHeaders),r=v.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};w.debug('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.warn('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)};w.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(_.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(_.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){w.debug("acceptAndTerminate()");var r=[];t&&(n=n||_.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(_.ACK),this.sendRequest(_.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=d.parse(e),this._localHold&&!this._remoteHold){w.debug("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){w.debug("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){w.debug("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 d.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>=_.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>=_.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&&(w.debug("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===_.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w.warn("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:_.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){w.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){w.debug("session connecting"),w.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){w.debug("session progress"),w.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){w.debug("session accepted"),this._start_time=new Date,w.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){w.debug("session confirmed"),this._is_confirmed=!0,w.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){w.debug("session ended"),this._end_time=new Date,this._close(),w.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){w.debug("session failed"),w.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),w.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){w.debug("session onhold"),this._setLocalMediaStatus(),w.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){w.debug("session onunhold"),this._setLocalMediaStatus(),w.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onmute"),this._setLocalMediaStatus(),w.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onunmute"),this._setLocalMediaStatus(),w.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return I}},{key:"causes",get:function(){return _.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,"./Logger":9,"./RTCSession/DTMF":15,"./RTCSession/Info":16,"./RTCSession/ReferNotifier":17,"./RTCSession/ReferSubscriber":18,"./RequestSender":20,"./SIPMessage":21,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,events:31,"sdp-transform":37}],15:[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;n1&&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 h.InvalidStateError(this._session.status);var r=d.cloneArray(n.extraHeaders);if(this.eventHandlers=d.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(c.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=_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):f.debug("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),a}(),t.exports.C=_},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":28,events:31}],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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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),d}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,events:31}],17:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(i.NOTIFY,{extraHeaders:["Event: ".concat(l.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(l.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"../Constants":2,"../Logger":9}],18:[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;n1&&void 0!==arguments[1]?arguments[1]:{};f.debug("sendRefer()");var r=d.cloneArray(n.extraHeaders),s=d.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):"",">");if(r.push(l),!r.some(function(e){return e.toLowerCase().startsWith("referred-by:")})){var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u)}r.push("Contact: ".concat(this._session.contact));var a=this._session.sendRequest(c.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,c.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,c.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,c.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,c.causes.DIALOG_ERROR)}}});this._id=a.cseq}},{key:"receiveNotify",value:function(e){if(f.debug("receiveNotify()"),e.body){var t=h.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.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){f.debug("REFER succeeded"),f.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){f.debug("REFER failed"),f.debug('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),a}()},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":28,events:31}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,s;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)a.debug("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var n=new l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new u(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,o.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")){a.debug("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a.debug("no Contact header pointing to us, response ignored");break}var s=r.getParam("expires");!s&&t.hasHeader("expires")&&(s=t.getHeader("expires")),s||(s=e._expires),(s=Number(s))<10&&(s=10);var l=s>64?1e3*s/2+Math.floor(1e3*(s/2-32)*Math.random()):1e3*s-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,o.causes.SIP_FAILURE_CODE));break;default:var u=i.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new u(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,o.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=i.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else a.debug("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}},{key:"_unregistered",value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:"registered",get:function(){return this._registered}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28}],20:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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")),this.setHeader("via",""),this.setHeader("max-forwards",p.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 v(l,a,u),this.setHeader("to",this.to.toString());var h,d=s.from_uri||r.configuration.uri,f={tag:s.from_tag||m.newTag()};h=void 0!==s.from_display_name?s.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new v(d,h,f),this.setHeader("from",this.from.toString());var _=s.call_id||r.configuration.jssip_id+m.createRandomToken(15);this.call_id=_,this.setHeader("call-id",_);var g=s.cseq||Math.floor(1e4*Math.random());this.cseq=g,this.setHeader("cseq","".concat(g," ").concat(t))}return d(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(e=m.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=g.parse(r,e.replace(/-/g,"_"));return-1===s?(this.headers[e].splice(t,1),void y.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=s,s)}y.debug('not so many "'.concat(e,'" headers present'))}else y.debug('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[m.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=f.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),e}(),S=function(e){s(n,b);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 d(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||p.REASON_PHRASE[e]||"",n=m.cloneArray(n);var a="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===p.INVITE&&e>100&&e<=200){var c,h=u(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var d=c.value;a+="Record-Route: ".concat(d,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var f,_=u(this.getHeaders("via"));try{for(_.s();!(f=_.n()).done;){var v=f.value;a+="Via: ".concat(v,"\r\n")}}catch(e){_.e(e)}finally{_.f()}!this.to_tag&&e>100?l+=";tag=".concat(m.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 p.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 p.UPDATE:this.ua.configuration.session_timers&&o.push("timer"),r&&o.push("ice"),o.push("replaces")}if(o.push("outbound"),this.method===p.OPTIONS?(a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(o,"\r\n"),r){var C=m.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||p.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(m.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,b);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:T,InitialOutgoingInviteRequest:C,IncomingRequest:S,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":28,"sdp-transform":37}],22:[function(e,t,n){"use strict";var r=e("./Logger"),s=e("./Utils"),i=e("./Grammar"),o=new r("Socket");n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return o.warn("undefined JsSIP.Socket instance"),!1;try{if(!s.isString(e.url))throw o.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!s.isString(e.via_transport))throw o.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===i.parse(e.sip_uri,"SIP_URI"))throw o.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!s.isFunction(e[t]))throw o.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch(e){return!1}return!0}},{"./Grammar":7,"./Logger":9,"./Utils":28}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case b.STATUS_CALLING:this.stateChanged(b.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},m.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return b}}]),n}(),A=function(e){l(n,d);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(){y.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return b}}]),n}(),R=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){T.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,T.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case b.STATUS_TRYING:this.stateChanged(b.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case b.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 b.STATUS_TRYING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){s.timer_J()},m.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case b.STATUS_COMPLETED:}}},{key:"C",get:function(){return b}}]),n}(),w=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){C.debug("Timer H expired for transaction ".concat(this.id)),this.state===b.STATUS_COMPLETED&&C.debug("ACK not received, dialog will be terminated"),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){C.debug("Timer L expired for transaction ".concat(this.id)),this.state===b.STATUS_ACCEPTED&&(this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,C.debug("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(b.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 b.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===b.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){s.resend_provisional()},m.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){s.timer_L()},m.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case b.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case b.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(b.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},m.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:"C",get:function(){return b}}]),n}();t.exports={C:b,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:R,InviteServerTransaction:w,checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case _.INVITE:if(n=r.ist[t.via_branch]){switch(n.state){case b.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case b.STATUS_ACCEPTED:}return!0}break;case _.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===b.STATUS_ACCEPTED)return!1;if(n.state===b.STATUS_COMPLETED)return n.state=b.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},m.TIMER_I),!0;break;case _.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==b.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case b.STATUS_TRYING:break;case b.STATUS_PROCEEDING:case b.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Timers":23,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),l.debug("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){l.warn("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!i.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,s;return t=e,(n=[{key:"connect",value:function(){l.debug("connect()"),this.isConnected()?l.debug("Transport is already connected"):this.isConnecting()?l.debug("Transport is connecting"):(this.close_requested=!1,this.status=u.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.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.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.debug("send()"),!this.isConnected())return l.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return l.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),l.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void l.debug("received binary message failed to be converted into string, message discarded")}l.debug("received binary message:\n\n".concat(e,"\n"))}else l.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else l.debug("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}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./Socket":22}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R.debug("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R.debug("- ".concat(i,": NOT SHOWN"));break;default:R.debug("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}},{key:"C",get:function(){return w}},{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,"./Logger":9,"./Message":10,"./Options":12,"./Parser":13,"./RTCSession":14,"./Registrator":19,"./SIPMessage":21,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,events:31}],27:[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);n4&&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":28}],28:[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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,d,f,_,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>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&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;a1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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);n1)return d.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=h.str_utf8_length(i.body),t=i.getHeader("content-length");if(e0&&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 d(){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;t1&&(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=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=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):[]}},{}],32:[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":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t=0;for(let n=0;n{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{r[e]=t[e]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}},{ms:34}],34:[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))}},{}],35:[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,d=-1;function f(){h&&a&&(h=!1,a.length?c=a.concat(c):d=-1,c.length&&_())}function _(){if(!h){var e=u(f);h=!0;for(var t=c.length;t;){for(a=c,c=[];++d1)for(var n=1;n1&&(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=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":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.8.0",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","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)}); \ No newline at end of file From 7cfdc7e56158636c7e159f95d254571dd0386a47 Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 5 Jul 2021 15:32:16 +0300 Subject: [PATCH 51/70] fixed: init subscribe non-ok response no emit terminated --- lib/Subscriber.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Subscriber.js b/lib/Subscriber.js index dc050b228..eed1b8fc8 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -520,7 +520,7 @@ module.exports = class Subscriber extends EventEmitter _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) { // To prevent duplicate emit terminated event. - if (!this._dialog) + if (this._state === C.STATE_TERMINATED) { return; } @@ -531,8 +531,11 @@ module.exports = class Subscriber extends EventEmitter clearTimeout(this._expires_timer); clearTimeout(this._unsubscribe_timeout_timer); - this._dialog.terminate(); - this._dialog = null; + if (this._dialog) + { + this._dialog.terminate(); + this._dialog = null; + } debug(`emit "terminated" code=${terminationCode}`); this.emit('terminated', terminationCode, reason, retryAfter); From 864cff464932639f7162fa601c247c18ba007322 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 6 Jul 2021 13:52:35 +0300 Subject: [PATCH 52/70] equeue subscribe until init subscribe ok --- lib/Subscriber.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/Subscriber.js b/lib/Subscriber.js index eed1b8fc8..b74bebfa7 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -173,6 +173,9 @@ module.exports = class Subscriber extends EventEmitter { this._headers.push(`Allow-Events: ${allowEvents}`); } + + // To enqueue subscribes created before receive initial subscribe OK. + this._queue = []; } onRequestTimeout() @@ -312,7 +315,6 @@ module.exports = class Subscriber extends EventEmitter if (this._state === C.STATE_INIT) { - this._state = C.STATE_NOTIFY_WAIT; this._sendInitialSubscribe(body, this._headers); } else @@ -345,7 +347,7 @@ module.exports = class Subscriber extends EventEmitter return s.startsWith('Expires') ? 'Expires: 0' : s; }); - if (!this._dialog) + if (this._state === C.STATE_INIT) { // fetch-subscribe - initial subscribe with Expires: 0. this._sendInitialSubscribe(body, headers); @@ -396,6 +398,8 @@ module.exports = class Subscriber extends EventEmitter headers.push(`Content-Type: ${this._content_type}`); } + this._state = C.STATE_NOTIFY_WAIT; + const request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); @@ -439,6 +443,14 @@ module.exports = class Subscriber extends EventEmitter debug('emit "dialogCreated"'); this.emit('dialogCreated'); + + // Subsequent subscribes saved in the queue until dialog created. + for (const subscribe of this._queue) + { + debug('dequeue subscribe'); + + this._sendSubsequentSubscribe(subscribe.body, subscribe.headers); + } } // Check expires value. @@ -472,12 +484,20 @@ module.exports = class Subscriber extends EventEmitter _sendSubsequentSubscribe(body, headers) { - if (!this._dialog) + if (this._state === C.STATE_TERMINATED) { - debugerror('sending subsequent subscribe before OK response to initial subscribe'); - throw new Error('not received final response to initial SUBSCRIBE'); + return; } + + if (!this._dialog) + { + debug('enqueue subscribe'); + this._queue.push({ body, headers: headers.slice() }); + + return; + } + if (body) { if (!this._content_type) From d12ab9ee2384a529b4a5f856a1cb0b1c3ac41650 Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 8 Aug 2021 14:29:08 +0300 Subject: [PATCH 53/70] use logger instead debug, debugerror --- lib/Notifier.js | 25 ++++++------ lib/Subscriber.js | 43 ++++++++++----------- lib/UA.js | 98 ++++++++++++++++++++++++++++++++--------------- 3 files changed, 101 insertions(+), 65 deletions(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index 5ade1c049..843232892 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -1,11 +1,10 @@ const EventEmitter = require('events').EventEmitter; +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const Utils = require('./Utils'); const Dialog = require('./Dialog'); -const debug = require('debug')('JsSIP:Notifier'); -const debugerror = require('debug')('JsSIP:ERROR:Notifier'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('Notifier'); /** * Termination codes. @@ -55,7 +54,7 @@ module.exports = class Notifier extends EventEmitter */ constructor(ua, subscribe, contentType, { extraHeaders, allowEvents, pending }) { - debug('new'); + logger.debug('new'); super(); @@ -115,7 +114,7 @@ module.exports = class Notifier extends EventEmitter if (dialog.error) { - debugerror(dialog.error); + logger.warn(dialog.error); throw new Error('SUBSCRIBE missed Contact'); } @@ -149,7 +148,7 @@ module.exports = class Notifier extends EventEmitter { // Missed header Expires. RFC 6665 3.1.1. Set default expires value. expiresValue = '900'; - debug(`Missed expires header. Set by default ${expiresValue}`); + logger.debug(`Missed expires header. Set by default ${expiresValue}`); } this._expires = parseInt(expiresValue); @@ -164,7 +163,7 @@ module.exports = class Notifier extends EventEmitter this._setExpiresTimer(); } - debug('emit "subscribe"'); + logger.debug('emit "subscribe"'); this.emit('subscribe', is_unsubscribe, request, body, content_type); if (is_unsubscribe) @@ -181,7 +180,7 @@ module.exports = class Notifier extends EventEmitter */ start() { - debug('start()'); + logger.debug('start()'); this.receiveRequest(this._initial_subscribe); } @@ -191,7 +190,7 @@ module.exports = class Notifier extends EventEmitter */ setActiveState() { - debug('setActiveState()'); + logger.debug('setActiveState()'); if (this._state === C.STATE_PENDING) { @@ -205,12 +204,12 @@ module.exports = class Notifier extends EventEmitter */ notify(body = null) { - debug('notify()'); + logger.debug('notify()'); // Prevent send notify after final notify. if (!this._dialog) { - debugerror('final notify has sent'); + logger.warn('final notify has sent'); return; } @@ -289,7 +288,7 @@ module.exports = class Notifier extends EventEmitter */ terminate(body = null, reason = null, retryAfter = null) { - debug('terminate()'); + logger.debug('terminate()'); this._state = C.STATE_TERMINATED; this._terminated_reason = reason; @@ -337,7 +336,7 @@ module.exports = class Notifier extends EventEmitter const send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; - debug(`emit "terminated" code=${termination_code}, send final notify=${send_final_notify}`); + logger.debug(`emit "terminated" code=${termination_code}, send final notify=${send_final_notify}`); this.emit('terminated', termination_code, send_final_notify); } diff --git a/lib/Subscriber.js b/lib/Subscriber.js index b74bebfa7..ca806d4b7 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -1,14 +1,13 @@ const EventEmitter = require('events').EventEmitter; +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const Utils = require('./Utils'); const Grammar = require('./Grammar'); const SIPMessage = require('./SIPMessage'); const RequestSender = require('./RequestSender'); const Dialog = require('./Dialog'); -const debug = require('debug')('JsSIP:Subscriber'); -const debugerror = require('debug')('JsSIP:ERROR:Subscriber'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('Subscriber'); /** * Termination codes. @@ -67,7 +66,7 @@ module.exports = class Subscriber extends EventEmitter constructor(ua, target, eventName, accept, { expires, contentType, allowEvents, params, extraHeaders }) { - debug('new'); + logger.debug('new'); super(); @@ -195,7 +194,7 @@ module.exports = class Subscriber extends EventEmitter { if (request.method !== JsSIP_C.NOTIFY) { - debugerror('received non-NOTIFY request'); + logger.warn('received non-NOTIFY request'); request.reply(405); return; @@ -206,7 +205,7 @@ module.exports = class Subscriber extends EventEmitter if (!event_header) { - debugerror('missed Event header'); + logger.warn('missed Event header'); request.reply(400); this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); @@ -218,7 +217,7 @@ module.exports = class Subscriber extends EventEmitter if (event_name !== this._event_name || event_id !== this._event_id) { - debugerror('Event header does not match SUBSCRIBE'); + logger.warn('Event header does not match SUBSCRIBE'); request.reply(489); this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); @@ -230,7 +229,7 @@ module.exports = class Subscriber extends EventEmitter if (!subs_state) { - debugerror('missed Subscription-State header'); + logger.warn('missed Subscription-State header'); request.reply(400); this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); @@ -255,7 +254,7 @@ module.exports = class Subscriber extends EventEmitter // Expiration time is shorter and the difference is not too small. if (this._expires_timestamp - expires_timestamp > max_time_deviation) { - debug('update sending re-SUBSCRIBE time'); + logger.debug('update sending re-SUBSCRIBE time'); this._scheduleSubscribe(expires); } @@ -264,12 +263,12 @@ module.exports = class Subscriber extends EventEmitter if (prev_state !== C.STATE_PENDING && new_state === C.STATE_PENDING) { - debug('emit "pending"'); + logger.debug('emit "pending"'); this.emit('pending'); } else if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { - debug('emit "active"'); + logger.debug('emit "active"'); this.emit('active'); } @@ -283,7 +282,7 @@ module.exports = class Subscriber extends EventEmitter { const content_type = request.getHeader('content-type'); - debug('emit "notify"'); + logger.debug('emit "notify"'); this.emit('notify', is_final, request, body, content_type); } @@ -311,7 +310,7 @@ module.exports = class Subscriber extends EventEmitter */ subscribe(body = null) { - debug('subscribe()'); + logger.debug('subscribe()'); if (this._state === C.STATE_INIT) { @@ -330,12 +329,12 @@ module.exports = class Subscriber extends EventEmitter */ terminate(body = null) { - debug('terminate()'); + logger.debug('terminate()'); // Prevent duplication un-subscribe sending. if (this._send_unsubscribe) { - debugerror('unsubscribe has already been sent'); + logger.warn('unsubscribe has already been sent'); return; } @@ -433,7 +432,7 @@ module.exports = class Subscriber extends EventEmitter if (dialog.error) { // OK response without Contact - debugerror(dialog.error); + logger.warn(dialog.error); this._dialogTerminated(C.SUBSCRIBE_BAD_OK_RESPONSE); return; @@ -441,13 +440,13 @@ module.exports = class Subscriber extends EventEmitter this._dialog = dialog; - debug('emit "dialogCreated"'); + logger.debug('emit "dialogCreated"'); this.emit('dialogCreated'); // Subsequent subscribes saved in the queue until dialog created. for (const subscribe of this._queue) { - debug('dequeue subscribe'); + logger.debug('dequeue subscribe'); this._sendSubsequentSubscribe(subscribe.body, subscribe.headers); } @@ -458,7 +457,7 @@ module.exports = class Subscriber extends EventEmitter if (expires_value !== 0 && !expires_value) { - debugerror('response without Expires header'); + logger.warn('response without Expires header'); // RFC 6665 3.1.1 subscribe OK response must contain Expires header. // Use workaround expires value. @@ -491,7 +490,7 @@ module.exports = class Subscriber extends EventEmitter if (!this._dialog) { - debug('enqueue subscribe'); + logger.debug('enqueue subscribe'); this._queue.push({ body, headers: headers.slice() }); @@ -557,7 +556,7 @@ module.exports = class Subscriber extends EventEmitter this._dialog = null; } - debug(`emit "terminated" code=${terminationCode}`); + logger.debug(`emit "terminated" code=${terminationCode}`); this.emit('terminated', terminationCode, reason, retryAfter); } @@ -568,7 +567,7 @@ module.exports = class Subscriber extends EventEmitter this._expires_timestamp = new Date().getTime() + (expires * 1000); - debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); + logger.debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); clearTimeout(this._expires_timer); this._expires_timer = setTimeout(() => diff --git a/lib/UA.js b/lib/UA.js index 82585d13d..fa774d20b 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -1,10 +1,12 @@ const EventEmitter = require('events').EventEmitter; +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const Registrator = require('./Registrator'); const RTCSession = require('./RTCSession'); const Subscriber = require('./Subscriber'); const Notifier = require('./Notifier'); const Message = require('./Message'); +const Options = require('./Options'); const Transactions = require('./Transactions'); const Transport = require('./Transport'); const Utils = require('./Utils'); @@ -14,10 +16,8 @@ const Parser = require('./Parser'); const SIPMessage = require('./SIPMessage'); const sanityCheck = require('./sanityCheck'); const config = require('./Config'); -const debug = require('debug')('JsSIP:UA'); -const debugerror = require('debug')('JsSIP:ERROR:UA'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('UA'); const C = { // UA status codes. @@ -60,7 +60,7 @@ module.exports = class UA extends EventEmitter this._dynConfiguration = {}; this._dialogs = {}; - // User actions outside any session/dialog (MESSAGE). + // User actions outside any session/dialog (MESSAGE/OPTIONS). this._applicants = {}; this._sessions = {}; @@ -137,7 +137,7 @@ module.exports = class UA extends EventEmitter */ start() { - debug('start()'); + logger.debug('start()'); if (this._status === C.STATUS_INIT) { @@ -145,7 +145,7 @@ module.exports = class UA extends EventEmitter } else if (this._status === C.STATUS_USER_CLOSED) { - debug('restarting UA'); + logger.debug('restarting UA'); // Disconnect. if (this._closeTimer !== null) @@ -161,11 +161,11 @@ module.exports = class UA extends EventEmitter } else if (this._status === C.STATUS_READY) { - debug('UA is in READY status, not restarted'); + logger.debug('UA is in READY status, not restarted'); } else { - debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); + logger.debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); } // Set dynamic configuration. @@ -177,7 +177,7 @@ module.exports = class UA extends EventEmitter */ register() { - debug('register()'); + logger.debug('register()'); this._dynConfiguration.register = true; this._registrator.register(); @@ -188,7 +188,7 @@ module.exports = class UA extends EventEmitter */ unregister(options) { - debug('unregister()'); + logger.debug('unregister()'); this._dynConfiguration.register = false; this._registrator.unregister(options); @@ -229,7 +229,7 @@ module.exports = class UA extends EventEmitter */ call(target, options) { - debug('call()'); + logger.debug('call()'); const session = new RTCSession(this); @@ -250,7 +250,7 @@ module.exports = class UA extends EventEmitter */ sendMessage(target, body, options) { - debug('sendMessage()'); + logger.debug('sendMessage()'); const message = new Message(this); @@ -264,7 +264,7 @@ module.exports = class UA extends EventEmitter */ subscribe(target, eventName, accept, options) { - debug('subscribe()'); + logger.debug('subscribe()'); return new Subscriber(this, target, eventName, accept, options); } @@ -274,17 +274,37 @@ module.exports = class UA extends EventEmitter */ notify(subscribe, contentType, options) { - debug('notify()'); + logger.debug('notify()'); return new Notifier(this, subscribe, contentType, options); } + /** + * Send a SIP OPTIONS. + * + * -param {String} target + * -param {String} [body] + * -param {Object} [options] + * + * -throws {TypeError} + * + */ + sendOptions(target, body, options) + { + logger.debug('sendOptions()'); + + const message = new Options(this); + + message.send(target, body, options); + + return message; + } /** * Terminate ongoing sessions. */ terminateSessions(options) { - debug('terminateSessions()'); + logger.debug('terminateSessions()'); for (const idx in this._sessions) { @@ -301,14 +321,14 @@ module.exports = class UA extends EventEmitter */ stop() { - debug('stop()'); + logger.debug('stop()'); // Remove dynamic settings. this._dynConfiguration = {}; if (this._status === C.STATUS_USER_CLOSED) { - debug('UA already closed'); + logger.debug('UA already closed'); return; } @@ -324,7 +344,7 @@ module.exports = class UA extends EventEmitter { if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { - debug(`closing session ${session}`); + logger.debug(`closing session ${session}`); try { this._sessions[session].terminate(); } catch (error) {} } @@ -390,7 +410,7 @@ module.exports = class UA extends EventEmitter return this._configuration.authorization_jwt; default: - debugerror('get() | cannot get "%s" parameter in runtime', parameter); + logger.warn('get() | cannot get "%s" parameter in runtime', parameter); return undefined; } @@ -437,7 +457,7 @@ module.exports = class UA extends EventEmitter } default: - debugerror('set() | cannot set "%s" parameter in runtime', parameter); + logger.warn('set() | cannot set "%s" parameter in runtime', parameter); return false; } @@ -496,6 +516,15 @@ module.exports = class UA extends EventEmitter this.emit('newMessage', data); } + /** + * new Options + */ + newOptions(message, data) + { + this._applicants[message] = message; + this.emit('newOptions', data); + } + /** * Message destroyed. */ @@ -560,7 +589,7 @@ module.exports = class UA extends EventEmitter if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { - debug('Request-URI does not point to us'); + logger.debug('Request-URI does not point to us'); if (request.method !== JsSIP_C.ACK) { request.reply_sl(404); @@ -604,7 +633,16 @@ module.exports = class UA extends EventEmitter */ if (method === JsSIP_C.OPTIONS) { - request.reply(200); + if (this.listeners('newOptions').length === 0) + { + request.reply(200); + + return; + } + + const message = new Options(this); + + message.init_incoming(request); } else if (method === JsSIP_C.MESSAGE) { @@ -680,7 +718,7 @@ module.exports = class UA extends EventEmitter } else { - debugerror('INVITE received but WebRTC is not supported'); + logger.warn('INVITE received but WebRTC is not supported'); request.reply(488); } break; @@ -696,7 +734,7 @@ module.exports = class UA extends EventEmitter } else { - debug('received CANCEL request for a non existent session'); + logger.debug('received CANCEL request for a non existent session'); } break; case JsSIP_C.ACK: @@ -742,7 +780,7 @@ module.exports = class UA extends EventEmitter } else { - debug('received NOTIFY request for a non existent subscription'); + logger.debug('received NOTIFY request for a non existent subscription'); request.reply(481, 'Subscription does not exist'); } } @@ -867,7 +905,7 @@ module.exports = class UA extends EventEmitter } catch (e) { - debugerror(e); + logger.warn(e); throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); } @@ -964,7 +1002,7 @@ module.exports = class UA extends EventEmitter } } - debug('configuration parameters after validation:'); + logger.debug('configuration parameters after validation:'); for (const parameter in this._configuration) { // Only show the user user configurable parameters. @@ -974,15 +1012,15 @@ module.exports = class UA extends EventEmitter { case 'uri': case 'registrar_server': - debug(`- ${parameter}: ${this._configuration[parameter]}`); + logger.debug(`- ${parameter}: ${this._configuration[parameter]}`); break; case 'password': case 'ha1': case 'authorization_jwt': - debug(`- ${parameter}: NOT SHOWN`); + logger.debug(`- ${parameter}: NOT SHOWN`); break; default: - debug(`- ${parameter}: ${JSON.stringify(this._configuration[parameter])}`); + logger.debug(`- ${parameter}: ${JSON.stringify(this._configuration[parameter])}`); } } } From f30314805ed427f72ffdc554aed9a51e99556a6a Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 23 Sep 2021 19:32:55 +0300 Subject: [PATCH 54/70] subscriber/notifer set contact as ua._contact.toString() --- lib/Notifier.js | 2 +- lib/Subscriber.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index 843232892..d3ef9eec8 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -96,7 +96,7 @@ module.exports = class Notifier extends EventEmitter this._contact = this._headers.find((header) => header.startsWith('Contact')); if (!this._contact) { - this._contact = `Contact: `; + this._contact = `Contact: ${this._ua._contact.toString()}`; this._headers.push(this._contact); } diff --git a/lib/Subscriber.js b/lib/Subscriber.js index ca806d4b7..58868ad40 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -162,9 +162,9 @@ module.exports = class Subscriber extends EventEmitter if (!this._headers.find((header) => header.startsWith('Contact'))) { - let contact = `Contact: `; - contact += `;+sip.instance=""`; + const contact = `Contact: ${this._ua._contact.toString()}`; + this._headers.push(contact); } From 6f304179e5cd9766c8d646ab36ee2298db0767b0 Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 25 Sep 2021 23:25:57 +0300 Subject: [PATCH 55/70] added unit test subscriber/notifier communiction --- gulpfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 9a63a7795..5feebdb58 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -105,7 +105,8 @@ gulp.task('test', function() 'test/test-parser.js', 'test/test-properties.js', 'test/test-UA-no-WebRTC.js', - 'test/test-digestAuthentication.js' + 'test/test-digestAuthentication.js', + 'test/test-UA-subscriber-notifier.js' ]; return gulp.src(src) From 642d500222b178ba2b1e7e070c8740fd6039d8dd Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 25 Sep 2021 23:25:57 +0300 Subject: [PATCH 56/70] added unit test subscriber/notifier communiction --- gulpfile.js | 3 +- test/include/loopSocket.js | 48 +++++++++ test/test-UA-subscriber-notifier.js | 147 ++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 test/include/loopSocket.js create mode 100644 test/test-UA-subscriber-notifier.js diff --git a/gulpfile.js b/gulpfile.js index 9a63a7795..5feebdb58 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -105,7 +105,8 @@ gulp.task('test', function() 'test/test-parser.js', 'test/test-properties.js', 'test/test-UA-no-WebRTC.js', - 'test/test-digestAuthentication.js' + 'test/test-digestAuthentication.js', + 'test/test-UA-subscriber-notifier.js' ]; return gulp.src(src) diff --git a/test/include/loopSocket.js b/test/include/loopSocket.js new file mode 100644 index 000000000..9055bd296 --- /dev/null +++ b/test/include/loopSocket.js @@ -0,0 +1,48 @@ +// LoopSocket send message itself. +// Used P2P logic: message call-id is modified in each leg. +module.exports = class LoopSocket +{ + constructor() + { + this.url = 'ws://localhost:12345'; + this.via_transport = 'WS'; + this.sip_uri = 'sip:localhost:12345;transport=ws'; + } + + connect() + { + setTimeout(() => { this.onconnect(); }, 0); + } + + disconnect() + { + } + + send(message) + { + const message2 = this._modifyCallId(message); + + setTimeout(() => { this.ondata(message2); }, 0); + + return true; + } + + // Call-ID: add or drop word '_second'. + _modifyCallId(message) + { + const ixBegin = message.indexOf('Call-ID'); + const ixEnd = message.indexOf('\r', ixBegin); + let callId = message.substring(ixBegin+9, ixEnd); + + if (callId.endsWith('_second')) + { + callId = callId.substring(0, callId.length - 7); + } + else + { + callId += '_second'; + } + + return `${message.substring(0, ixBegin)}Call-ID: ${callId}${message.substring(ixEnd)}`; + } +}; \ No newline at end of file diff --git a/test/test-UA-subscriber-notifier.js b/test/test-UA-subscriber-notifier.js new file mode 100644 index 000000000..0b1792760 --- /dev/null +++ b/test/test-UA-subscriber-notifier.js @@ -0,0 +1,147 @@ +/* eslint no-console: 0*/ + +require('./include/common'); +const JsSIP = require('../'); +const LoopSocket = require('./include/LoopSocket'); + +module.exports = { + 'subscriber/notifier communication' : function(test) + { + test.expect(17); + + let notifyCounter = 0; + const notifyMaxCounter = 1; + const weatherRequest = 'Please report the weather condition'; + const weatherReport = '+20..+24°C, no precipitation, light wind'; + const contentType = 'text/plain'; + + function createNotifier(ua, subscribe) + { + + const notifier = ua.notify(subscribe, contentType, { pending: false }); + + // Receive subscribe (includes initial) + notifier.on('subscribe', (isUnsubscribe, subs, body, contType) => + { + test.strictEqual(body, weatherRequest, 'received subscribe body'); + test.strictEqual(contType, contentType, 'received subscribe content-type'); + + if (isUnsubscribe) + { + notifier.terminate(weatherReport); + } + else + { + notifier.notify(weatherReport); + } + }); + + notifier.on('terminated', (terminationCode, sendFinalNotify) => + { + if (sendFinalNotify) + { + notifier.terminate(weatherReport); + } + }); + + notifier.start(); + } + + function createSubscriber(ua) + { + const target = 'ikq'; + const eventName = 'weather'; + const accept = 'application/text, text/plain'; + const options = { + expires : 3600, + contentType : 'text/plain', + params : null + }; + + const subscriber = ua.subscribe(target, eventName, accept, options); + + subscriber.on('active', () => + { + test.ok(true, 'receive NOTIFY with Subscription-state: active'); + }); + + subscriber.on('notify', (isFinal, notify, body, contType) => + { + test.strictEqual(body, weatherReport, 'received notify body'); + test.strictEqual(contType, contentType, 'received notify content-type'); + + if (++notifyCounter === notifyMaxCounter) + { + test.ok(true, 'send unsubscrige'); + subscriber.terminate(weatherRequest); + } + }); + + subscriber.on('terminated', (terminationCode, reason, retryAfter) => + { + test.ok(terminationCode === subscriber.C.RECEIVE_FINAL_NOTIFY); + test.ok(reason === undefined); + test.ok(retryAfter === undefined); + + ua.stop(); + test.done(); + }); + + subscriber.on('dialogCreated', () => + { + test.ok(true, 'subscribe dialog created'); + }); + + subscriber.subscribe(weatherRequest); + } + + const config = + { + sockets : new LoopSocket(), // message sending itself, with modified Call-ID + uri : 'sip:ikq@example.com', + contact_uri : 'sip:ikq@abcdefabcdef.invalid;transport=ws', + register : false + }; + + const ua = new JsSIP.UA(config); + + // Uncomment to see SIP communication + // JsSIP.debug.enable('JsSIP:*'); + + ua.on('newSubscribe', (e) => + { + test.ok(true, 'receive SUBSCRIBE'); + + const subs = e.request; + const ev = subs.parseHeader('event'); + + test.strictEqual(ev.event, 'weather'); + if (ev.event !== 'weather') + { + subs.reply(489); // "Bad Event" + + return; + } + + const accepts = subs.getHeaders('accept'); + const isAcceptOK = accepts && accepts.some((v) => v.includes('text/plain')); + + test.ok(isAcceptOK, 'notifier understand subscribe accept header'); + if (!isAcceptOK) + { + subs.reply(406); // "Not Acceptable" + + return; + } + + createNotifier(ua, subs); + }); + + ua.on('connected', () => + { + createSubscriber(ua); + }); + + ua.start(); + } +}; \ No newline at end of file From 1e565a451009b8b9f85009d68e8bbb845284154f Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 26 Sep 2021 12:01:40 +0300 Subject: [PATCH 57/70] unit test improvement: eventSequence checking --- test/test-UA-subscriber-notifier.js | 45 ++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/test/test-UA-subscriber-notifier.js b/test/test-UA-subscriber-notifier.js index 0b1792760..f85d41b51 100644 --- a/test/test-UA-subscriber-notifier.js +++ b/test/test-UA-subscriber-notifier.js @@ -7,17 +7,15 @@ const LoopSocket = require('./include/LoopSocket'); module.exports = { 'subscriber/notifier communication' : function(test) { - test.expect(17); - - let notifyCounter = 0; - const notifyMaxCounter = 1; + test.expect(26); + + let eventSequence = 0; const weatherRequest = 'Please report the weather condition'; const weatherReport = '+20..+24°C, no precipitation, light wind'; const contentType = 'text/plain'; function createNotifier(ua, subscribe) { - const notifier = ua.notify(subscribe, contentType, { pending: false }); // Receive subscribe (includes initial) @@ -28,16 +26,23 @@ module.exports = { if (isUnsubscribe) { + test.ok(++eventSequence === 9, 'receive un-subscribe, send final notify'); + notifier.terminate(weatherReport); } else { + test.ok(++eventSequence === 4, 'receive subscribe, send notify'); + notifier.notify(weatherReport); } }); notifier.on('terminated', (terminationCode, sendFinalNotify) => { + test.ok(++eventSequence === 10, 'notifier terminated'); + test.ok(!sendFinalNotify, 'here final notify sending if subscription expired'); + if (sendFinalNotify) { notifier.terminate(weatherReport); @@ -62,36 +67,44 @@ module.exports = { subscriber.on('active', () => { - test.ok(true, 'receive NOTIFY with Subscription-state: active'); + test.ok(++eventSequence === 6, 'receive notify with subscription-state: active'); }); subscriber.on('notify', (isFinal, notify, body, contType) => { + eventSequence++; + test.ok(eventSequence === 7 || eventSequence === 11, 'receive notify'); test.strictEqual(body, weatherReport, 'received notify body'); test.strictEqual(contType, contentType, 'received notify content-type'); - - if (++notifyCounter === notifyMaxCounter) + + // After receiving the first notify, send un-subscribe. + if (eventSequence === 7) { - test.ok(true, 'send unsubscrige'); + test.ok(++eventSequence === 8, 'send un-subscribe'); + subscriber.terminate(weatherRequest); } }); subscriber.on('terminated', (terminationCode, reason, retryAfter) => { + test.ok(++eventSequence === 12, 'subscriber terminated'); test.ok(terminationCode === subscriber.C.RECEIVE_FINAL_NOTIFY); test.ok(reason === undefined); - test.ok(retryAfter === undefined); - + test.ok(retryAfter === undefined); + ua.stop(); + test.done(); }); subscriber.on('dialogCreated', () => { - test.ok(true, 'subscribe dialog created'); + test.ok(++eventSequence === 5, 'subscriber - dialog created'); }); + test.ok(++eventSequence === 2, 'send subscribe'); + subscriber.subscribe(weatherRequest); } @@ -104,18 +117,19 @@ module.exports = { }; const ua = new JsSIP.UA(config); - + // Uncomment to see SIP communication // JsSIP.debug.enable('JsSIP:*'); ua.on('newSubscribe', (e) => { - test.ok(true, 'receive SUBSCRIBE'); + test.ok(++eventSequence === 3, 'receive initial subscribe'); const subs = e.request; const ev = subs.parseHeader('event'); test.strictEqual(ev.event, 'weather'); + if (ev.event !== 'weather') { subs.reply(489); // "Bad Event" @@ -127,6 +141,7 @@ module.exports = { const isAcceptOK = accepts && accepts.some((v) => v.includes('text/plain')); test.ok(isAcceptOK, 'notifier understand subscribe accept header'); + if (!isAcceptOK) { subs.reply(406); // "Not Acceptable" @@ -139,6 +154,8 @@ module.exports = { ua.on('connected', () => { + test.ok(++eventSequence === 1, 'socket connected event'); + createSubscriber(ua); }); From 2775008ddb1be3ebc444cf0cd92882af8644cb82 Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 27 Sep 2021 11:03:35 +0300 Subject: [PATCH 58/70] unit test improvement: check url, method, contact, accept, subscription-state --- test/test-UA-subscriber-notifier.js | 125 ++++++++++++++++------------ 1 file changed, 70 insertions(+), 55 deletions(-) diff --git a/test/test-UA-subscriber-notifier.js b/test/test-UA-subscriber-notifier.js index f85d41b51..450402a41 100644 --- a/test/test-UA-subscriber-notifier.js +++ b/test/test-UA-subscriber-notifier.js @@ -7,63 +7,28 @@ const LoopSocket = require('./include/LoopSocket'); module.exports = { 'subscriber/notifier communication' : function(test) { - test.expect(26); + test.expect(39); let eventSequence = 0; - const weatherRequest = 'Please report the weather condition'; - const weatherReport = '+20..+24°C, no precipitation, light wind'; - const contentType = 'text/plain'; - function createNotifier(ua, subscribe) - { - const notifier = ua.notify(subscribe, contentType, { pending: false }); - - // Receive subscribe (includes initial) - notifier.on('subscribe', (isUnsubscribe, subs, body, contType) => - { - test.strictEqual(body, weatherRequest, 'received subscribe body'); - test.strictEqual(contType, contentType, 'received subscribe content-type'); - - if (isUnsubscribe) - { - test.ok(++eventSequence === 9, 'receive un-subscribe, send final notify'); - - notifier.terminate(weatherReport); - } - else - { - test.ok(++eventSequence === 4, 'receive subscribe, send notify'); - - notifier.notify(weatherReport); - } - }); - - notifier.on('terminated', (terminationCode, sendFinalNotify) => - { - test.ok(++eventSequence === 10, 'notifier terminated'); - test.ok(!sendFinalNotify, 'here final notify sending if subscription expired'); - - if (sendFinalNotify) - { - notifier.terminate(weatherReport); - } - }); - - notifier.start(); - } - + const TARGET = 'ikq'; + const REQUEST_URI = 'sip:ikq@example.com'; + const CONTACT_URI = 'sip:ikq@abcdefabcdef.invalid;transport=ws'; + const SUBSCRIBE_ACCEPT = 'application/text, text/plain'; + const EVENT_NAME = 'weather'; + const CONTENT_TYPE = 'text/plain'; + const WEATHER_REQUEST = 'Please report the weather condition'; + const WEATHER_REPORT = '+20..+24°C, no precipitation, light wind'; + function createSubscriber(ua) { - const target = 'ikq'; - const eventName = 'weather'; - const accept = 'application/text, text/plain'; const options = { expires : 3600, - contentType : 'text/plain', + contentType : CONTENT_TYPE, params : null }; - const subscriber = ua.subscribe(target, eventName, accept, options); + const subscriber = ua.subscribe(TARGET, EVENT_NAME, SUBSCRIBE_ACCEPT, options); subscriber.on('active', () => { @@ -74,15 +39,22 @@ module.exports = { { eventSequence++; test.ok(eventSequence === 7 || eventSequence === 11, 'receive notify'); - test.strictEqual(body, weatherReport, 'received notify body'); - test.strictEqual(contType, contentType, 'received notify content-type'); + + test.strictEqual(notify.method, 'NOTIFY'); + test.strictEqual(notify.getHeader('contact'), `<${CONTACT_URI}>`, 'notify contact'); + test.strictEqual(body, WEATHER_REPORT, 'notify body'); + test.strictEqual(contType, CONTENT_TYPE, 'notify content-type'); + + const subsState = notify.parseHeader('subscription-state').state; + + test.ok(subsState === 'active' || subsState === 'terminated', 'notify subscription-state'); // After receiving the first notify, send un-subscribe. if (eventSequence === 7) { test.ok(++eventSequence === 8, 'send un-subscribe'); - subscriber.terminate(weatherRequest); + subscriber.terminate(WEATHER_REQUEST); } }); @@ -105,14 +77,56 @@ module.exports = { test.ok(++eventSequence === 2, 'send subscribe'); - subscriber.subscribe(weatherRequest); + subscriber.subscribe(WEATHER_REQUEST); + } + + function createNotifier(ua, subscribe) + { + const notifier = ua.notify(subscribe, CONTENT_TYPE, { pending: false }); + + // Receive subscribe (includes initial) + notifier.on('subscribe', (isUnsubscribe, subs, body, contType) => + { + test.strictEqual(subscribe.method, 'SUBSCRIBE'); + test.strictEqual(subscribe.getHeader('contact'), `<${CONTACT_URI}>`, 'subscribe contact'); + test.strictEqual(subscribe.getHeader('accept'), SUBSCRIBE_ACCEPT, 'subscribe accept'); + test.strictEqual(body, WEATHER_REQUEST, 'subscribe body'); + test.strictEqual(contType, CONTENT_TYPE, 'subscribe content-type'); + + if (isUnsubscribe) + { + test.ok(++eventSequence === 9, 'receive un-subscribe, send final notify'); + + notifier.terminate(WEATHER_REPORT); + } + else + { + test.ok(++eventSequence === 4, 'receive subscribe, send notify'); + + notifier.notify(WEATHER_REPORT); + } + }); + + notifier.on('terminated', (terminationCode, sendFinalNotify) => + { + test.ok(++eventSequence === 10, 'notifier terminated'); + test.ok(!sendFinalNotify, 'final notify sending if subscription expired'); + + if (sendFinalNotify) + { + notifier.terminate(WEATHER_REPORT); + } + }); + + notifier.start(); } + // Start JsSIP UA with loop socket. const config = { sockets : new LoopSocket(), // message sending itself, with modified Call-ID - uri : 'sip:ikq@example.com', - contact_uri : 'sip:ikq@abcdefabcdef.invalid;transport=ws', + uri : REQUEST_URI, + contact_uri : CONTACT_URI, register : false }; @@ -128,9 +142,10 @@ module.exports = { const subs = e.request; const ev = subs.parseHeader('event'); - test.strictEqual(ev.event, 'weather'); + test.strictEqual(subs.ruri.toString(), REQUEST_URI, 'initial subscribe uri'); + test.strictEqual(ev.event, EVENT_NAME, 'subscribe event'); - if (ev.event !== 'weather') + if (ev.event !== EVENT_NAME) { subs.reply(489); // "Bad Event" From 8cfc57458b76891097b2b1431b3dfca88375d134 Mon Sep 17 00:00:00 2001 From: igor Date: Mon, 27 Sep 2021 11:32:47 +0300 Subject: [PATCH 59/70] fixed typo issues --- test/test-UA-subscriber-notifier.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test-UA-subscriber-notifier.js b/test/test-UA-subscriber-notifier.js index 450402a41..835132575 100644 --- a/test/test-UA-subscriber-notifier.js +++ b/test/test-UA-subscriber-notifier.js @@ -47,7 +47,7 @@ module.exports = { const subsState = notify.parseHeader('subscription-state').state; - test.ok(subsState === 'active' || subsState === 'terminated', 'notify subscription-state'); + test.ok(subsState === 'pending' || subsState === 'active' || subsState === 'terminated', 'notify subscription-state'); // After receiving the first notify, send un-subscribe. if (eventSequence === 7) @@ -72,7 +72,7 @@ module.exports = { subscriber.on('dialogCreated', () => { - test.ok(++eventSequence === 5, 'subscriber - dialog created'); + test.ok(++eventSequence === 5, 'subscriber dialog created'); }); test.ok(++eventSequence === 2, 'send subscribe'); @@ -153,11 +153,11 @@ module.exports = { } const accepts = subs.getHeaders('accept'); - const isAcceptOK = accepts && accepts.some((v) => v.includes('text/plain')); + const canUse = accepts && accepts.some((v) => v.includes(CONTENT_TYPE)); - test.ok(isAcceptOK, 'notifier understand subscribe accept header'); + test.ok(canUse, 'notifier can use subscribe accept header'); - if (!isAcceptOK) + if (!canUse) { subs.reply(406); // "Not Acceptable" @@ -169,7 +169,7 @@ module.exports = { ua.on('connected', () => { - test.ok(++eventSequence === 1, 'socket connected event'); + test.ok(++eventSequence === 1, 'socket connected'); createSubscriber(ua); }); From 5262d48ea767b1d5593aad5fdd4dffc4e840aebc Mon Sep 17 00:00:00 2001 From: Igor Kolosov <10967586+ikq@users.noreply.github.com> Date: Tue, 5 Oct 2021 16:34:44 +0300 Subject: [PATCH 60/70] Update lib/Subscriber.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Luis Millán --- lib/Subscriber.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 58868ad40..b8faa09a7 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -341,9 +341,9 @@ module.exports = class Subscriber extends EventEmitter this._send_unsubscribe = true; // Set header Expires: 0. - const headers = this._headers.map((s) => + const headers = this._headers.map((header) => { - return s.startsWith('Expires') ? 'Expires: 0' : s; + return header.startsWith('Expires') ? 'Expires: 0' : header; }); if (this._state === C.STATE_INIT) From ecdc2ae430161c017f2b18c5875d342ddcdf44f5 Mon Sep 17 00:00:00 2001 From: Igor Kolosov <10967586+ikq@users.noreply.github.com> Date: Tue, 5 Oct 2021 17:13:55 +0300 Subject: [PATCH 61/70] Update lib/Notifier.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I'll add parseInt Co-authored-by: José Luis Millán --- lib/Notifier.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index d3ef9eec8..3afc9a885 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -142,16 +142,17 @@ module.exports = class Notifier extends EventEmitter return; } - let expiresValue = request.getHeader('expires'); - - if (expiresValue === undefined || expiresValue === null) + if (request.hasHeader('expires')) { - // Missed header Expires. RFC 6665 3.1.1. Set default expires value. - expiresValue = '900'; - logger.debug(`Missed expires header. Set by default ${expiresValue}`); + this._expires = request.getHeader('expires') + } + else + { + // RFC 6665 3.1.1, default expires value. + this._expires = 900; + + logger.debug(`missing Expires header field, default value set: ${this._expires}`); } - - this._expires = parseInt(expiresValue); request.reply(200, null, [ `Expires: ${this._expires}`, `${this._contact}` ]); const body = request.body; From 7c9e97cd1222c152e10d6b1e979708c0617cb662 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 5 Oct 2021 20:29:53 +0300 Subject: [PATCH 62/70] some of the changes after the review --- lib/Notifier.js | 14 ++++++-------- lib/Subscriber.js | 18 ++++++++++++++++-- test/test-UA-subscriber-notifier.js | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index 3afc9a885..34579cb33 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -63,6 +63,11 @@ module.exports = class Notifier extends EventEmitter throw new TypeError('subscribe is undefined'); } + if (!subscribe.hasHeader('contact')) + { + throw new TypeError('subscribe - no contact header'); + } + if (!contentType) { throw new TypeError('contentType is undefined'); @@ -112,13 +117,6 @@ module.exports = class Notifier extends EventEmitter // Create dialog for normal and fetch-subscribe. const dialog = new Dialog(this, subscribe, 'UAS'); - if (dialog.error) - { - logger.warn(dialog.error); - - throw new Error('SUBSCRIBE missed Contact'); - } - this._dialog = dialog; if (this._expires > 0) @@ -144,7 +142,7 @@ module.exports = class Notifier extends EventEmitter if (request.hasHeader('expires')) { - this._expires = request.getHeader('expires') + this._expires = parseInt(request.getHeader('expires')); } else { diff --git a/lib/Subscriber.js b/lib/Subscriber.js index b8faa09a7..c89a720a7 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -440,8 +440,8 @@ module.exports = class Subscriber extends EventEmitter this._dialog = dialog; - logger.debug('emit "dialogCreated"'); - this.emit('dialogCreated'); + logger.debug('emit "accepted"'); + this.emit('accepted'); // Subsequent subscribes saved in the queue until dialog created. for (const subscribe of this._queue) @@ -562,6 +562,20 @@ module.exports = class Subscriber extends EventEmitter _scheduleSubscribe(expires) { + /* + If the expires time is less than 140 seconds we do not support Chrome intensive timer throttling mode. + In this case, the re-subcribe is sent 5 seconds before the subscription expiration. + + When Chrome is intensive timer throttling mode, in the worst case, + the timer will be 60 seconds late. + We give the server 10 seconds to make sure it will execute the command even if it is heavily loaded. + As a result, we order the time no later than 70 seconds before the subscription expiration. + Resulting time calculated as half time interval + (half interval - 70) * random. + + E.g. expires is 140, re-subscribe will be ordered to send in 70 seconds. + expires is 600, re-subscribe will be ordered to send in 300 + (0 .. 230) seconds. + */ + const timeout = expires >= 140 ? (expires * 1000 / 2) + Math.floor(((expires / 2) - 70) * 1000 * Math.random()) : (expires * 1000) - 5000; diff --git a/test/test-UA-subscriber-notifier.js b/test/test-UA-subscriber-notifier.js index 835132575..1b3670762 100644 --- a/test/test-UA-subscriber-notifier.js +++ b/test/test-UA-subscriber-notifier.js @@ -70,9 +70,9 @@ module.exports = { test.done(); }); - subscriber.on('dialogCreated', () => + subscriber.on('accepted', () => { - test.ok(++eventSequence === 5, 'subscriber dialog created'); + test.ok(++eventSequence === 5, 'initial subscribe accepted'); }); test.ok(++eventSequence === 2, 'send subscribe'); From 2d326675ead90c400ab62dba0b8210cfce214303 Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 6 Oct 2021 15:24:14 +0300 Subject: [PATCH 63/70] modified terminate() --- lib/Subscriber.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Subscriber.js b/lib/Subscriber.js index c89a720a7..d16017ca7 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -127,8 +127,8 @@ module.exports = class Subscriber extends EventEmitter this._expires_timer = null; this._expires_timestamp = null; - // To prevent duplicate un-subscribe sending. - this._send_unsubscribe = false; + // To prevent duplicate terminated call. + this._terminated = false; // After send un-subscribe wait final notify limited time. this._unsubscribe_timeout_timer = null; @@ -332,13 +332,12 @@ module.exports = class Subscriber extends EventEmitter logger.debug('terminate()'); // Prevent duplication un-subscribe sending. - if (this._send_unsubscribe) + if (this._terminated) { - logger.warn('unsubscribe has already been sent'); return; } - this._send_unsubscribe = true; + this._terminated = true; // Set header Expires: 0. const headers = this._headers.map((header) => From fc88e8d5c1dface691fb5ce1b9233b7492ca920a Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 6 Oct 2021 15:28:42 +0300 Subject: [PATCH 64/70] fixed typo in comment --- lib/Subscriber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Subscriber.js b/lib/Subscriber.js index d16017ca7..6b1737d71 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -565,7 +565,7 @@ module.exports = class Subscriber extends EventEmitter If the expires time is less than 140 seconds we do not support Chrome intensive timer throttling mode. In this case, the re-subcribe is sent 5 seconds before the subscription expiration. - When Chrome is intensive timer throttling mode, in the worst case, + When Chrome is in intensive timer throttling mode, in the worst case, the timer will be 60 seconds late. We give the server 10 seconds to make sure it will execute the command even if it is heavily loaded. As a result, we order the time no later than 70 seconds before the subscription expiration. From ad374975f912633aa4ad94ad89440fa385719b5b Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 8 Dec 2021 09:57:45 +0200 Subject: [PATCH 65/70] fixed ts constant definition --- lib/Subscriber.d.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts index d63e10491..2fdb047a8 100644 --- a/lib/Subscriber.d.ts +++ b/lib/Subscriber.d.ts @@ -6,10 +6,11 @@ declare enum SubscriberTerminatedCode { SUBSCRIBE_RESPONSE_TIMEOUT = 0, SUBSCRIBE_TRANSPORT_ERROR = 1, SUBSCRIBE_NON_OK_RESPONSE = 2, - SUBSCRIBE_FAILED_AUTHENTICATION = 3, - UNSUBSCRIBE_TIMEOUT = 4, - RECEIVE_FINAL_NOTIFY = 5, - RECEIVE_BAD_NOTIFY = 6 + SUBSCRIBE_BAD_OK_RESPONSE = 3, + SUBSCRIBE_FAILED_AUTHENTICATION = 4, + UNSUBSCRIBE_TIMEOUT = 5, + RECEIVE_FINAL_NOTIFY = 6, + RECEIVE_BAD_NOTIFY = 7 } export class Subscriber extends EventEmitter { From 759d40e4e03c8f8cbcb633470f07abb3e29069ed Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 4 Sep 2022 18:38:06 +0300 Subject: [PATCH 66/70] fixed ts definitions --- lib/Constants.d.ts | 2 +- lib/UA.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Constants.d.ts b/lib/Constants.d.ts index 465552f49..ca99e19b9 100644 --- a/lib/Constants.d.ts +++ b/lib/Constants.d.ts @@ -57,7 +57,7 @@ export enum DTMF_TRANSPORT { } export const REASON_PHRASE: Record -export const ALLOWED_METHODS = 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY' +export const ALLOWED_METHODS = 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY,SUBSCRIBE' export const ACCEPTED_BODY_TYPES = 'application/sdp, application/dtmf-relay' export const MAX_FORWARDS = 69 export const SESSION_EXPIRES = 90 diff --git a/lib/UA.d.ts b/lib/UA.d.ts index e74bcdb4a..230eefcfb 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -204,7 +204,7 @@ export class UA extends EventEmitter { subscribe(target: string, eventName: string, accept: string, options?: SubscriberOptions): Subscriber; - notifier( subscribe: IncomingRequest, contentType: string, options?: NotifierOptions): Notifier; + notify( subscribe: IncomingRequest, contentType: string, options?: NotifierOptions): Notifier; terminateSessions(options?: TerminateOptions): void; From 95a23258a2328d8fdc19952e641d0353a147a443 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 3 Nov 2023 14:36:59 +0200 Subject: [PATCH 67/70] removed spaces before EOL. Synchronized with latest master --- .eslintrc.js | 1 + CHANGELOG.md | 10 ++ dist/jssip.js | 38 +++++-- dist/jssip.min.js | 6 +- lib/Config.js | 17 +++- lib/Notifier.js | 100 +++++++++---------- lib/RTCSession.d.ts | 20 ++-- lib/RTCSession.js | 12 ++- lib/Registrator.js | 23 ++++- lib/Subscriber.js | 150 ++++++++++++++-------------- lib/Transport.js | 20 +++- lib/UA.d.ts | 6 +- lib/UA.js | 17 ++-- package.json | 2 +- test/include/loopSocket.js | 18 ++-- test/test-UA-subscriber-notifier.js | 106 ++++++++++---------- 16 files changed, 316 insertions(+), 230 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d8a779d41..f9ee93327 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -139,6 +139,7 @@ module.exports = 'no-sparse-arrays': 2, 'no-this-before-super': 2, 'no-throw-literal': 2, + 'no-trailing-spaces': 2, 'no-undef': 2, 'no-unexpected-multiline': 2, 'no-unmodified-loop-condition': 2, diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a89cbb4e..ce01fd5df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,17 @@ CHANGELOG ### NEXT RELEASE +* New UA config param register_from_tag_trail (#793). Credits to @kkozlik. + + +### 3.10.1 + * TS: fix socket/transport types (#790). +* Transport: Handle keep alive request from server (#791). +* Prevent repeated ICE finish (#800). Credits to @pschichtel . +* Use built-in MediaStreamConstraints type (#809). Credits to @edumt. +* Add extra_headers as a modificable property (#825). Credits to @cesterlizi. +* Fix type definitions to not import Listener from events #837. Credits to @jlaine. ### 3.10.0 diff --git a/dist/jssip.js b/dist/jssip.js index 743304ab1..97c924c4d 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -1,7 +1,7 @@ /* - * JsSIP v3.10.0 + * JsSIP v3.10.1 * the Javascript SIP library - * Copyright: 2012-2022 + * Copyright: 2012-2023 * Homepage: https://jssip.net * License: MIT */ @@ -19049,6 +19049,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this13._iceReady = false; var ready = function ready() { + if (finished) { + return; + } + connection.removeEventListener('icecandidate', iceCandidateListener); connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener); finished = true; @@ -19075,12 +19079,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { candidate: candidate, ready: ready }); - } else if (!finished) { + } else { ready(); } }); connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = function iceGatheringStateListener() { - if (connection.iceGatheringState === 'complete' && !finished) { + if (connection.iceGatheringState === 'complete') { ready(); } }); @@ -23854,7 +23858,21 @@ module.exports = /*#__PURE__*/function () { }, { key: "_onData", value: function _onData(data) { - // CRLF Keep Alive response from server. Ignore it. + // CRLF Keep Alive request from server, reply. + if (data === '\r\n\r\n') { + logger.debug('received message with double-CRLF Keep Alive request'); + + try { + // Reply with single CRLF. + this.socket.send('\r\n'); + } catch (error) { + logger.warn("error sending Keep Alive response: ".concat(error)); + } + + return; + } // CRLF Keep Alive response from server, ignore it. + + if (data === '\r\n') { logger.debug('received message with CRLF Keep Alive response'); return; @@ -24332,6 +24350,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { break; } + case 'extra_headers': + { + this._configuration.extra_headers = value; + break; + } + default: logger.warn('set() | cannot set "%s" parameter in runtime', parameter); return false; @@ -24780,7 +24804,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }; // Seal the configuration. - var writable_parameters = ['authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register']; + var writable_parameters = ['authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register', 'extra_headers']; for (var parameter in this._configuration) { if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) { @@ -28340,7 +28364,7 @@ module.exports={ "name": "jssip", "title": "JsSIP", "description": "the Javascript SIP library", - "version": "3.10.0", + "version": "3.10.1", "homepage": "https://jssip.net", "contributors": [ "José Luis Millán (https://github.com/jmillan)", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 3adeadac5..265e528bd 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -1,9 +1,9 @@ /* - * JsSIP v3.10.0 + * JsSIP v3.10.1 * the Javascript SIP library - * Copyright: 2012-2022 + * Copyright: 2012-2023 * 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=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);n0)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},extra_headers:function(e){var t=[];if(Array.isArray(e)&&e.length){var n,s=r(e);try{for(s.s();!(n=s.n()).done;){var i=n.value;"string"==typeof i&&t.push(i)}}catch(e){s.e(e)}finally{s.f()}return t}}}};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":22,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:d.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 o.IncomingResponse&&(s=n.status_code<200?d.STATUS_EARLY:d.STATUS_CONFIRMED);var i=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=i.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=i.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),h.debug("new ".concat(r," dialog created with status ").concat(this._state===d.STATUS_EARLY?"EARLY":"CONFIRMED"))}return s(e,null,[{key:"C",get:function(){return d}}]),s(e,[{key:"isTerminated",value:function(){return this._status===d.STATUS_TERMINATED}},{key:"update",value:function(e,t){this._state=d.STATUS_CONFIRMED,h.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){h.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=d.STATUS_TERMINATED}},{key:"sendRequest",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=c.cloneArray(n.extraHeaders),s=c.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new a(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===l.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===l.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=c.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===l.CANCEL||e===l.ACK?this._local_seqnum:this._local_seqnum+=1;return new o.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===l.INVITE||e.method===l.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!==u.C.STATUS_ACCEPTED&&e.server_transaction.state!==u.C.STATUS_COMPLETED&&e.server_transaction.state!==u.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===u.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===l.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===u.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,"./Logger":9,"./SIPMessage":21,"./Transactions":24,"./Utils":28}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){t._dialog.isTerminated()||(t._reattempt=!0,t.send())},1e3)):e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e)}},{key:"request",get:function(){return this._request}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RequestSender":20,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return o.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return o.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return o.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return o.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop)if(t.qop.indexOf("auth-int")>-1)this._qop="auth-int";else{if(!(t.qop.indexOf("auth")>-1))return o.warn('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=l||i.createRandomToken(12),this._nc+=1;var u,a,c=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-c.length)+c,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=i.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(a))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(i.calculateMD5(s||"")),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(a))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=null [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(a))),o.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Logger":9,"./Utils":28}],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 d=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}(),f=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:d,InvalidStateError:f,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:d,HEXDIG:f,WSP:_,OCTET:p,DQUOTE:m,SP:v,HTAB:g,alphanum:y,reserved:T,unreserved:C,mark:b,escaped:S,LWS:E,SWS:A,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=X())&&(r=e());null!==r;)n.push(r),null===(r=K())&&null===(r=X())&&(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:z,quoted_string_clean:Y,qdtext:$,quoted_pair:X,SIP_URI_noparams:J,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:se,password:ie,hostport:oe,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:he,IPv6address:de,h16:fe,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:Ce,method_param:be,ttl_param:Se,maddr_param:Ee,lr_param:Ae,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:ze,pchar:Ye,scheme:$e,authority:Xe,srvr:Je,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:dt,extension_code:ft,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Lt())){for(t=[],o=i,null!==(n=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;tl&&(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 d(){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 f(){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=b()),e}function b(){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 S(){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=f())&&null!==(r=f())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=e.join("")),null===e&&(i=s),e}function E(){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 A(){var e;return e=null!==(e=E())?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=A())?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=E();null!==s;)r.push(s),s=E();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],s=E();null!==s;)r.push(s),s=E();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=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null!==t&&null!==(r=A())?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=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null!==t&&null!==(r=A())?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=A())?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=A())?(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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=A())?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=A())&&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=A())?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=E()))),e}function z(){var e,t,r,s,o,l,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 Y(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 $(){var e;return null===(e=E())&&(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 X(){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 J(){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,d;return h=i,d=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=d)):(e=null,i=d),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=S())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=S())&&(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=S())&&(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=S())&&(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=d())){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=de())?(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 de(){var e,t,r,s,l,u,c,h,d,f,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=fe())?(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,d,f,_,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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=fe())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,u,c,h,d,f,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(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=fe())?(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=fe())?e=[e,t]:(e=null,i=g),null===e&&(g=i,null!==(e=fe())?("::"===n.substr(i,2)?(t="::",i+=2):(t=null,0===o&&a('"::"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=_e())?e=[e,t,r,s,l,u,c,h,d,f,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?(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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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 fe(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,t,r,s;return s=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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,d,f;return h=i,d=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=d)):(e=null,i=d)):(e=null,i=d)):(e=null,i=d),null!==e&&(f=h,jn.host_type="IPv4",e=n.substring(i,f)),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=be())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ae())&&(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 be(){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 Se(){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=An())?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 Ee(){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 Ae(){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=S()),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=S()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());else e=null;return e}function xe(){var e,t;for(e=[],null===(t=Pe())&&null===(t=C())&&(t=S());null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());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=$e())?(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=Xe())&&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=S()),e}function Ve(){var e;return null===(e=C())&&null===(e=S())&&(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=Ye();null!==t;)e.push(t),t=Ye();if(null!==e){for(t=[],u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=ze())?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=ze())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function ze(){var e,t;for(e=[],t=Ye();null!==t;)e.push(t),t=Ye();return e}function Ye(){var e;return null===(e=C())&&null===(e=S())&&(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 $e(){var e,t,r,s,l,u;if(s=i,l=i,null!==(e=d())){for(t=[],null===(r=d())&&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=d())&&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 Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){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=S())&&(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=S())&&(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,d,f;if(c=i,d=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=d)}else e=null,i=d;else e=null,i=d}else e=null,i=d;else e=null,i=d;return null!==e&&(f=c,e=void(jn.sip_version=n.substring(i,f))),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=dt())&&null!==(r=v())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function dt(){var e,t,n;return t=i,null!==(e=ft())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function ft(){var e,t,n,r;return r=i,null!==(e=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=S())&&null===(t=O())&&null===(t=k())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=S())&&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=J())&&(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=E())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=E())&&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=Y()),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=St()),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=bt())?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 bt(){var e,t,r,s,l,u,c,d,f;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&a('"0"')),null!==e?(d=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=d),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=c)):(e=null,i=c),null!==e&&(f=u,e=parseFloat(n.substring(i,f))),null===e&&(i=u),e}function St(){var e,t,n,r,s,o,l,u;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],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 Et(){var e;return null===(e=N())&&null===(e=le())&&(e=z()),e}function At(){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=St()),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=z()),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=St()),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=E()))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=E()))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=z()),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=zt())&&null===(e=$t())&&null===(e=Jt())&&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=Y())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function zt(){var e,t,r,s,l,u,c,h,d;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=Yt())){if(l=[],d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=Yt())?u=[u,c]:(u=null,i=d);null!==u;){if(l.push(u),d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;null!==u&&null!==(c=Yt())?u=[u,c]:(u=null,i=d)}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 Yt(){var e;return null===(e=Le())&&(e=je()),e}function $t(){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=Xt())?e=[e,t,r]:(e=null,i=s),e}function Xt(){var e,t,n;return t=i,null!==(e=Y())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Jt(){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=Y())?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,d,f;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(d=i,null!==(s=tn())){for(l=[],f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==u;)l.push(u),f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==l?s=[s,l]:(s=null,i=d)}else s=null,i=d;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=St())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=St())?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=St()),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=St())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=St())?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=St()))),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=St()),e}function hn(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=bn())){for(r=[],u=i,null!==(s=G())&&null!==(o=dn())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=dn())?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 dn(){var e;return null===(e=fn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=St()),e}function fn(){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=An())?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=de()),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 bn(){var e,t,n,r,s;return r=i,null!==(e=Sn())?(s=i,null!==(t=W())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Sn(){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 En(){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 An(){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=St()),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=E());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=E());return e}function kn(){var e,t,r,s,l,u,c,h,d,f,_,p;return f=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!==(d=Dn())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=f,e[0],e=void(jn=n.substring(i+5,p))),null===e&&(i=f),e}function Nn(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=f())&&null!==(n=f())&&null!==(r=f())?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=St()),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=Gn2&&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=d.cloneArray(r.extraHeaders),o=d.cloneObject(r.eventHandlers),l=r.contentType||"text/plain",u={};for(var a in r.fromUserName&&(u.from_uri=new p("sip",r.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),r.fromDisplayName&&(u.from_display_name=r.fromDisplayName),o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new h.OutgoingRequest(c.MESSAGE,e,this._ua,u,i),t&&(this._request.body=t);var _=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),_.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=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.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=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.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=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.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){m.debug("MESSAGE failed"),this._close(),m.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){m.debug("MESSAGE succeeded"),this._close(),m.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./URI":27,"./Utils":28,events:31}],11:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),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":27}],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){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:{},s=e;if(void 0===e)throw new TypeError("A target is required for OPTIONS");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(s));var i=d.cloneArray(r.extraHeaders),o=d.cloneObject(r.eventHandlers),l=r.contentType||"application/sdp";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 h.OutgoingRequest(c.OPTIONS,e,this._ua,null,i),t&&(this._request.body=t);var a=new f(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newOptions("local",this._request),a.send()}},{key:"init_incoming",value:function(e){this._request=e,this._newOptions("remote",e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:"accept",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,r,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=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){p.debug("OPTIONS failed"),this._close(),p.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){p.debug("OPTIONS succeeded"),this._close(),p.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28,events:31}],13:[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=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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;w.debug("connect()");var r=e,s=v.cloneObject(t.eventHandlers),i=v.cloneArray(t.extraHeaders),o=v.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=v.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 p.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new p.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=v.newTag();var d=t.anonymous||!1,f={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:d,outbound:!0}),d?(f.from_display_name="Anonymous",f.from_uri=new R("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(f.from_uri=new R("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(f.from_display_name=t.fromDisplayName),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 y.InitialOutgoingInviteRequest(e,this._ua,f,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;w.debug("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=v.newTag(),this._createDialog(e,"UAS",!0)?(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,_.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,_.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("answer()");var n=this._request,r=v.cloneArray(t.extraHeaders),i=v.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=v.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=v.cloneObject(t.rtcOfferConstraints),h=!1,d=!1,f=!1,m=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new p.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new p.InvalidStateError(this._status);if(this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.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||(f=!0)),"video"===C.type&&(d=!0,C.direction&&"sendrecv"!==C.direction||(m=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var b,S=s(o.getAudioTracks());try{for(S.s();!(b=S.n()).done;){var E=b.value;o.removeTrack(E)}}catch(e){S.e(e)}finally{S.f()}}if(o&&!1===i.video){var A,R=s(o.getVideoTracks());try{for(R.s();!(A=R.n()).done;){var O=A.value;o.removeTrack(O)}}catch(e){R.e(e)}finally{R.f()}}o||void 0!==i.audio||(i.audio=f),o||void 0!==i.video||(i.video=m),o||h||c.offerToReceiveAudio||(i.audio=!1),o||d||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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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};w.debug('emit "sdp"'),e.emit("sdp",t);var r=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed("system",null,_.causes.WEBRTC_ERROR),w.warn('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,_.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&w.warn(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]:{};w.debug("terminate()");var n,r=t.cause||_.causes.BYE,s=v.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new p.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(w.debug("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||_.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,_.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(w.debug("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,_.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(w.debug("terminating session"),l=t.reason_phrase||_.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!==m.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===_.ACK&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===m.C.STATUS_TERMINATED&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(_.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]:{};w.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||_.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&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.InvalidStateError(this._status);if(i!==_.DTMF_TRANSPORT.INFO&&i!==_.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&&!v.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rb.C.MAX_DURATION?(w.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(b.C.MAX_DURATION," milliseconds")),r=b.C.MAX_DURATION):r=Math.abs(r):r=b.C.DEFAULT_DURATION,t.duration=r,s&&!v.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new b(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(w.debug("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.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};w.debug("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};w.debug("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(w.debug("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:_.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(w.debug("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:_.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;w.debug("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:_.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;w.debug("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 w.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(w.debug("receiveRequest()"),e.method===_.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,_.causes.CANCELED));else switch(e.method){case _.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:_.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",n);var r=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed("remote",e)}).catch(function(e){t.terminate({cause:_.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case _.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,_.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,_.causes.BYE)):e.reply(403,"Wrong Status");break;case _.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case _.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 b(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case _.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case _.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case _.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){w.warn("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.CONNECTION_ERROR,cause:_.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){w.warn("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:_.causes.REQUEST_TIMEOUT,cause:_.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){w.warn("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.DIALOG_ERROR,cause:_.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){w.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){w.debug("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(w.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(w.debug("_isReadyToReOffer() | session not established yet"),!1):(w.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(w.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(w.debug("close() | closing local MediaStream"),v.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){w.warn("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=g.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),ng.T2&&(n=g.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&&(w.debug("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(_.BYE),e._ended("remote",null,_.causes.NO_ACK))},g.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:_.causes.RTP_TIMEOUT,status_code:408,reason_phrase:_.causes.RTP_TIMEOUT})}),w.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(w.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return w.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return w.warn('emit "peerconnection:createanswerfailed" [error:%o]',e),n.emit("peerconnection:createanswerfailed",e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,w.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){var s=t&&t.iceRestart;if("complete"===r.iceGatheringState&&!s||"gathering"===r.iceGatheringState&&n._iceReady){n._rtcReady=!0;var i={originator:"local",type:e,sdp:r.localDescription.sdp};return w.debug('emit "sdp"'),n.emit("sdp",i),Promise.resolve(i.sdp)}return new Promise(function(t){var s,i,o=!1;n._iceReady=!1;var l=function(){r.removeEventListener("icecandidate",s),r.removeEventListener("icegatheringstatechange",i),o=!0,n._rtcReady=!0,n._iceReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};w.debug('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()})})})}},{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 T(this,e,t,T.C.STATUS_EARLY)).error?(w.debug(o.error),this._failed("remote",e,_.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 T(this,e,t);return l.error?(w.debug(l.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;w.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("_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};w.debug('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.warn('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.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){w.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(w.debug("receiveRefer()"),!e.refer_to)return w.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==_.SIP)return w.debug("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);w.debug('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=v.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(w.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(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;w.debug("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(){w.debug("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new C(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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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,_.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,w.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&w.warn(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;w.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(w.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(_.ACK);var n=new T(this,e,"UAC");return void 0!==n.error?void w.debug(n.error):(this.sendRequest(_.ACK),void this.sendRequest(_.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){w.debug("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};w.debug('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.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=I.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,_.causes.MISSING_SDP),this._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};w.debug('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,_.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(_.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=v.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]:{};w.debug("sendReinvite()");var n=v.cloneArray(t.extraHeaders),r=v.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)};w.debug('emit "sdp"'),e.emit("sdp",s),e.sendRequest(_.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(_.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};w.debug('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.warn('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]:{};w.debug("sendUpdate()");var n=v.cloneArray(t.extraHeaders),r=v.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};w.debug('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.warn('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)};w.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(_.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(_.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){w.debug("acceptAndTerminate()");var r=[];t&&(n=n||_.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(_.ACK),this.sendRequest(_.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=d.parse(e),this._localHold&&!this._remoteHold){w.debug("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){w.debug("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){w.debug("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 d.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>=_.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>=_.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&&e._isReadyToReOffer()&&(w.debug("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===_.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w.warn("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:_.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){w.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){w.debug("session connecting"),w.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){w.debug("session progress"),w.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){w.debug("session accepted"),this._start_time=new Date,w.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){w.debug("session confirmed"),this._is_confirmed=!0,w.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){w.debug("session ended"),this._end_time=new Date,this._close(),w.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){w.debug("session failed"),w.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),w.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){w.debug("session onhold"),this._setLocalMediaStatus(),w.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){w.debug("session onunhold"),this._setLocalMediaStatus(),w.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onmute"),this._setLocalMediaStatus(),w.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onunmute"),this._setLocalMediaStatus(),w.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return I}},{key:"causes",get:function(){return _.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,"./Logger":9,"./RTCSession/DTMF":15,"./RTCSession/Info":16,"./RTCSession/ReferNotifier":17,"./RTCSession/ReferSubscriber":18,"./RequestSender":20,"./SIPMessage":21,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,events:31,"sdp-transform":37}],15:[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;n1&&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 h.InvalidStateError(this._session.status);var r=d.cloneArray(n.extraHeaders);if(this.eventHandlers=d.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(c.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=_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):f.debug("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),a}(),t.exports.C=_},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":28,events:31}],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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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),d}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,events:31}],17:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(i.NOTIFY,{extraHeaders:["Event: ".concat(l.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(l.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"../Constants":2,"../Logger":9}],18:[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;n1&&void 0!==arguments[1]?arguments[1]:{};f.debug("sendRefer()");var r=d.cloneArray(n.extraHeaders),s=d.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):"",">");if(r.push(l),!r.some(function(e){return e.toLowerCase().startsWith("referred-by:")})){var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u)}r.push("Contact: ".concat(this._session.contact));var a=this._session.sendRequest(c.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,c.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,c.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,c.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,c.causes.DIALOG_ERROR)}}});this._id=a.cseq}},{key:"receiveNotify",value:function(e){if(f.debug("receiveNotify()"),e.body){var t=h.parse(e.body.trim().split("\r\n",1)[0],"Status_Line");if(-1!==t)switch(!0){case/^100$/.test(t.status_code):this.emit("trying",{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit("progress",{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit("accepted",{request:e,status_line:t});break;default:this.emit("failed",{request:e,status_line:t})}else f.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){f.debug("REFER succeeded"),f.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){f.debug("REFER failed"),f.debug('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),a}()},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":28,events:31}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,s;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)a.debug("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var n=new l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new u(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,o.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")){a.debug("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a.debug("no Contact header pointing to us, response ignored");break}var s=r.getParam("expires");!s&&t.hasHeader("expires")&&(s=t.getHeader("expires")),s||(s=e._expires),(s=Number(s))<10&&(s=10);var l=s>64?1e3*s/2+Math.floor(1e3*(s/2-32)*Math.random()):1e3*s-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,o.causes.SIP_FAILURE_CODE));break;default:var u=i.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new u(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,o.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=i.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else a.debug("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}},{key:"_unregistered",value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:"registered",get:function(){return this._registered}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28}],20:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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")),this.setHeader("via",""),this.setHeader("max-forwards",p.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 v(l,a,u),this.setHeader("to",this.to.toString());var h,d=s.from_uri||r.configuration.uri,f={tag:s.from_tag||m.newTag()};h=void 0!==s.from_display_name?s.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new v(d,h,f),this.setHeader("from",this.from.toString());var _=s.call_id||r.configuration.jssip_id+m.createRandomToken(15);this.call_id=_,this.setHeader("call-id",_);var g=s.cseq||Math.floor(1e4*Math.random());this.cseq=g,this.setHeader("cseq","".concat(g," ").concat(t))}return d(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(e=m.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=g.parse(r,e.replace(/-/g,"_"));return-1===s?(this.headers[e].splice(t,1),void y.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=s,s)}y.debug('not so many "'.concat(e,'" headers present'))}else y.debug('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[m.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=f.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),e}(),S=function(e){s(n,b);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 d(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||p.REASON_PHRASE[e]||"",n=m.cloneArray(n),this.ua.configuration.extra_headers&&(n=n.concat(this.ua.configuration.extra_headers));var a="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===p.INVITE&&e>100&&e<=200){var c,h=u(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var d=c.value;a+="Record-Route: ".concat(d,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var f,_=u(this.getHeaders("via"));try{for(_.s();!(f=_.n()).done;){var v=f.value;a+="Via: ".concat(v,"\r\n")}}catch(e){_.e(e)}finally{_.f()}!this.to_tag&&e>100?l+=";tag=".concat(m.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 p.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 p.UPDATE:this.ua.configuration.session_timers&&o.push("timer"),r&&o.push("ice"),o.push("replaces")}if(o.push("outbound"),this.method===p.OPTIONS?(a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(o,"\r\n"),r){var C=m.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||p.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");if(!this.to_tag&&e>100?l+=";tag=".concat(m.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"),this.ua.configuration.extra_headers){var a,c=u(this.ua.configuration.extra_headers);try{for(c.s();!(a=c.n()).done;){var h=a.value;s+="".concat(h.trim(),"\r\n")}}catch(e){c.e(e)}finally{c.f()}}s+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(s)}}]),n}(),E=function(e){s(n,b);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:T,InitialOutgoingInviteRequest:C,IncomingRequest:S,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":28,"sdp-transform":37}],22:[function(e,t,n){"use strict";var r=e("./Logger"),s=e("./Utils"),i=e("./Grammar"),o=new r("Socket");n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return o.warn("undefined JsSIP.Socket instance"),!1;try{if(!s.isString(e.url))throw o.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!s.isString(e.via_transport))throw o.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===i.parse(e.sip_uri,"SIP_URI"))throw o.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!s.isFunction(e[t]))throw o.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch(e){return!1}return!0}},{"./Grammar":7,"./Logger":9,"./Utils":28}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case b.STATUS_CALLING:this.stateChanged(b.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},m.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return b}}]),n}(),A=function(e){l(n,d);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(){y.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return b}}]),n}(),R=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){T.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,T.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case b.STATUS_TRYING:this.stateChanged(b.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case b.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 b.STATUS_TRYING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){s.timer_J()},m.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case b.STATUS_COMPLETED:}}},{key:"C",get:function(){return b}}]),n}(),w=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){C.debug("Timer H expired for transaction ".concat(this.id)),this.state===b.STATUS_COMPLETED&&C.debug("ACK not received, dialog will be terminated"),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){C.debug("Timer L expired for transaction ".concat(this.id)),this.state===b.STATUS_ACCEPTED&&(this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,C.debug("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(b.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 b.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===b.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){s.resend_provisional()},m.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){s.timer_L()},m.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case b.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case b.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(b.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},m.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:"C",get:function(){return b}}]),n}();t.exports={C:b,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:R,InviteServerTransaction:w,checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case _.INVITE:if(n=r.ist[t.via_branch]){switch(n.state){case b.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case b.STATUS_ACCEPTED:}return!0}break;case _.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===b.STATUS_ACCEPTED)return!1;if(n.state===b.STATUS_COMPLETED)return n.state=b.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},m.TIMER_I),!0;break;case _.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==b.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case b.STATUS_TRYING:break;case b.STATUS_PROCEEDING:case b.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Timers":23,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),l.debug("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){l.warn("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!i.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,s;return t=e,(n=[{key:"connect",value:function(){l.debug("connect()"),this.isConnected()?l.debug("Transport is already connected"):this.isConnecting()?l.debug("Transport is connecting"):(this.close_requested=!1,this.status=u.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.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.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.debug("send()"),!this.isConnected())return l.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return l.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),l.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void l.debug("received binary message failed to be converted into string, message discarded")}l.debug("received binary message:\n\n".concat(e,"\n"))}else l.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else l.debug("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}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./Socket":22}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];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 R.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R.debug("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R.debug("- ".concat(i,": NOT SHOWN"));break;default:R.debug("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}},{key:"C",get:function(){return w}},{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,"./Logger":9,"./Message":10,"./Options":12,"./Parser":13,"./RTCSession":14,"./Registrator":19,"./SIPMessage":21,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,events:31}],27:[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);n4&&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":28}],28:[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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,d,f,_,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>>29,i}(e=function(e){for(var t="",n=0;n127&&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;a1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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);n1)return d.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=h.str_utf8_length(i.body),t=i.getHeader("content-length");if(e0&&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 d(){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;t1&&(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=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=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):[]}},{}],32:[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":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t=0;for(let n=0;n{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{r[e]=t[e]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}},{ms:34}],34:[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))}},{}],35:[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,d=-1;function f(){h&&a&&(h=!1,a.length?c=a.concat(c):d=-1,c.length&&_())}function _(){if(!h){var e=u(f);h=!0;for(var t=c.length;t;){for(a=c,c=[];++d1)for(var n=1;n1&&(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=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":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.10.0",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.19.6","@babel/preset-env":"^7.19.4","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},scripts:{lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"}}},{}]},{},[8])(8)}); \ No newline at end of file +!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=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);n0)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},extra_headers:function(e){var t=[];if(Array.isArray(e)&&e.length){var n,s=r(e);try{for(s.s();!(n=s.n()).done;){var i=n.value;"string"==typeof i&&t.push(i)}}catch(e){s.e(e)}finally{s.f()}return t}}}};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":22,"./URI":27,"./Utils":28}],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:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":40}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:d.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 o.IncomingResponse&&(s=n.status_code<200?d.STATUS_EARLY:d.STATUS_CONFIRMED);var i=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=i.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=i.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),h.debug("new ".concat(r," dialog created with status ").concat(this._state===d.STATUS_EARLY?"EARLY":"CONFIRMED"))}return s(e,null,[{key:"C",get:function(){return d}}]),s(e,[{key:"isTerminated",value:function(){return this._status===d.STATUS_TERMINATED}},{key:"update",value:function(e,t){this._state=d.STATUS_CONFIRMED,h.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){h.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=d.STATUS_TERMINATED}},{key:"sendRequest",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=c.cloneArray(n.extraHeaders),s=c.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new a(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===l.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===l.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=c.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===l.CANCEL||e===l.ACK?this._local_seqnum:this._local_seqnum+=1;return new o.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===l.INVITE||e.method===l.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!==u.C.STATUS_ACCEPTED&&e.server_transaction.state!==u.C.STATUS_COMPLETED&&e.server_transaction.state!==u.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===u.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===l.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===u.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,"./Logger":9,"./SIPMessage":21,"./Transactions":24,"./Utils":28}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){t._dialog.isTerminated()||(t._reattempt=!0,t.send())},1e3)):e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e)}},{key:"request",get:function(){return this._request}}])&&r(t.prototype,n),u&&r(t,u),e}()},{"../Constants":2,"../RequestSender":20,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&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.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return o.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return o.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return o.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return o.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop)if(t.qop.indexOf("auth-int")>-1)this._qop="auth-int";else{if(!(t.qop.indexOf("auth")>-1))return o.warn('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=l||i.createRandomToken(12),this._nc+=1;var u,a,c=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-c.length)+c,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=i.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(a))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(i.calculateMD5(s||"")),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(a))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=null [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(a))),o.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Logger":9,"./Utils":28}],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 d=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}(),f=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:d,InvalidStateError:f,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:d,HEXDIG:f,WSP:_,OCTET:p,DQUOTE:m,SP:v,HTAB:g,alphanum:y,reserved:T,unreserved:C,mark:b,escaped:S,LWS:E,SWS:A,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:x,STAR:D,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=X())&&(r=e());null!==r;)n.push(r),null===(r=K())&&null===(r=X())&&(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:z,quoted_string_clean:Y,qdtext:$,quoted_pair:X,SIP_URI_noparams:J,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:se,password:ie,hostport:oe,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:he,IPv6address:de,h16:fe,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:Ce,method_param:be,ttl_param:Se,maddr_param:Ee,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:ke,headers:Ne,header:Ue,hname:xe,hvalue:De,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:ze,pchar:Ye,scheme:$e,authority:Xe,srvr:Je,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:dt,extension_code:ft,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Lt())){for(t=[],o=i,null!==(n=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=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=D()))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;tl&&(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 d(){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 f(){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=b()),e}function b(){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 S(){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=f())&&null!==(r=f())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=e.join("")),null===e&&(i=s),e}function E(){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 A(){var e;return e=null!==(e=E())?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=A())?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=E();null!==s;)r.push(s),s=E();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],s=E();null!==s;)r.push(s),s=E();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 x(){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 D(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null!==t&&null!==(r=A())?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=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t&&null!==(r=A())?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=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=A())?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=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null!==t&&null!==(r=A())?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=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null!==t&&null!==(r=A())?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=A())?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=A())?(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=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null!==t&&null!==(r=A())?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=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=A())?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=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=A())?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=A())&&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=A())?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=E()))),e}function z(){var e,t,r,s,o,l,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 Y(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());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 $(){var e;return null===(e=E())&&(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 X(){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 J(){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,d;return h=i,d=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=d)):(e=null,i=d),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=S())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=S())&&(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=S())&&(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=S())&&(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=d())){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=de())?(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 de(){var e,t,r,s,l,u,c,h,d,f,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=fe())?(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,d,f,_,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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=fe())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,u,c,h,d,f,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(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=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(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=fe())?(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=fe())?e=[e,t]:(e=null,i=g),null===e&&(g=i,null!==(e=fe())?("::"===n.substr(i,2)?(t="::",i+=2):(t=null,0===o&&a('"::"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=_e())?e=[e,t,r,s,l,u,c,h,d,f,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?(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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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=fe())?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 fe(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,t,r,s;return s=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?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,d,f;return h=i,d=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=d)):(e=null,i=d)):(e=null,i=d)):(e=null,i=d),null!==e&&(f=h,jn.host_type="IPv4",e=n.substring(i,f)),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=be())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ae())&&(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 be(){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 Se(){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=An())?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 Ee(){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 Ae(){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=S()),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=xe())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=De())?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 xe(){var e,t;if(null===(t=Pe())&&null===(t=C())&&(t=S()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());else e=null;return e}function De(){var e,t;for(e=[],null===(t=Pe())&&null===(t=C())&&(t=S());null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());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=$e())?(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=Xe())&&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=S()),e}function Ve(){var e;return null===(e=C())&&null===(e=S())&&(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=Ye();null!==t;)e.push(t),t=Ye();if(null!==e){for(t=[],u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=ze())?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=ze())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function ze(){var e,t;for(e=[],t=Ye();null!==t;)e.push(t),t=Ye();return e}function Ye(){var e;return null===(e=C())&&null===(e=S())&&(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 $e(){var e,t,r,s,l,u;if(s=i,l=i,null!==(e=d())){for(t=[],null===(r=d())&&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=d())&&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 Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){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=S())&&(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=S())&&(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,d,f;if(c=i,d=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=d)}else e=null,i=d;else e=null,i=d}else e=null,i=d;else e=null,i=d;return null!==e&&(f=c,e=void(jn.sip_version=n.substring(i,f))),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=dt())&&null!==(r=v())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function dt(){var e,t,n;return t=i,null!==(e=ft())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function ft(){var e,t,n,r;return r=i,null!==(e=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=S())&&null===(t=O())&&null===(t=k())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=S())&&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=J())&&(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=E())&&null!==(r=N())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=E())&&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=Y()),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=St()),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=bt())?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 bt(){var e,t,r,s,l,u,c,d,f;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&a('"0"')),null!==e?(d=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=d),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=c)):(e=null,i=c),null!==e&&(f=u,e=parseFloat(n.substring(i,f))),null===e&&(i=u),e}function St(){var e,t,n,r,s,o,l,u;return r=i,s=i,null!==(e=N())?(o=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],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 Et(){var e;return null===(e=N())&&null===(e=le())&&(e=z()),e}function At(){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=St()),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=Dt())){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=xt()),e}function xt(){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 Dt(){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=z()),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=St()),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=E()))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=E()))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=z()),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=zt())&&null===(e=$t())&&null===(e=Jt())&&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=Y())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function zt(){var e,t,r,s,l,u,c,h,d;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=Yt())){if(l=[],d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=Yt())?u=[u,c]:(u=null,i=d);null!==u;){if(l.push(u),d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;null!==u&&null!==(c=Yt())?u=[u,c]:(u=null,i=d)}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 Yt(){var e;return null===(e=Le())&&(e=je()),e}function $t(){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=Xt())?e=[e,t,r]:(e=null,i=s),e}function Xt(){var e,t,n;return t=i,null!==(e=Y())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Jt(){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=Y())?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,d,f;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(d=i,null!==(s=tn())){for(l=[],f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==u;)l.push(u),f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==l?s=[s,l]:(s=null,i=d)}else s=null,i=d;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=St())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=St())?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=St()),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=St())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=St())?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=St()))),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=St()),e}function hn(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=bn())){for(r=[],u=i,null!==(s=G())&&null!==(o=dn())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=dn())?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 dn(){var e;return null===(e=fn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=St()),e}function fn(){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=An())?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=de()),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 bn(){var e,t,n,r,s;return r=i,null!==(e=Sn())?(s=i,null!==(t=W())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Sn(){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 En(){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 An(){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=St()),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=E());null!==t;)e.push(t),null===(t=I())&&null===(t=k())&&(t=E());return e}function kn(){var e,t,r,s,l,u,c,h,d,f,_,p;return f=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!==(d=xn())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=f,e[0],e=void(jn=n.substring(i+5,p))),null===e&&(i=f),e}function Nn(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=f())&&null!==(n=f())&&null!==(r=f())?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 xn(){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 Dn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=x())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=x())?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=St()),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=Gn2&&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=d.cloneArray(r.extraHeaders),o=d.cloneObject(r.eventHandlers),l=r.contentType||"text/plain",u={};for(var a in r.fromUserName&&(u.from_uri=new p("sip",r.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),r.fromDisplayName&&(u.from_display_name=r.fromDisplayName),o)Object.prototype.hasOwnProperty.call(o,a)&&this.on(a,o[a]);i.push("Content-Type: ".concat(l)),this._request=new h.OutgoingRequest(c.MESSAGE,e,this._ua,u,i),t&&(this._request.body=t);var _=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),_.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=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.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=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.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=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.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){m.debug("MESSAGE failed"),this._close(),m.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){m.debug("MESSAGE succeeded"),this._close(),m.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./URI":27,"./Utils":28,events:31}],11:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),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":27}],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){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:{},s=e;if(void 0===e)throw new TypeError("A target is required for OPTIONS");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(s));var i=d.cloneArray(r.extraHeaders),o=d.cloneObject(r.eventHandlers),l=r.contentType||"application/sdp";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 h.OutgoingRequest(c.OPTIONS,e,this._ua,null,i),t&&(this._request.body=t);var a=new f(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newOptions("local",this._request),a.send()}},{key:"init_incoming",value:function(e){this._request=e,this._newOptions("remote",e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:"accept",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,r,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=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){p.debug("OPTIONS failed"),this._close(),p.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){p.debug("OPTIONS succeeded"),this._close(),p.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28,events:31}],13:[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=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);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;w.debug("connect()");var r=e,s=v.cloneObject(t.eventHandlers),i=v.cloneArray(t.extraHeaders),o=v.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=v.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 p.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new p.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=v.newTag();var d=t.anonymous||!1,f={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:d,outbound:!0}),d?(f.from_display_name="Anonymous",f.from_uri=new R("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(f.from_uri=new R("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(f.from_display_name=t.fromDisplayName),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 y.InitialOutgoingInviteRequest(e,this._ua,f,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;w.debug("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(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=v.newTag(),this._createDialog(e,"UAS",!0)?(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,_.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,_.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&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("answer()");var n=this._request,r=v.cloneArray(t.extraHeaders),i=v.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=v.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=v.cloneObject(t.rtcOfferConstraints),h=!1,d=!1,f=!1,m=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new p.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new p.InvalidStateError(this._status);if(this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.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||(f=!0)),"video"===C.type&&(d=!0,C.direction&&"sendrecv"!==C.direction||(m=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var b,S=s(o.getAudioTracks());try{for(S.s();!(b=S.n()).done;){var E=b.value;o.removeTrack(E)}}catch(e){S.e(e)}finally{S.f()}}if(o&&!1===i.video){var A,R=s(o.getVideoTracks());try{for(R.s();!(A=R.n()).done;){var O=A.value;o.removeTrack(O)}}catch(e){R.e(e)}finally{R.f()}}o||void 0!==i.audio||(i.audio=f),o||void 0!==i.video||(i.video=m),o||h||c.offerToReceiveAudio||(i.audio=!1),o||d||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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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};w.debug('emit "sdp"'),e.emit("sdp",t);var r=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed("system",null,_.causes.WEBRTC_ERROR),w.warn('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,_.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&w.warn(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]:{};w.debug("terminate()");var n,r=t.cause||_.causes.BYE,s=v.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new p.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(w.debug("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||_.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,_.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(w.debug("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,_.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(w.debug("terminating session"),l=t.reason_phrase||_.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!==m.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===_.ACK&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===m.C.STATUS_TERMINATED&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(_.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]:{};w.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||_.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&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.InvalidStateError(this._status);if(i!==_.DTMF_TRANSPORT.INFO&&i!==_.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&&!v.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rb.C.MAX_DURATION?(w.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(b.C.MAX_DURATION," milliseconds")),r=b.C.MAX_DURATION):r=Math.abs(r):r=b.C.DEFAULT_DURATION,t.duration=r,s&&!v.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new b(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(w.debug("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_1XX_RECEIVED)throw new p.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};w.debug("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};w.debug("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(w.debug("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:_.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(w.debug("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:_.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;w.debug("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:_.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;w.debug("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 w.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(w.debug("receiveRequest()"),e.method===_.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,_.causes.CANCELED));else switch(e.method){case _.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:_.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",n);var r=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed("remote",e)}).catch(function(e){t.terminate({cause:_.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case _.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,_.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,_.causes.BYE)):e.reply(403,"Wrong Status");break;case _.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case _.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 b(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case _.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case _.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case _.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){w.warn("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.CONNECTION_ERROR,cause:_.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){w.warn("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:_.causes.REQUEST_TIMEOUT,cause:_.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){w.warn("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.DIALOG_ERROR,cause:_.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){w.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){w.debug("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(w.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(w.debug("_isReadyToReOffer() | session not established yet"),!1):(w.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(w.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(w.debug("close() | closing local MediaStream"),v.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){w.warn("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=g.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),ng.T2&&(n=g.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&&(w.debug("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(_.BYE),e._ended("remote",null,_.causes.NO_ACK))},g.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:_.causes.RTP_TIMEOUT,status_code:408,reason_phrase:_.causes.RTP_TIMEOUT})}),w.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(w.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return w.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return w.warn('emit "peerconnection:createanswerfailed" [error:%o]',e),n.emit("peerconnection:createanswerfailed",e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,w.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){var s=t&&t.iceRestart;if("complete"===r.iceGatheringState&&!s||"gathering"===r.iceGatheringState&&n._iceReady){n._rtcReady=!0;var i={originator:"local",type:e,sdp:r.localDescription.sdp};return w.debug('emit "sdp"'),n.emit("sdp",i),Promise.resolve(i.sdp)}return new Promise(function(t){var s,i,o=!1;n._iceReady=!1;var l=function(){if(!o){r.removeEventListener("icecandidate",s),r.removeEventListener("icegatheringstatechange",i),o=!0,n._rtcReady=!0,n._iceReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};w.debug('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}):l()}),r.addEventListener("icegatheringstatechange",i=function(){"complete"===r.iceGatheringState&&l()})})})}},{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 T(this,e,t,T.C.STATUS_EARLY)).error?(w.debug(o.error),this._failed("remote",e,_.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 T(this,e,t);return l.error?(w.debug(l.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;w.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.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 w.debug("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.warn(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;w.debug("_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};w.debug('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.warn('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.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){w.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(w.debug("receiveRefer()"),!e.refer_to)return w.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==_.SIP)return w.debug("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);w.debug('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=v.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(w.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(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;w.debug("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(){w.debug("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new C(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,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('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,_.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,w.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&w.warn(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;w.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(w.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(_.ACK);var n=new T(this,e,"UAC");return void 0!==n.error?void w.debug(n.error):(this.sendRequest(_.ACK),void this.sendRequest(_.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){w.debug("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};w.debug('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.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=I.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,_.causes.MISSING_SDP),this._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};w.debug('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,_.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(_.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=v.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]:{};w.debug("sendReinvite()");var n=v.cloneArray(t.extraHeaders),r=v.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)};w.debug('emit "sdp"'),e.emit("sdp",s),e.sendRequest(_.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(_.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};w.debug('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.warn('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]:{};w.debug("sendUpdate()");var n=v.cloneArray(t.extraHeaders),r=v.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};w.debug('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.warn('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)};w.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(_.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(_.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){w.debug("acceptAndTerminate()");var r=[];t&&(n=n||_.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(_.ACK),this.sendRequest(_.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=d.parse(e),this._localHold&&!this._remoteHold){w.debug("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){w.debug("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){w.debug("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 d.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>=_.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>=_.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&&e._isReadyToReOffer()&&(w.debug("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===_.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w.warn("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:_.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){w.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){w.debug("session connecting"),w.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){w.debug("session progress"),w.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){w.debug("session accepted"),this._start_time=new Date,w.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){w.debug("session confirmed"),this._is_confirmed=!0,w.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){w.debug("session ended"),this._end_time=new Date,this._close(),w.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){w.debug("session failed"),w.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),w.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){w.debug("session onhold"),this._setLocalMediaStatus(),w.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){w.debug("session onunhold"),this._setLocalMediaStatus(),w.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onmute"),this._setLocalMediaStatus(),w.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onunmute"),this._setLocalMediaStatus(),w.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return I}},{key:"causes",get:function(){return _.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,"./Logger":9,"./RTCSession/DTMF":15,"./RTCSession/Info":16,"./RTCSession/ReferNotifier":17,"./RTCSession/ReferSubscriber":18,"./RequestSender":20,"./SIPMessage":21,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,events:31,"sdp-transform":37}],15:[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;n1&&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 h.InvalidStateError(this._session.status);var r=d.cloneArray(n.extraHeaders);if(this.eventHandlers=d.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(c.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=_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):f.debug("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),a}(),t.exports.C=_},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":28,events:31}],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;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);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),d}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,events:31}],17:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(i.NOTIFY,{extraHeaders:["Event: ".concat(l.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(l.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"../Constants":2,"../Logger":9}],18:[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;n1&&void 0!==arguments[1]?arguments[1]:{};f.debug("sendRefer()");var r=d.cloneArray(n.extraHeaders),s=d.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):"",">");if(r.push(l),!r.some(function(e){return e.toLowerCase().startsWith("referred-by:")})){var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u)}r.push("Contact: ".concat(this._session.contact));var a=this._session.sendRequest(c.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,c.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,c.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,c.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,c.causes.DIALOG_ERROR)}}});this._id=a.cseq}},{key:"receiveNotify",value:function(e){if(f.debug("receiveNotify()"),e.body){var t=h.parse(e.body.trim().split("\r\n",1)[0],"Status_Line");if(-1!==t)switch(!0){case/^100$/.test(t.status_code):this.emit("trying",{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit("progress",{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit("accepted",{request:e,status_line:t});break;default:this.emit("failed",{request:e,status_line:t})}else f.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){f.debug("REFER succeeded"),f.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){f.debug("REFER failed"),f.debug('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),a}()},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":28,events:31}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}var t,n,s;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)a.debug("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var n=new l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new u(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,o.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")){a.debug("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]),r=n.find(function(t){return e._sipInstance===t.getParam("+sip.instance")&&e._reg_id===parseInt(t.getParam("reg-id"))});if(r||(r=n.find(function(t){return t.uri.user===e._ua.contact.uri.user})),!r){a.debug("no Contact header pointing to us, response ignored");break}var s=r.getParam("expires");!s&&t.hasHeader("expires")&&(s=t.getHeader("expires")),s||(s=e._expires),(s=Number(s))<10&&(s=10);var l=s>64?1e3*s/2+Math.floor(1e3*(s/2-32)*Math.random()):1e3*s-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},l),r.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,o.causes.SIP_FAILURE_CODE));break;default:var u=i.sipErrorCause(t.status_code);e._registrationFailure(t,u)}}});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 l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new u(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,o.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=i.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else a.debug("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}},{key:"_unregistered",value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:"registered",get:function(){return this._registered}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28}],20:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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")),this.setHeader("via",""),this.setHeader("max-forwards",p.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 v(l,a,u),this.setHeader("to",this.to.toString());var h,d=s.from_uri||r.configuration.uri,f={tag:s.from_tag||m.newTag()};h=void 0!==s.from_display_name?s.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new v(d,h,f),this.setHeader("from",this.from.toString());var _=s.call_id||r.configuration.jssip_id+m.createRandomToken(15);this.call_id=_,this.setHeader("call-id",_);var g=s.cseq||Math.floor(1e4*Math.random());this.cseq=g,this.setHeader("cseq","".concat(g," ").concat(t))}return d(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(e=m.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=g.parse(r,e.replace(/-/g,"_"));return-1===s?(this.headers[e].splice(t,1),void y.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=s,s)}y.debug('not so many "'.concat(e,'" headers present'))}else y.debug('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[m.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=f.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),e}(),S=function(e){s(n,b);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 d(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||p.REASON_PHRASE[e]||"",n=m.cloneArray(n),this.ua.configuration.extra_headers&&(n=n.concat(this.ua.configuration.extra_headers));var a="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===p.INVITE&&e>100&&e<=200){var c,h=u(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var d=c.value;a+="Record-Route: ".concat(d,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var f,_=u(this.getHeaders("via"));try{for(_.s();!(f=_.n()).done;){var v=f.value;a+="Via: ".concat(v,"\r\n")}}catch(e){_.e(e)}finally{_.f()}!this.to_tag&&e>100?l+=";tag=".concat(m.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 p.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 p.UPDATE:this.ua.configuration.session_timers&&o.push("timer"),r&&o.push("ice"),o.push("replaces")}if(o.push("outbound"),this.method===p.OPTIONS?(a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(o,"\r\n"),r){var C=m.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||p.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");if(!this.to_tag&&e>100?l+=";tag=".concat(m.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"),this.ua.configuration.extra_headers){var a,c=u(this.ua.configuration.extra_headers);try{for(c.s();!(a=c.n()).done;){var h=a.value;s+="".concat(h.trim(),"\r\n")}}catch(e){c.e(e)}finally{c.f()}}s+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(s)}}]),n}(),E=function(e){s(n,b);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:T,InitialOutgoingInviteRequest:C,IncomingRequest:S,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":28,"sdp-transform":37}],22:[function(e,t,n){"use strict";var r=e("./Logger"),s=e("./Utils"),i=e("./Grammar"),o=new r("Socket");n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return o.warn("undefined JsSIP.Socket instance"),!1;try{if(!s.isString(e.url))throw o.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!s.isString(e.via_transport))throw o.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===i.parse(e.sip_uri,"SIP_URI"))throw o.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!s.isFunction(e[t]))throw o.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch(e){return!1}return!0}},{"./Grammar":7,"./Logger":9,"./Utils":28}],23:[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}},{}],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){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case b.STATUS_CALLING:this.stateChanged(b.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},m.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return b}}]),n}(),A=function(e){l(n,d);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(){y.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return b}}]),n}(),R=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){T.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,T.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case b.STATUS_TRYING:this.stateChanged(b.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case b.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 b.STATUS_TRYING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){s.timer_J()},m.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case b.STATUS_COMPLETED:}}},{key:"C",get:function(){return b}}]),n}(),w=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.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=b.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(){C.debug("Timer H expired for transaction ".concat(this.id)),this.state===b.STATUS_COMPLETED&&C.debug("ACK not received, dialog will be terminated"),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){C.debug("Timer L expired for transaction ".concat(this.id)),this.state===b.STATUS_ACCEPTED&&(this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,C.debug("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(b.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 b.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===b.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){s.resend_provisional()},m.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){s.timer_L()},m.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case b.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case b.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(b.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},m.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:"C",get:function(){return b}}]),n}();t.exports={C:b,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:R,InviteServerTransaction:w,checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case _.INVITE:if(n=r.ist[t.via_branch]){switch(n.state){case b.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case b.STATUS_ACCEPTED:}return!0}break;case _.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===b.STATUS_ACCEPTED)return!1;if(n.state===b.STATUS_COMPLETED)return n.state=b.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},m.TIMER_I),!0;break;case _.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==b.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case b.STATUS_TRYING:break;case b.STATUS_PROCEEDING:case b.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Timers":23,events:31}],25:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),l.debug("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){l.warn("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!i.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:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,s;return t=e,(n=[{key:"connect",value:function(){l.debug("connect()"),this.isConnected()?l.debug("Transport is already connected"):this.isConnecting()?l.debug("Transport is connecting"):(this.close_requested=!1,this.status=u.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.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.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.debug("send()"),!this.isConnected())return l.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return l.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),l.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==u.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=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n\r\n"!==e)if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void l.debug("received binary message failed to be converted into string, message discarded")}l.debug("received binary message:\n\n".concat(e,"\n"))}else l.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else l.debug("received message with CRLF Keep Alive response");else{l.debug("received message with double-CRLF Keep Alive request");try{this.socket.send("\r\n")}catch(e){l.warn("error sending Keep Alive response: ".concat(e))}}}},{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./Socket":22}],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){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register","extra_headers"];for(var 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 R.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(A.settings,i))switch(i){case"uri":case"registrar_server":R.debug("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":R.debug("- ".concat(i,": NOT SHOWN"));break;default:R.debug("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}},{key:"C",get:function(){return w}},{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,"./Logger":9,"./Message":10,"./Options":12,"./Parser":13,"./RTCSession":14,"./Registrator":19,"./SIPMessage":21,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,events:31}],27:[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);n4&&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":28}],28:[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);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>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,d,f,_,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>>29,i}(e=function(e){for(var t="",n=0;n127&&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;a1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=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);n1)return d.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=h.str_utf8_length(i.body),t=i.getHeader("content-length");if(e0&&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 d(){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;t1&&(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=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=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):[]}},{}],32:[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":33,_process:35}],33:[function(e,t,n){t.exports=function(t){function n(e){let t=0;for(let n=0;n{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{r[e]=t[e]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}},{ms:34}],34:[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))}},{}],35:[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,d=-1;function f(){h&&a&&(h=!1,a.length?c=a.concat(c):d=-1,c.length&&_())}function _(){if(!h){var e=u(f);h=!0;for(var t=c.length;t;){for(a=c,c=[];++d1)for(var n=1;n1&&(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=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":36}],40:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.10.1",homepage:"https://jssip.net",contributors:["José Luis Millán (https://github.com/jmillan)","Iñaki Baz Castillo (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.19.6","@babel/preset-env":"^7.19.4","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},scripts:{lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"}}},{}]},{},[8])(8)}); \ No newline at end of file diff --git a/lib/Config.js b/lib/Config.js index 67ae638a8..18fcdbc1a 100644 --- a/lib/Config.js +++ b/lib/Config.js @@ -32,9 +32,10 @@ exports.settings = { no_answer_timeout : 60, // Registration parameters. - register : true, - register_expires : 600, - registrar_server : null, + register : true, + register_expires : 600, + register_from_tag_trail : '', + registrar_server : null, // Connection options. sockets : null, @@ -282,6 +283,16 @@ const checks = { } }, + register_from_tag_trail(register_from_tag_trail) + { + if (typeof register_from_tag_trail === 'function') + { + return register_from_tag_trail; + } + + return String(register_from_tag_trail); + }, + registrar_server(registrar_server) { if (!/^sip:/i.test(registrar_server)) diff --git a/lib/Notifier.js b/lib/Notifier.js index 34579cb33..87b7741eb 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -7,16 +7,16 @@ const Dialog = require('./Dialog'); const logger = new Logger('Notifier'); /** - * Termination codes. + * Termination codes. */ const C = { // Termination codes. - NOTIFY_RESPONSE_TIMEOUT : 0, - NOTIFY_TRANSPORT_ERROR : 1, - NOTIFY_NON_OK_RESPONSE : 2, + NOTIFY_RESPONSE_TIMEOUT : 0, + NOTIFY_TRANSPORT_ERROR : 1, + NOTIFY_NON_OK_RESPONSE : 2, NOTIFY_FAILED_AUTHENTICATION : 3, - SEND_FINAL_NOTIFY : 4, - RECEIVE_UNSUBSCRIBE : 5, + SEND_FINAL_NOTIFY : 4, + RECEIVE_UNSUBSCRIBE : 5, SUBSCRIPTION_EXPIRED : 6, // Notifer states @@ -28,7 +28,7 @@ const C = { /** * RFC 6665 Notifier implementation. */ -module.exports = class Notifier extends EventEmitter +module.exports = class Notifier extends EventEmitter { /** * Expose C object. @@ -50,9 +50,9 @@ module.exports = class Notifier extends EventEmitter * @param {NotifierOptions} options - Optional parameters. * @param {Array} extraHeaders - Additional SIP headers. * @param {string} allowEvents - Allow-Events header value. - * @param {boolean} pending - Set initial dialog state as "pending". + * @param {boolean} pending - Set initial dialog state as "pending". */ - constructor(ua, subscribe, contentType, { extraHeaders, allowEvents, pending }) + constructor(ua, subscribe, contentType, { extraHeaders, allowEvents, pending }) { logger.debug('new'); @@ -89,7 +89,7 @@ module.exports = class Notifier extends EventEmitter this.data = {}; this._dialog = null; - + const eventName = subscribe.getHeader('event'); this._content_type = contentType; @@ -117,7 +117,7 @@ module.exports = class Notifier extends EventEmitter // Create dialog for normal and fetch-subscribe. const dialog = new Dialog(this, subscribe, 'UAS'); - this._dialog = dialog; + this._dialog = dialog; if (this._expires > 0) { @@ -128,27 +128,27 @@ module.exports = class Notifier extends EventEmitter /** * Dialog callback. - * Called also for initial subscribe. + * Called also for initial subscribe. * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). */ - receiveRequest(request) + receiveRequest(request) { - if (request.method !== JsSIP_C.SUBSCRIBE) + if (request.method !== JsSIP_C.SUBSCRIBE) { - request.reply(405); + request.reply(405); return; } - if (request.hasHeader('expires')) - { + if (request.hasHeader('expires')) + { this._expires = parseInt(request.getHeader('expires')); } else - { + { // RFC 6665 3.1.1, default expires value. this._expires = 900; - + logger.debug(`missing Expires header field, default value set: ${this._expires}`); } request.reply(200, null, [ `Expires: ${this._expires}`, `${this._contact}` ]); @@ -165,10 +165,10 @@ module.exports = class Notifier extends EventEmitter logger.debug('emit "subscribe"'); this.emit('subscribe', is_unsubscribe, request, body, content_type); - if (is_unsubscribe) + if (is_unsubscribe) { this._dialogTerminated(C.RECEIVE_UNSUBSCRIBE); - } + } } /** @@ -178,7 +178,7 @@ module.exports = class Notifier extends EventEmitter * Please call after creating the Notifier instance and setting the event handlers. */ start() - { + { logger.debug('start()'); this.receiveRequest(this._initial_subscribe); @@ -187,21 +187,21 @@ module.exports = class Notifier extends EventEmitter /** * Switch pending dialog state to active. */ - setActiveState() + setActiveState() { logger.debug('setActiveState()'); - if (this._state === C.STATE_PENDING) + if (this._state === C.STATE_PENDING) { this._state = C.STATE_ACTIVE; } } - + /** * Send the initial and subsequent notify request. * @param {string} body - notify request body. */ - notify(body = null) + notify(body = null) { logger.debug('notify()'); @@ -214,8 +214,8 @@ module.exports = class Notifier extends EventEmitter } let subs_state = this._stateNumberToString(this._state); - - if (this._state !== C.STATE_TERMINATED) + + if (this._state !== C.STATE_TERMINATED) { let expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); @@ -225,16 +225,16 @@ module.exports = class Notifier extends EventEmitter } subs_state += `;expires=${expires}`; - } - else + } + else { - if (this._terminated_reason) + if (this._terminated_reason) { subs_state += `;reason=${this._terminated_reason}`; } if (this._terminated_retry_after !== null) { - subs_state += `;retry-after=${this._terminated_retry_after}`; + subs_state += `;retry-after=${this._terminated_retry_after}`; } } @@ -242,13 +242,13 @@ module.exports = class Notifier extends EventEmitter headers.push(`Subscription-State: ${subs_state}`); - if (body) + if (body) { headers.push(`Content-Type: ${this._content_type}`); } - - this._dialog.sendRequest(JsSIP_C.NOTIFY, { - body, + + this._dialog.sendRequest(JsSIP_C.NOTIFY, { + body, extraHeaders : headers, eventHandlers : { onRequestTimeout : () => @@ -265,30 +265,30 @@ module.exports = class Notifier extends EventEmitter { this._dialogTerminated(C.NOTIFY_FAILED_AUTHENTICATION); } - else + else { this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); } - }, + }, onDialogError : () => { this._dialogTerminated(C.NOTIFY_NON_OK_RESPONSE); - } + } } }); } /** * Terminate. (Send the final NOTIFY request). - * + * * @param {string} body - Notify message body. * @param {string} reason - Set Subscription-State reason parameter. * @param {number} retryAfter - Set Subscription-State retry-after parameter. */ - terminate(body = null, reason = null, retryAfter = null) + terminate(body = null, reason = null, retryAfter = null) { logger.debug('terminate()'); - + this._state = C.STATE_TERMINATED; this._terminated_reason = reason; this._terminated_retry_after = retryAfter; @@ -299,7 +299,7 @@ module.exports = class Notifier extends EventEmitter } /** - * Get dialog state. + * Get dialog state. */ get state() { @@ -313,12 +313,12 @@ module.exports = class Notifier extends EventEmitter { return this._dialog ? this._dialog.id : null; } - + /** * Private API */ - _dialogTerminated(termination_code) - { + _dialogTerminated(termination_code) + { if (!this._dialog) { return; @@ -334,17 +334,17 @@ module.exports = class Notifier extends EventEmitter } const send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; - + logger.debug(`emit "terminated" code=${termination_code}, send final notify=${send_final_notify}`); this.emit('terminated', termination_code, send_final_notify); } - _setExpiresTimer() + _setExpiresTimer() { this._expires_timestamp = new Date().getTime() + (this._expires * 1000); clearTimeout(this._expires_timer); - this._expires_timer = setTimeout(() => + this._expires_timer = setTimeout(() => { if (!this._dialog) { @@ -367,4 +367,4 @@ module.exports = class Notifier extends EventEmitter default: throw new TypeError('wrong state value'); } } -}; \ No newline at end of file +}; diff --git a/lib/RTCSession.d.ts b/lib/RTCSession.d.ts index edff17102..7e52d447d 100644 --- a/lib/RTCSession.d.ts +++ b/lib/RTCSession.d.ts @@ -1,4 +1,4 @@ -import {EventEmitter, Listener} from 'events' +import {EventEmitter} from 'events' import {IncomingRequest, IncomingResponse, OutgoingRequest} from './SIPMessage' import {NameAddrHeader} from './NameAddrHeader' @@ -25,17 +25,12 @@ export declare enum Originator { } // options -export interface MediaConstraints { - audio?: boolean; - video?: boolean; -} - export interface ExtraHeaders { extraHeaders?: string[]; } export interface AnswerOptions extends ExtraHeaders { - mediaConstraints?: MediaConstraints; + mediaConstraints?: MediaStreamConstraints; mediaStream?: MediaStream; pcConfig?: RTCConfiguration; rtcConstraints?: object; @@ -177,6 +172,7 @@ export interface IncomingAckEvent { } // listener +export type GenericErrorListener = (error: any) => void; export type PeerConnectionListener = (event: PeerConnectionEvent) => void; export type ConnectingListener = (event: ConnectingEvent) => void; export type SendingListener = (event: SendingEvent) => void; @@ -222,11 +218,11 @@ export interface RTCSessionEventMap { 'replaces': ReferListener; 'sdp': SDPListener; 'icecandidate': IceCandidateListener; - 'getusermediafailed': Listener; - 'peerconnection:createofferfailed': Listener; - 'peerconnection:createanswerfailed': Listener; - 'peerconnection:setlocaldescriptionfailed': Listener; - 'peerconnection:setremotedescriptionfailed': Listener; + 'getusermediafailed': GenericErrorListener; + 'peerconnection:createofferfailed': GenericErrorListener; + 'peerconnection:createanswerfailed': GenericErrorListener; + 'peerconnection:setlocaldescriptionfailed': GenericErrorListener; + 'peerconnection:setremotedescriptionfailed': GenericErrorListener; } declare enum SessionStatus { diff --git a/lib/RTCSession.js b/lib/RTCSession.js index df9e50a56..7a1dfd63f 100644 --- a/lib/RTCSession.js +++ b/lib/RTCSession.js @@ -1933,7 +1933,7 @@ module.exports = class RTCSession extends EventEmitter * - 'connection.iceGatheringState' is 'gathering' and 'iceReady' is true. */ const iceRestart = constraints && constraints.iceRestart; - + if ((connection.iceGatheringState === 'complete' && !iceRestart) || (connection.iceGatheringState === 'gathering' && this._iceReady)) { @@ -1959,6 +1959,11 @@ module.exports = class RTCSession extends EventEmitter const ready = () => { + if (finished) + { + return; + } + connection.removeEventListener('icecandidate', iceCandidateListener); connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener); @@ -1988,8 +1993,7 @@ module.exports = class RTCSession extends EventEmitter ready }); } - - else if (!finished) + else { ready(); } @@ -1997,7 +2001,7 @@ module.exports = class RTCSession extends EventEmitter connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = () => { - if ((connection.iceGatheringState === 'complete') && !finished) + if (connection.iceGatheringState === 'complete') { ready(); } diff --git a/lib/Registrator.js b/lib/Registrator.js index 2c889741e..f47114902 100644 --- a/lib/Registrator.js +++ b/lib/Registrator.js @@ -49,7 +49,7 @@ module.exports = class Registrator // Contents of the sip.instance Contact header parameter. this._sipInstance = `""`; - + this._contact += `;reg-id=${this._reg_id}`; this._contact += `;+sip.instance=${this._sipInstance}`; } @@ -109,11 +109,26 @@ module.exports = class Registrator ${this._contact};expires=${this._expires}${this._extraContactParams}`); extraHeaders.push(`Expires: ${this._expires}`); + let fromTag = Utils.newTag(); + + if (this._ua.configuration.register_from_tag_trail) + { + if (typeof this._ua.configuration.register_from_tag_trail === 'function') + { + fromTag += this._ua.configuration.register_from_tag_trail(); + } + else + { + fromTag += this._ua.configuration.register_from_tag_trail; + } + } + const request = new SIPMessage.OutgoingRequest( JsSIP_C.REGISTER, this._registrar, this._ua, { - 'to_uri' : this._to_uri, - 'call_id' : this._call_id, - 'cseq' : (this._cseq += 1) + 'to_uri' : this._to_uri, + 'call_id' : this._call_id, + 'cseq' : (this._cseq += 1), + 'from_tag' : fromTag }, extraHeaders); const request_sender = new RequestSender(this._ua, request, { diff --git a/lib/Subscriber.js b/lib/Subscriber.js index 6b1737d71..31cfc01ac 100644 --- a/lib/Subscriber.js +++ b/lib/Subscriber.js @@ -14,12 +14,12 @@ const logger = new Logger('Subscriber'); */ const C = { // Termination codes. - SUBSCRIBE_RESPONSE_TIMEOUT : 0, - SUBSCRIBE_TRANSPORT_ERROR : 1, - SUBSCRIBE_NON_OK_RESPONSE : 2, + SUBSCRIBE_RESPONSE_TIMEOUT : 0, + SUBSCRIBE_TRANSPORT_ERROR : 1, + SUBSCRIBE_NON_OK_RESPONSE : 2, SUBSCRIBE_BAD_OK_RESPONSE : 3, SUBSCRIBE_FAILED_AUTHENTICATION : 4, - UNSUBSCRIBE_TIMEOUT : 5, + UNSUBSCRIBE_TIMEOUT : 5, RECEIVE_FINAL_NOTIFY : 6, RECEIVE_BAD_NOTIFY : 7, @@ -34,7 +34,7 @@ const C = { /** * RFC 6665 Subscriber implementation. */ -module.exports = class Subscriber extends EventEmitter +module.exports = class Subscriber extends EventEmitter { /** * Expose C object. @@ -54,17 +54,17 @@ module.exports = class Subscriber extends EventEmitter * @param {string} target * @param {string} eventName - Event header value. May end with optional ;id=xxx * @param {string} accept - Accept header value. - * + * * @param {SubscriberOption} options - optional parameters. * @param {number} expires - Expires header value. Default is 900. * @param {string} contentType - Content-Type header value. Used for SUBSCRIBE with body * @param {string} allowEvents - Allow-Events header value. - * @param {RequestParams} params - Will have priority over ua.configuration. + * @param {RequestParams} params - Will have priority over ua.configuration. * If set please define: to_uri, to_display_name, from_uri, from_display_name * @param {Array} extraHeaders - Additional SIP headers. */ - constructor(ua, target, eventName, accept, { expires, contentType, - allowEvents, params, extraHeaders }) + constructor(ua, target, eventName, accept, { expires, contentType, + allowEvents, params, extraHeaders }) { logger.debug('new'); @@ -97,7 +97,7 @@ module.exports = class Subscriber extends EventEmitter this._expires = expires; // Used to subscribe with body. - this._content_type = contentType; + this._content_type = contentType; // Set initial subscribe parameters. this._params = Utils.cloneObject(params); @@ -110,13 +110,13 @@ module.exports = class Subscriber extends EventEmitter this._params.from_tag = Utils.newTag(); this._params.to_tag = null; this._params.call_id = Utils.createRandomToken(20); - + // Create subscribe cseq if not defined custom cseq. if (this._params.cseq === undefined) - { + { this._params.cseq = Math.floor((Math.random() * 10000) + 1); } - + // Subscriber state. this._state = C.STATE_INIT; @@ -126,14 +126,14 @@ module.exports = class Subscriber extends EventEmitter // To refresh subscription. this._expires_timer = null; this._expires_timestamp = null; - + // To prevent duplicate terminated call. this._terminated = false; // After send un-subscribe wait final notify limited time. this._unsubscribe_timeout_timer = null; - // Custom session empty object for high level use. + // Custom session empty object for high level use. this.data = {}; const parsed = Grammar.parse(eventName, 'Event'); @@ -142,10 +142,10 @@ module.exports = class Subscriber extends EventEmitter { throw new TypeError('eventName - wrong format'); } - + this._event_name = parsed.event; this._event_id = parsed.params && parsed.params.id; - + let eventValue = this._event_name; if (this._event_id) @@ -159,12 +159,12 @@ module.exports = class Subscriber extends EventEmitter `Expires: ${this._expires}`, `Accept: ${accept}` ]); - + if (!this._headers.find((header) => header.startsWith('Contact'))) { const contact = `Contact: ${this._ua._contact.toString()}`; - + this._headers.push(contact); } @@ -177,12 +177,12 @@ module.exports = class Subscriber extends EventEmitter this._queue = []; } - onRequestTimeout() + onRequestTimeout() { this._dialogTerminated(C.SUBSCRIBE_RESPONSE_TIMEOUT); } - onTransportError() + onTransportError() { this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); } @@ -190,12 +190,12 @@ module.exports = class Subscriber extends EventEmitter /** * Dialog callback. */ - receiveRequest(request) + receiveRequest(request) { - if (request.method !== JsSIP_C.NOTIFY) + if (request.method !== JsSIP_C.NOTIFY) { logger.warn('received non-NOTIFY request'); - request.reply(405); + request.reply(405); return; } @@ -203,7 +203,7 @@ module.exports = class Subscriber extends EventEmitter // RFC 6665 8.2.1. Check if event header matches. const event_header = request.parseHeader('Event'); - if (!event_header) + if (!event_header) { logger.warn('missed Event header'); request.reply(400); @@ -227,7 +227,7 @@ module.exports = class Subscriber extends EventEmitter // Process Subscription-State header. const subs_state = request.parseHeader('subscription-state'); - if (!subs_state) + if (!subs_state) { logger.warn('missed Subscription-State header'); request.reply(400); @@ -240,19 +240,19 @@ module.exports = class Subscriber extends EventEmitter const new_state = this._stateStringToNumber(subs_state.state); const prev_state = this._state; - - if (prev_state !== C.STATE_TERMINATED && new_state !== C.STATE_TERMINATED) + + if (prev_state !== C.STATE_TERMINATED && new_state !== C.STATE_TERMINATED) { this._state = new_state; - if (subs_state.expires !== undefined) + if (subs_state.expires !== undefined) { const expires = subs_state.expires; const expires_timestamp = new Date().getTime() + (expires * 1000); const max_time_deviation = 2000; // Expiration time is shorter and the difference is not too small. - if (this._expires_timestamp - expires_timestamp > max_time_deviation) + if (this._expires_timestamp - expires_timestamp > max_time_deviation) { logger.debug('update sending re-SUBSCRIBE time'); @@ -261,12 +261,12 @@ module.exports = class Subscriber extends EventEmitter } } - if (prev_state !== C.STATE_PENDING && new_state === C.STATE_PENDING) + if (prev_state !== C.STATE_PENDING && new_state === C.STATE_PENDING) { logger.debug('emit "pending"'); this.emit('pending'); } - else if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) + else if (prev_state !== C.STATE_ACTIVE && new_state === C.STATE_ACTIVE) { logger.debug('emit "active"'); this.emit('active'); @@ -278,7 +278,7 @@ module.exports = class Subscriber extends EventEmitter const is_final = new_state === C.STATE_TERMINATED; // Notify event fired only for notify with body. - if (body) + if (body) { const content_type = request.getHeader('content-type'); @@ -294,7 +294,7 @@ module.exports = class Subscriber extends EventEmitter if (subs_state.params && subs_state.params['retry-after'] !== undefined) { retry_after = parseInt(subs_state.params['retry-after']); - } + } this._dialogTerminated(C.RECEIVE_FINAL_NOTIFY, reason, retry_after); } @@ -304,11 +304,11 @@ module.exports = class Subscriber extends EventEmitter * User API */ - /** + /** * Send the initial (non-fetch) and subsequent subscribe. * @param {string} body - subscribe request body. */ - subscribe(body = null) + subscribe(body = null) { logger.debug('subscribe()'); @@ -316,18 +316,18 @@ module.exports = class Subscriber extends EventEmitter { this._sendInitialSubscribe(body, this._headers); } - else + else { this._sendSubsequentSubscribe(body, this._headers); } } - /** - * terminate. + /** + * terminate. * Send un-subscribe or fetch-subscribe (with Expires: 0). * @param {string} body - un-subscribe request body */ - terminate(body = null) + terminate(body = null) { logger.debug('terminate()'); @@ -340,9 +340,9 @@ module.exports = class Subscriber extends EventEmitter this._terminated = true; // Set header Expires: 0. - const headers = this._headers.map((header) => - { - return header.startsWith('Expires') ? 'Expires: 0' : header; + const headers = this._headers.map((header) => + { + return header.startsWith('Expires') ? 'Expires: 0' : header; }); if (this._state === C.STATE_INIT) @@ -351,14 +351,14 @@ module.exports = class Subscriber extends EventEmitter this._sendInitialSubscribe(body, headers); } else - { + { this._sendSubsequentSubscribe(body, headers); } // Waiting for the final notify for a while. const final_notify_timeout = 30000; - this._unsubscribe_timeout_timer = setTimeout(() => + this._unsubscribe_timeout_timer = setTimeout(() => { this._dialogTerminated(C.UNSUBSCRIBE_TIMEOUT); }, final_notify_timeout); @@ -371,7 +371,7 @@ module.exports = class Subscriber extends EventEmitter { return this._state; } - + /** * Get dialog id. */ @@ -385,10 +385,10 @@ module.exports = class Subscriber extends EventEmitter */ _sendInitialSubscribe(body, headers) { - if (body) + if (body) { if (!this._content_type) - { + { throw new TypeError('content_type is undefined'); } @@ -398,7 +398,7 @@ module.exports = class Subscriber extends EventEmitter this._state = C.STATE_NOTIFY_WAIT; - const request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, + const request = new SIPMessage.OutgoingRequest(JsSIP_C.SUBSCRIBE, this._ua.normalizeTarget(this._target), this._ua, this._params, headers, body); const request_sender = new RequestSender(this._ua, request, { @@ -419,25 +419,25 @@ module.exports = class Subscriber extends EventEmitter request_sender.send(); } - _receiveSubscribeResponse(response) + _receiveSubscribeResponse(response) { - if (response.status_code >= 200 && response.status_code < 300) + if (response.status_code >= 200 && response.status_code < 300) { // Create dialog - if (this._dialog === null) + if (this._dialog === null) { const dialog = new Dialog(this, response, 'UAC'); if (dialog.error) { - // OK response without Contact + // OK response without Contact logger.warn(dialog.error); this._dialogTerminated(C.SUBSCRIBE_BAD_OK_RESPONSE); return; } - - this._dialog = dialog; + + this._dialog = dialog; logger.debug('emit "accepted"'); this.emit('accepted'); @@ -469,12 +469,12 @@ module.exports = class Subscriber extends EventEmitter { this._scheduleSubscribe(expires); } - } + } else if (response.status_code === 401 || response.status_code === 407) { this._dialogTerminated(C.SUBSCRIBE_FAILED_AUTHENTICATION); } - else if (response.status_code >= 300) + else if (response.status_code >= 300) { this._dialogTerminated(C.SUBSCRIBE_NON_OK_RESPONSE); } @@ -484,9 +484,9 @@ module.exports = class Subscriber extends EventEmitter { if (this._state === C.STATE_TERMINATED) { - return; + return; } - + if (!this._dialog) { logger.debug('enqueue subscribe'); @@ -495,11 +495,11 @@ module.exports = class Subscriber extends EventEmitter return; } - - if (body) + + if (body) { if (!this._content_type) - { + { throw new TypeError('content_type is undefined'); } @@ -507,8 +507,8 @@ module.exports = class Subscriber extends EventEmitter headers.push(`Content-Type: ${this._content_type}`); } - this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { - body, + this._dialog.sendRequest(JsSIP_C.SUBSCRIBE, { + body, extraHeaders : headers, eventHandlers : { onRequestTimeout : () => @@ -522,20 +522,20 @@ module.exports = class Subscriber extends EventEmitter onSuccessResponse : (response) => { this._receiveSubscribeResponse(response); - }, + }, onErrorResponse : (response) => { this._receiveSubscribeResponse(response); - }, + }, onDialogError : (response) => { this._receiveSubscribeResponse(response); - } + } } }); } - _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) + _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) { // To prevent duplicate emit terminated event. if (this._state === C.STATE_TERMINATED) @@ -559,15 +559,15 @@ module.exports = class Subscriber extends EventEmitter this.emit('terminated', terminationCode, reason, retryAfter); } - _scheduleSubscribe(expires) + _scheduleSubscribe(expires) { /* - If the expires time is less than 140 seconds we do not support Chrome intensive timer throttling mode. + If the expires time is less than 140 seconds we do not support Chrome intensive timer throttling mode. In this case, the re-subcribe is sent 5 seconds before the subscription expiration. - When Chrome is in intensive timer throttling mode, in the worst case, + When Chrome is in intensive timer throttling mode, in the worst case, the timer will be 60 seconds late. - We give the server 10 seconds to make sure it will execute the command even if it is heavily loaded. + We give the server 10 seconds to make sure it will execute the command even if it is heavily loaded. As a result, we order the time no later than 70 seconds before the subscription expiration. Resulting time calculated as half time interval + (half interval - 70) * random. @@ -575,7 +575,7 @@ module.exports = class Subscriber extends EventEmitter expires is 600, re-subscribe will be ordered to send in 300 + (0 .. 230) seconds. */ - const timeout = expires >= 140 ? (expires * 1000 / 2) + const timeout = expires >= 140 ? (expires * 1000 / 2) + Math.floor(((expires / 2) - 70) * 1000 * Math.random()) : (expires * 1000) - 5000; this._expires_timestamp = new Date().getTime() + (expires * 1000); @@ -583,7 +583,7 @@ module.exports = class Subscriber extends EventEmitter logger.debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); clearTimeout(this._expires_timer); - this._expires_timer = setTimeout(() => + this._expires_timer = setTimeout(() => { this._expires_timer = null; this._sendSubsequentSubscribe(null, this._headers); @@ -602,4 +602,4 @@ module.exports = class Subscriber extends EventEmitter default: throw new TypeError('wrong state value'); } } -}; \ No newline at end of file +}; diff --git a/lib/Transport.js b/lib/Transport.js index 33018e74d..52c6f1508 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -340,7 +340,25 @@ module.exports = class Transport _onData(data) { - // CRLF Keep Alive response from server. Ignore it. + // CRLF Keep Alive request from server, reply. + if (data === '\r\n\r\n') + { + logger.debug('received message with double-CRLF Keep Alive request'); + + try + { + // Reply with single CRLF. + this.socket.send('\r\n'); + } + catch (error) + { + logger.warn(`error sending Keep Alive response: ${error}`); + } + + return; + } + + // CRLF Keep Alive response from server, ignore it. if (data === '\r\n') { logger.debug('received message with CRLF Keep Alive response'); diff --git a/lib/UA.d.ts b/lib/UA.d.ts index 20774d899..de64cca3a 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -1,4 +1,4 @@ -import {EventEmitter, Listener} from 'events' +import {EventEmitter} from 'events' import {Socket, WeightedSocket} from './Socket' import {AnswerOptions, Originator, RTCSession, RTCSessionEventMap, TerminateOptions} from './RTCSession' @@ -42,6 +42,7 @@ export interface UAConfiguration { ha1?: string; register?: boolean; register_expires?: number; + register_from_tag_trail?: string | function() : string; registrar_server?: string; use_preloaded_route?: boolean; user_agent?: string; @@ -115,6 +116,7 @@ export type DisconnectedListener = (event: DisconnectEvent) => void; export type RegisteredListener = (event: RegisteredEvent) => void; export type UnRegisteredListener = (event: UnRegisteredEvent) => void; export type RegistrationFailedListener = UnRegisteredListener; +export type RegistrationExpiringListener = () => void; export type IncomingRTCSessionListener = (event: IncomingRTCSessionEvent) => void; export type OutgoingRTCSessionListener = (event: OutgoingRTCSessionEvent) => void; export type RTCSessionListener = IncomingRTCSessionListener | OutgoingRTCSessionListener; @@ -134,7 +136,7 @@ export interface UAEventMap { registered: RegisteredListener; unregistered: UnRegisteredListener; registrationFailed: RegistrationFailedListener; - registrationExpiring: Listener; + registrationExpiring: RegistrationExpiringListener; newRTCSession: RTCSessionListener; newMessage: MessageListener; sipEvent: SipEventListener; diff --git a/lib/UA.js b/lib/UA.js index 26389bfc8..6597b627f 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -258,15 +258,15 @@ module.exports = class UA extends EventEmitter return message; } - - /** + + /** * Create subscriber instance */ - subscribe(target, eventName, accept, options) + subscribe(target, eventName, accept, options) { logger.debug('subscribe()'); - return new Subscriber(this, target, eventName, accept, options); + return new Subscriber(this, target, eventName, accept, options); } /** @@ -457,6 +457,11 @@ module.exports = class UA extends EventEmitter break; } + case 'extra_headers': { + this._configuration.extra_headers = value; + break; + } + default: logger.warn('set() | cannot set "%s" parameter in runtime', parameter); @@ -662,7 +667,7 @@ module.exports = class UA extends EventEmitter if (this.listeners('newSubscribe').length === 0) { request.reply(405); - + return; } } @@ -979,7 +984,7 @@ module.exports = class UA extends EventEmitter // Seal the configuration. const writable_parameters = [ - 'authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register' + 'authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register', 'extra_headers' ]; for (const parameter in this._configuration) diff --git a/package.json b/package.json index 963e68f30..4e65305a1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jssip", "title": "JsSIP", "description": "the Javascript SIP library", - "version": "3.10.0", + "version": "3.10.1", "homepage": "https://jssip.net", "contributors": [ "José Luis Millán (https://github.com/jmillan)", diff --git a/test/include/loopSocket.js b/test/include/loopSocket.js index 9055bd296..9a92d9a21 100644 --- a/test/include/loopSocket.js +++ b/test/include/loopSocket.js @@ -5,10 +5,10 @@ module.exports = class LoopSocket constructor() { this.url = 'ws://localhost:12345'; - this.via_transport = 'WS'; + this.via_transport = 'WS'; this.sip_uri = 'sip:localhost:12345;transport=ws'; } - + connect() { setTimeout(() => { this.onconnect(); }, 0); @@ -21,9 +21,9 @@ module.exports = class LoopSocket send(message) { const message2 = this._modifyCallId(message); - + setTimeout(() => { this.ondata(message2); }, 0); - + return true; } @@ -33,16 +33,16 @@ module.exports = class LoopSocket const ixBegin = message.indexOf('Call-ID'); const ixEnd = message.indexOf('\r', ixBegin); let callId = message.substring(ixBegin+9, ixEnd); - + if (callId.endsWith('_second')) { callId = callId.substring(0, callId.length - 7); - } - else + } + else { callId += '_second'; } - + return `${message.substring(0, ixBegin)}Call-ID: ${callId}${message.substring(ixEnd)}`; } -}; \ No newline at end of file +}; diff --git a/test/test-UA-subscriber-notifier.js b/test/test-UA-subscriber-notifier.js index 1b3670762..448c8cabe 100644 --- a/test/test-UA-subscriber-notifier.js +++ b/test/test-UA-subscriber-notifier.js @@ -8,18 +8,18 @@ module.exports = { 'subscriber/notifier communication' : function(test) { test.expect(39); - + let eventSequence = 0; - + const TARGET = 'ikq'; const REQUEST_URI = 'sip:ikq@example.com'; const CONTACT_URI = 'sip:ikq@abcdefabcdef.invalid;transport=ws'; const SUBSCRIBE_ACCEPT = 'application/text, text/plain'; const EVENT_NAME = 'weather'; - const CONTENT_TYPE = 'text/plain'; + const CONTENT_TYPE = 'text/plain'; const WEATHER_REQUEST = 'Please report the weather condition'; const WEATHER_REPORT = '+20..+24°C, no precipitation, light wind'; - + function createSubscriber(ua) { const options = { @@ -30,89 +30,89 @@ module.exports = { const subscriber = ua.subscribe(TARGET, EVENT_NAME, SUBSCRIBE_ACCEPT, options); - subscriber.on('active', () => + subscriber.on('active', () => { - test.ok(++eventSequence === 6, 'receive notify with subscription-state: active'); + test.ok(++eventSequence === 6, 'receive notify with subscription-state: active'); }); - subscriber.on('notify', (isFinal, notify, body, contType) => + subscriber.on('notify', (isFinal, notify, body, contType) => { eventSequence++; test.ok(eventSequence === 7 || eventSequence === 11, 'receive notify'); - + test.strictEqual(notify.method, 'NOTIFY'); test.strictEqual(notify.getHeader('contact'), `<${CONTACT_URI}>`, 'notify contact'); test.strictEqual(body, WEATHER_REPORT, 'notify body'); test.strictEqual(contType, CONTENT_TYPE, 'notify content-type'); - + const subsState = notify.parseHeader('subscription-state').state; - + test.ok(subsState === 'pending' || subsState === 'active' || subsState === 'terminated', 'notify subscription-state'); - + // After receiving the first notify, send un-subscribe. if (eventSequence === 7) - { + { test.ok(++eventSequence === 8, 'send un-subscribe'); - + subscriber.terminate(WEATHER_REQUEST); } }); - subscriber.on('terminated', (terminationCode, reason, retryAfter) => + subscriber.on('terminated', (terminationCode, reason, retryAfter) => { test.ok(++eventSequence === 12, 'subscriber terminated'); - test.ok(terminationCode === subscriber.C.RECEIVE_FINAL_NOTIFY); + test.ok(terminationCode === subscriber.C.RECEIVE_FINAL_NOTIFY); test.ok(reason === undefined); - test.ok(retryAfter === undefined); - + test.ok(retryAfter === undefined); + ua.stop(); - - test.done(); + + test.done(); }); - subscriber.on('accepted', () => + subscriber.on('accepted', () => { test.ok(++eventSequence === 5, 'initial subscribe accepted'); }); test.ok(++eventSequence === 2, 'send subscribe'); - + subscriber.subscribe(WEATHER_REQUEST); } - function createNotifier(ua, subscribe) + function createNotifier(ua, subscribe) { const notifier = ua.notify(subscribe, CONTENT_TYPE, { pending: false }); // Receive subscribe (includes initial) - notifier.on('subscribe', (isUnsubscribe, subs, body, contType) => + notifier.on('subscribe', (isUnsubscribe, subs, body, contType) => { test.strictEqual(subscribe.method, 'SUBSCRIBE'); test.strictEqual(subscribe.getHeader('contact'), `<${CONTACT_URI}>`, 'subscribe contact'); test.strictEqual(subscribe.getHeader('accept'), SUBSCRIBE_ACCEPT, 'subscribe accept'); test.strictEqual(body, WEATHER_REQUEST, 'subscribe body'); test.strictEqual(contType, CONTENT_TYPE, 'subscribe content-type'); - + if (isUnsubscribe) { - test.ok(++eventSequence === 9, 'receive un-subscribe, send final notify'); - + test.ok(++eventSequence === 9, 'receive un-subscribe, send final notify'); + notifier.terminate(WEATHER_REPORT); } - else + else { - test.ok(++eventSequence === 4, 'receive subscribe, send notify'); - + test.ok(++eventSequence === 4, 'receive subscribe, send notify'); + notifier.notify(WEATHER_REPORT); } }); - notifier.on('terminated', (terminationCode, sendFinalNotify) => + notifier.on('terminated', (terminationCode, sendFinalNotify) => { - test.ok(++eventSequence === 10, 'notifier terminated'); + test.ok(++eventSequence === 10, 'notifier terminated'); test.ok(!sendFinalNotify, 'final notify sending if subscription expired'); - - if (sendFinalNotify) + + if (sendFinalNotify) { notifier.terminate(WEATHER_REPORT); } @@ -122,7 +122,7 @@ module.exports = { } // Start JsSIP UA with loop socket. - const config = + const config = { sockets : new LoopSocket(), // message sending itself, with modified Call-ID uri : REQUEST_URI, @@ -131,49 +131,49 @@ module.exports = { }; const ua = new JsSIP.UA(config); - + // Uncomment to see SIP communication // JsSIP.debug.enable('JsSIP:*'); - - ua.on('newSubscribe', (e) => + + ua.on('newSubscribe', (e) => { - test.ok(++eventSequence === 3, 'receive initial subscribe'); + test.ok(++eventSequence === 3, 'receive initial subscribe'); const subs = e.request; const ev = subs.parseHeader('event'); - + test.strictEqual(subs.ruri.toString(), REQUEST_URI, 'initial subscribe uri'); test.strictEqual(ev.event, EVENT_NAME, 'subscribe event'); - + if (ev.event !== EVENT_NAME) { subs.reply(489); // "Bad Event" - + return; } - + const accepts = subs.getHeaders('accept'); const canUse = accepts && accepts.some((v) => v.includes(CONTENT_TYPE)); - + test.ok(canUse, 'notifier can use subscribe accept header'); - + if (!canUse) { subs.reply(406); // "Not Acceptable" - + return; } - - createNotifier(ua, subs); + + createNotifier(ua, subs); }); - - ua.on('connected', () => + + ua.on('connected', () => { - test.ok(++eventSequence === 1, 'socket connected'); - + test.ok(++eventSequence === 1, 'socket connected'); + createSubscriber(ua); }); - + ua.start(); } -}; \ No newline at end of file +}; From aac7d1cc4c771d2cc9ae781c1bea926c6fc3752e Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 5 Nov 2023 17:55:51 +0200 Subject: [PATCH 68/70] added _notify() that called from notify() and terminate() --- lib/Notifier.js | 86 ++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index 87b7741eb..a582a3120 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -81,10 +81,6 @@ module.exports = class Notifier extends EventEmitter // Notifier state: pending, active, terminated. Not used: init, resp_wait. this._state = pending ? C.STATE_PENDING : C.STATE_ACTIVE; - // Optional. Used to build terminated Subscription-State. - this._terminated_reason = null; - this._terminated_retry_after = null; - // Custom session empty object for high level use. this.data = {}; @@ -201,10 +197,32 @@ module.exports = class Notifier extends EventEmitter * Send the initial and subsequent notify request. * @param {string} body - notify request body. */ - notify(body = null) + notify(body=null) { logger.debug('notify()'); + if (this._state === C.STATE_TERMINATED) + { + throw new Error('Cannot send notify in terminated state.'); + } + + let expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); + + if (expires < 0) + { + expires = 0; + } + + this._notify([ `;expires=${expires}` ], body); + } + + /** + * @param {Array} subsStateParams subscription state parameters. + * @param {String} body Notify body + * @param {Array} extraHeaders + */ + _notify(subsStateParameters, body=null, extraHeaders=null) + { // Prevent send notify after final notify. if (!this._dialog) { @@ -213,35 +231,23 @@ module.exports = class Notifier extends EventEmitter return; } - let subs_state = this._stateNumberToString(this._state); + // Build Subscription-State header with parameters. + let subsState = `Subscription-State: ${this._stateToString()}`; - if (this._state !== C.STATE_TERMINATED) + for (const param of subsStateParameters) { - let expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); + subsState += param; + } - if (expires < 0) - { - expires = 0; - } + let headers = this._headers.slice(); - subs_state += `;expires=${expires}`; - } - else + headers.push(subsState); + + if (extraHeaders) { - if (this._terminated_reason) - { - subs_state += `;reason=${this._terminated_reason}`; - } - if (this._terminated_retry_after !== null) - { - subs_state += `;retry-after=${this._terminated_retry_after}`; - } + headers = headers.concat(extraHeaders); } - const headers = this._headers.slice(); - - headers.push(`Subscription-State: ${subs_state}`); - if (body) { headers.push(`Content-Type: ${this._content_type}`); @@ -290,12 +296,22 @@ module.exports = class Notifier extends EventEmitter logger.debug('terminate()'); this._state = C.STATE_TERMINATED; - this._terminated_reason = reason; - this._terminated_retry_after = retryAfter; - this.notify(body); + const subsStateParameters = []; + + if (reason) + { + subsStateParameters.push(`;reason=${reason}`); + } + + if (retryAfter !== null) + { + subsStateParameters.push(`;retry-after=${retryAfter}`); + } + + this._notify(subsStateParameters, body); - this._dialogTerminated(C.SEND_FINAL_NOTIFY); + this._dialogTerminated(reason === 'timeout' ? C.SUBSCRIPTION_EXPIRED : C.SEND_FINAL_NOTIFY); } /** @@ -351,15 +367,13 @@ module.exports = class Notifier extends EventEmitter return; } - this._terminated_reason = 'timeout'; - this.notify(); - this._dialogTerminated(C.SUBSCRIPTION_EXPIRED); + this.terminate(null, 'timeout'); }, this._expires * 1000); } - _stateNumberToString(state) + _stateToString() { - switch (state) + switch (this._state) { case C.STATE_PENDING: return 'pending'; case C.STATE_ACTIVE: return 'active'; From eca25f724554da0c98c47de1c675336e4b146c6b Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 5 Nov 2023 19:03:01 +0200 Subject: [PATCH 69/70] Fixed SUBSCRIPTION_EXPIRED termination functionality --- lib/Notifier.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Notifier.js b/lib/Notifier.js index a582a3120..b3d51ae22 100644 --- a/lib/Notifier.js +++ b/lib/Notifier.js @@ -349,10 +349,12 @@ module.exports = class Notifier extends EventEmitter this._dialog = null; } - const send_final_notify = termination_code === C.SUBSCRIPTION_EXPIRED; - - logger.debug(`emit "terminated" code=${termination_code}, send final notify=${send_final_notify}`); - this.emit('terminated', termination_code, send_final_notify); + // For SUBSCRIPTION_EXPIRED the 'terminated' event was fired in expiration timer + if (termination_code !== C.SUBSCRIPTION_EXPIRED) + { + logger.debug(`emit "terminated" code=${termination_code}, send final notify=false`); + this.emit('terminated', termination_code, false); + } } _setExpiresTimer() @@ -367,7 +369,8 @@ module.exports = class Notifier extends EventEmitter return; } - this.terminate(null, 'timeout'); + logger.debug(`emit "terminated" code=${C.SUBSCRIPTION_EXPIRED}, send final notify=true`); + this.emit('terminated', C.SUBSCRIPTION_EXPIRED, true); }, this._expires * 1000); } From b2ef69c96a8038092a87b593af47cbe16ef0c01e Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 5 Nov 2023 20:20:59 +0200 Subject: [PATCH 70/70] Added reason 'timeout' to user final NOTIFY --- test/test-UA-subscriber-notifier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-UA-subscriber-notifier.js b/test/test-UA-subscriber-notifier.js index 448c8cabe..e9a82a378 100644 --- a/test/test-UA-subscriber-notifier.js +++ b/test/test-UA-subscriber-notifier.js @@ -114,7 +114,7 @@ module.exports = { if (sendFinalNotify) { - notifier.terminate(WEATHER_REPORT); + notifier.terminate(WEATHER_REPORT, 'timeout'); } });